Class: Rattler::Compiler::ParserGenerator::GeneralListGenerator

Inherits:
ExprGenerator
  • Object
show all
Includes:
NestedSubGenerating
Defined in:
lib/rattler/compiler/parser_generator/general_list_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, #gen_token

Constructor Details

#initialize(*args) ⇒ GeneralListGenerator

Returns a new instance of GeneralListGenerator.



9
10
11
12
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 9

def initialize(*args)
  @init_args = args
  super
end

Class Method Details

.nested(*args) ⇒ Object



169
170
171
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 169

def GeneralListGenerator.nested(*args)
  NestedGeneralListGenerator.new(*args)
end

.top_level(*args) ⇒ Object



178
179
180
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 178

def GeneralListGenerator.top_level(*args)
  TopLevelGeneralListGenerator.new(*args)
end

Instance Method Details

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



22
23
24
25
26
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 22

def gen_assert(list, scope = ParserScope.empty)
  gen_predicate(list, scope) do
    @g.newline << "#{count_name} >= #{list.lower_bound}"
  end
end

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



14
15
16
17
18
19
20
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 14

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

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



28
29
30
31
32
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 28

def gen_disallow(list, scope = ParserScope.empty)
  gen_predicate(list, scope) do
    @g.newline << "#{count_name} < #{list.lower_bound}"
  end
end

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



34
35
36
37
38
39
40
41
# File 'lib/rattler/compiler/parser_generator/general_list_generator.rb', line 34

def gen_skip(list, scope = ParserScope.empty)
  expr :block do
    (@g << "#{count_name} = 0").newline
    (@g << "#{start_pos_name} = @scanner.pos").newline
    gen_skipping(list, scope) { (@g << "#{count_name} += 1").newline }
    gen_skipping_result list
  end
end