Class: Rattler::Compiler::ParserGenerator::RuleSetGenerator

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

Direct Known Subclasses

GrammarGenerator

Instance Method Summary collapse

Constructor Details

#initialize(g) ⇒ RuleSetGenerator

Returns a new instance of RuleSetGenerator.



9
10
11
12
# File 'lib/rattler/compiler/parser_generator/rule_set_generator.rb', line 9

def initialize(g)
  @g = g
  @rule_generator = RuleGenerator.new(@g)
end

Instance Method Details

#gen_rules(rules, opts = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/rattler/compiler/parser_generator/rule_set_generator.rb', line 19

def gen_rules(rules, opts={})
  gen_start_rule rules.start_rule if rules.start_rule
  @g.intersperse(rules, :newlines => 2) do |rule|
    @rule_generator.generate rule
  end
end

#gen_start_rule(start_rule) ⇒ Object



26
27
28
29
30
# File 'lib/rattler/compiler/parser_generator/rule_set_generator.rb', line 26

def gen_start_rule(start_rule)
  (@g << "# @private").newline
  @g.block('def start_rule #:nodoc:') { @g << ":#{start_rule}"}.newline
  @g.newline
end

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



14
15
16
17
# File 'lib/rattler/compiler/parser_generator/rule_set_generator.rb', line 14

def generate(parser, opts={})
  gen_rules parser, opts
  self
end