Module: Rattler::BackEnd::ParserGenerator::OptionalGenerating

Defined in:
lib/rattler/back_end/parser_generator/optional_generating.rb

Instance Method Summary collapse

Instance Method Details

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

:nodoc:



7
8
9
# File 'lib/rattler/back_end/parser_generator/optional_generating.rb', line 7

def gen_assert(optional, scope={})
  @g << 'true'
end

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



22
23
24
25
26
27
28
29
# File 'lib/rattler/back_end/parser_generator/optional_generating.rb', line 22

def gen_direct_action(optional, code, scope={})
  expr :block do
    @g << "#{result_name} = "
    generate optional.child, :basic, scope
    @g.newline <<
      '(' << code.bind(scope, ["(#{result_name} ? [#{result_name}] : [])"]) << ')'
  end
end

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



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

def gen_disallow(optional, scope={})
  @g << 'false'
end

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



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

def gen_dispatch_action(optional, code, scope={})
  expr :block do
    gen_loop optional, scope
    @g.newline << code.bind(scope, "#{result_name} ? [#{result_name}] : []")
  end
end

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



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

def gen_skip(optional, scope={})
  expr :block do
    generate optional.child, :intermediate_skip, scope
    @g.newline << 'true'
  end
end

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



31
32
33
34
35
36
# File 'lib/rattler/back_end/parser_generator/optional_generating.rb', line 31

def gen_token(optional, scope={})
  expr :block do
    generate optional.child, :token, scope
    @g << " || ''"
  end
end