Class: Rattler::BackEnd::ParserGenerator::ChoiceGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parsers

define

Methods inherited from ExprGenerator

#gen_intermediate, #gen_intermediate_disallow, #initialize

Constructor Details

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

Class Method Details

.nested(*args) ⇒ Object



88
89
90
# File 'lib/rattler/back_end/parser_generator/choice_generator.rb', line 88

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

.top_level(*args) ⇒ Object



97
98
99
# File 'lib/rattler/back_end/parser_generator/choice_generator.rb', line 97

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

Instance Method Details

#gen_assert(choice, scope = {}) ⇒ Object



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

def gen_assert(choice, scope={})
  expr do
    gen_intermediate_assert choice, scope
    @g << ' && true'
  end
end

#gen_basic(choice, scope = {}) ⇒ Object



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

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

#gen_direct_action(choice, code, scope = {}) ⇒ Object



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

def gen_direct_action(choice, code, scope={})
  expr :block do
    gen_action_code(choice) { "(#{code.bind scope, [result_name]})" }
  end
end

#gen_disallow(choice, scope = {}) ⇒ Object



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

def gen_disallow(choice, scope={})
  @g << '!'
  gen_intermediate_assert choice, scope
end

#gen_dispatch_action(choice, code, scope = {}) ⇒ Object



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

def gen_dispatch_action(choice, code, scope={})
  expr :block do
    gen_action_code(choice) { code.bind scope, "[#{result_name}]" }
  end
end

#gen_intermediate_assert(choice, scope = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/rattler/back_end/parser_generator/choice_generator.rb', line 52

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

#gen_intermediate_skip(choice, scope = {}) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/rattler/back_end/parser_generator/choice_generator.rb', line 60

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

#gen_skip(choice, scope = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/rattler/back_end/parser_generator/choice_generator.rb', line 45

def gen_skip(choice, scope={})
  expr do
    gen_intermediate_skip choice, scope
    @g << ' && true'
  end
end

#gen_token(choice, scope = {}) ⇒ Object



39
40
41
42
43
# File 'lib/rattler/back_end/parser_generator/choice_generator.rb', line 39

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