Class: Rattler::Parsers::Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/rattler/parsers/analysis.rb

Overview

Analysis represents a static analysis of a set of parse rules.

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ Analysis

Returns a new instance of Analysis.

Parameters:

  • rules (RuleSet)

    the rule set to analyze



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.

Parameters:

  • rule_name (Symbol)

    the name of a parse rule in the rule set

Returns:

  • (Boolean)

    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.

Parameters:

  • rule_name (Symbol)

    the name of a parse rule in the rule set

Returns:

  • (Boolean)

    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.

Parameters:

  • rule_name (Symbol)

    the name of a parse rule in the rule set

Returns:

  • (Boolean)

    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.

Parameters:

  • rule_name (Symbol)

    the name of a parse rule in the rule set

Returns:

  • (Boolean)

    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