Class: Rattler::BackEnd::ParserGenerator::RuleGenerator

Inherits:
Object
  • Object
show all
Includes:
Parsers
Defined in:
lib/rattler/back_end/parser_generator/rule_generator.rb

Constant Summary collapse

Grammar =

:nodoc:

Rattler::Grammar::Grammar

Instance Method Summary collapse

Methods included from Parsers

define

Constructor Details

#initialize(g) ⇒ RuleGenerator

Returns a new instance of RuleGenerator.



10
11
12
13
# File 'lib/rattler/back_end/parser_generator/rule_generator.rb', line 10

def initialize(g)
  @g = g
  @top_level_generator = TopLevelGenerator.new(@g)
end

Instance Method Details

#gen_rule_modular(rule) ⇒ Object



33
34
35
# File 'lib/rattler/back_end/parser_generator/rule_generator.rb', line 33

def gen_rule_modular(rule)
  gen_rule_hook rule, 'apply'
end

#gen_rule_standalone(rule, rule_set) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/rattler/back_end/parser_generator/rule_generator.rb', line 23

def gen_rule_standalone(rule, rule_set)
  if rule_set.analysis.left_recursive? rule.name
    gen_rule_hook rule, 'memoize_lr'
  elsif rule_set.analysis.recursive? rule.name
    gen_rule_hook rule, 'memoize'
  else
    gen_rule_method rule, "match_#{rule.name}"
  end
end

#generate(parser, opts = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rattler/back_end/parser_generator/rule_generator.rb', line 15

def generate(parser, opts={})
  case parser
  when Rule then gen_rule_modular parser
  else @top_level_generator.generate parser
  end
  self
end