Class: Rattler::Compiler::ParserGenerator::ChoiceGenerator

Inherits:
ExprGenerator
  • Object
show all
Includes:
NestedSubGenerating
Defined in:
lib/rattler/compiler/parser_generator/choice_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubGenerating

#gen_nested, #gen_top_level, #generate

Methods inherited from ExprGenerator

#gen_intermediate, #gen_intermediate_disallow, #initialize

Constructor Details

This class inherits a constructor from Rattler::Compiler::ParserGenerator::ExprGenerator

Class Method Details

.nested(*args) ⇒ Object



76
77
78
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 76

def ChoiceGenerator.nested(*args)
  NestedChoiceGenerator.new(*args)
end

.top_level(*args) ⇒ Object



85
86
87
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 85

def ChoiceGenerator.top_level(*args)
  TopLevelChoiceGenerator.new(*args)
end

Instance Method Details

#gen_assert(choice, scope = ParserScope.empty) ⇒ Object



15
16
17
18
19
20
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 15

def gen_assert(choice, scope = ParserScope.empty)
  expr do
    gen_intermediate_assert choice, scope
    @g << ' && true'
  end
end

#gen_basic(choice, scope = ParserScope.empty) ⇒ Object



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

def gen_basic(choice, scope = ParserScope.empty)
  expr :block do
    @g.intersperse_nl(choice, ' ||') {|_| generate _, :basic, scope }
  end
end

#gen_disallow(choice, scope = ParserScope.empty) ⇒ Object



22
23
24
25
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 22

def gen_disallow(choice, scope = ParserScope.empty)
  @g << '!'
  gen_intermediate_assert choice, scope
end

#gen_intermediate_assert(choice, scope = ParserScope.empty) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 40

def gen_intermediate_assert(choice, scope = ParserScope.empty)
  @g.block 'begin' do
    @g.intersperse_nl(choice, ' ||') do |_|
      generate _, :intermediate_assert, scope
    end
  end
end

#gen_intermediate_skip(choice, scope = ParserScope.empty) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 48

def gen_intermediate_skip(choice, scope = ParserScope.empty)
  @g.block 'begin' do
    @g.intersperse_nl(choice, ' ||') do |_|
      generate _, :intermediate_skip, scope
    end
  end
end

#gen_skip(choice, scope = ParserScope.empty) ⇒ Object



33
34
35
36
37
38
# File 'lib/rattler/compiler/parser_generator/choice_generator.rb', line 33

def gen_skip(choice, scope = ParserScope.empty)
  expr do
    gen_intermediate_skip choice, scope
    @g << ' && true'
  end
end

#gen_token(choice, scope = ParserScope.empty) ⇒ Object



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

def gen_token(choice, scope = ParserScope.empty)
  expr :block do
    @g.intersperse_nl(choice, ' ||') {|_| generate _, :token, scope }
  end
end