Module: Rattler::BackEnd::ParserGenerator::RepeatGenerating

Included in:
OneOrMoreGenerator, ZeroOrMoreGenerator
Defined in:
lib/rattler/back_end/parser_generator/repeat_generating.rb

Instance Method Summary collapse

Instance Method Details

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

:nodoc:



7
8
9
10
11
12
13
14
15
16
# File 'lib/rattler/back_end/parser_generator/repeat_generating.rb', line 7

def gen_basic(repeat, scope={})
  if repeat.capturing?
    expr :block do
      gen_loop(repeat) { |child| gen_nested child, :basic, scope }
      gen_result accumulator_name
    end
  else
    gen_skip repeat, scope
  end
end

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



25
26
27
28
29
30
# File 'lib/rattler/back_end/parser_generator/repeat_generating.rb', line 25

def gen_direct_action(repeat, code, scope={})
  expr :block do
    gen_loop repeat
    gen_result('(' + code.bind(scope, ["select_captures(#{accumulator_name})"]) + ')')
  end
end

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



18
19
20
21
22
23
# File 'lib/rattler/back_end/parser_generator/repeat_generating.rb', line 18

def gen_dispatch_action(repeat, code, scope={})
  expr :block do
    gen_loop repeat
    gen_result code.bind(scope, "select_captures(#{accumulator_name})")
  end
end

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



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

def gen_token(repeat, scope={})
  expr :block do
    gen_loop(repeat) { |child| generate child, :token, scope }
    gen_result "#{accumulator_name}.join"
  end
end