Class: Rattler::Compiler::ParserGenerator::GeneralRepeatGenerator

Inherits:
ExprGenerator
  • Object
show all
Includes:
NestedSubGenerating
Defined in:
lib/rattler/compiler/parser_generator/general_repeat_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_assert, #gen_intermediate_disallow, #gen_intermediate_skip, #initialize

Constructor Details

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

Class Method Details

.nested(*args) ⇒ Object



158
159
160
# File 'lib/rattler/compiler/parser_generator/general_repeat_generator.rb', line 158

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

.top_level(*args) ⇒ Object



167
168
169
# File 'lib/rattler/compiler/parser_generator/general_repeat_generator.rb', line 167

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

Instance Method Details

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



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

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

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



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

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

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



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

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

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



32
33
34
35
36
37
38
39
40
# File 'lib/rattler/compiler/parser_generator/general_repeat_generator.rb', line 32

def gen_skip(repeat, scope = ParserScope.empty)
  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 = ParserScope.empty) ⇒ Object



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

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