Class: Rattler::Parsers::Analysis
- Inherits:
-
Object
- Object
- Rattler::Parsers::Analysis
- Defined in:
- lib/rattler/parsers/analysis.rb
Overview
Analysis
represents a static analysis of a set of parse rules.
Instance Method Summary collapse
-
#initialize(rules) ⇒ Analysis
constructor
A new instance of Analysis.
-
#left_recursive?(rule_name) ⇒ Boolean
true
if the rule referenced byrule_name
is left-recursive. -
#recursive?(rule_name) ⇒ Boolean
true
if the rule referenced byrule_name
is recursive. -
#referenced?(rule_name) ⇒ Boolean
true
if the rule referenced byrule_name
is referenced by any other rule in the rule set. -
#regular?(rule_name) ⇒ Boolean
true
if the rule referenced byrule_name
is non-recursive.
Constructor Details
#initialize(rules) ⇒ Analysis
Returns a new instance of Analysis.
10 11 12 13 14 15 16 17 |
# File 'lib/rattler/parsers/analysis.rb', line 10 def initialize(rules) @rules = rules @references = {} @left_references = {} @direct_references = {} @direct_left_references = {} @has_super = {} end |
Instance Method Details
#left_recursive?(rule_name) ⇒ Boolean
Returns true
if the rule referenced by rule_name
is left-recursive.
34 35 36 |
# File 'lib/rattler/parsers/analysis.rb', line 34 def left_recursive?(rule_name) left_referenced_from? rule_name, rule_name end |
#recursive?(rule_name) ⇒ Boolean
Returns true
if the rule referenced by rule_name
is recursive.
27 28 29 30 |
# File 'lib/rattler/parsers/analysis.rb', line 27 def recursive?(rule_name) has_super? rule_name or referenced_from? rule_name, rule_name end |
#referenced?(rule_name) ⇒ Boolean
Returns true
if the rule referenced by rule_name
is referenced by any other rule in the rule set.
41 42 43 44 |
# File 'lib/rattler/parsers/analysis.rb', line 41 def referenced?(rule_name) rule_name == @rules.start_rule or referenced_from? @rules.start_rule, rule_name end |
#regular?(rule_name) ⇒ Boolean
Returns true
if the rule referenced by rule_name
is non-recursive.
21 22 23 |
# File 'lib/rattler/parsers/analysis.rb', line 21 def regular?(rule_name) not recursive?(rule_name) end |