Class: Rattler::Grammar::Analysis

Inherits:
Object
  • Object
show all
Includes:
Parsers
Defined in:
lib/rattler/grammar/analysis.rb

Instance Method Summary collapse

Methods included from Parsers

define

Constructor Details

#initialize(rules) ⇒ Analysis

Returns a new instance of Analysis.



15
16
17
18
19
20
21
# File 'lib/rattler/grammar/analysis.rb', line 15

def initialize(rules)
  @rules = rules
  @references = {}
  @left_references = {}
  @direct_references = {}
  @direct_left_references = {}
end

Instance Method Details

#left_recursive?(rule_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rattler/grammar/analysis.rb', line 31

def left_recursive?(rule_name)
  left_referenced_from? rule_name, rule_name
end

#left_referenced_from?(referencer, referencee) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rattler/grammar/analysis.rb', line 44

def left_referenced_from?(referencer, referencee)
  left_references_from(referencer).include? referencee
end

#recursive?(rule_name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rattler/grammar/analysis.rb', line 27

def recursive?(rule_name)
  referenced_from? rule_name, rule_name
end

#referenced?(rule_name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/rattler/grammar/analysis.rb', line 35

def referenced?(rule_name)
  rule_name == @rules.start_rule or
  referenced_from? @rules.start_rule, rule_name
end

#referenced_from?(referencer, referencee) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rattler/grammar/analysis.rb', line 40

def referenced_from?(referencer, referencee)
  references_from(referencer).include? referencee
end

#regular?(rule_name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rattler/grammar/analysis.rb', line 23

def regular?(rule_name)
  not recursive?(rule_name)
end