Class: Rattler::BackEnd::ParserGenerator::GeneralRepeatGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parsers

define

Methods inherited from ExprGenerator

#gen_intermediate, #gen_intermediate_assert, #gen_intermediate_disallow, #gen_intermediate_skip, #initialize

Constructor Details

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

Class Method Details

.nested(*args) ⇒ Object



164
165
166
# File 'lib/rattler/back_end/parser_generator/general_repeat_generator.rb', line 164

def GeneralRepeatGenerator.nested(*args)
  NestedGeneralRepeatGenerator.new(*args)
end

.top_level(*args) ⇒ Object



173
174
175
# File 'lib/rattler/back_end/parser_generator/general_repeat_generator.rb', line 173

def GeneralRepeatGenerator.top_level(*args)
  TopLevelGeneralRepeatGenerator.new(*args)
end

Instance Method Details

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



17
18
19
# File 'lib/rattler/back_end/parser_generator/general_repeat_generator.rb', line 17

def gen_assert(repeat, scope={})
  gen_predicate(repeat, scope) { gen_assert_result repeat }
end

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



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

def gen_basic(repeat, scope={})
  if repeat.capturing?
    gen_capturing repeat, scope
  else
    gen_skip repeat, scope
  end
end

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



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

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

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



21
22
23
# File 'lib/rattler/back_end/parser_generator/general_repeat_generator.rb', line 21

def gen_disallow(repeat, scope={})
  gen_predicate(repeat, scope) { gen_disallow_result repeat }
end

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



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

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

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



46
47
48
49
50
51
52
53
54
# File 'lib/rattler/back_end/parser_generator/general_repeat_generator.rb', line 46

def gen_skip(repeat, scope={})
  expr :block do
    setup_skip_loop repeat
    @g << 'while '
    generate repeat.child, :intermediate_skip, scope
    @g.block('') { gen_skip_loop_body repeat }.newline
    gen_skip_result repeat
  end
end

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



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

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