Module: Rattler::Compiler::ParserGenerator::SequenceGenerating

Includes:
NestedSubGenerating
Included in:
AttributedSequenceGenerator, SequenceGenerator
Defined in:
lib/rattler/compiler/parser_generator/sequence_generating.rb

Instance Method Summary collapse

Methods included from SubGenerating

#gen_nested, #gen_top_level, #generate

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rattler/compiler/parser_generator/sequence_generating.rb', line 8

def gen_assert(sequence, scope = ParserScope.empty)
  expr :block do
    lookahead do
      @g.block("#{result_name} = begin") do
        gen_children_matching(sequence, scope.nest) do |last_child, scope|
          @g.suffix(' &&') { gen_nested last_child, :intermediate_skip, scope }
          @g.newline << 'true'
        end
      end
      @g.newline
    end
    @g << result_name
  end
end

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



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rattler/compiler/parser_generator/sequence_generating.rb', line 23

def gen_disallow(sequence, scope = ParserScope.empty)
  expr :block do
    lookahead do
      @g.block("#{result_name} = !begin") do
        gen_children_matching(sequence, scope.nest) do |last_child, scope|
          gen_nested last_child, :intermediate_skip, scope
        end
      end
      @g.newline
    end
    @g << result_name
  end
end

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



46
47
48
49
50
51
52
53
# File 'lib/rattler/compiler/parser_generator/sequence_generating.rb', line 46

def gen_skip(sequence, scope = ParserScope.empty)
  with_backtracking do
    gen_children_matching(sequence, scope.nest) do |last_child, scope|
      @g.suffix(' &&') { gen_matching last_child, scope }
      @g.newline << 'true'
    end
  end
end

#gen_token(sequence, scope = ParserScope.empty) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rattler/compiler/parser_generator/sequence_generating.rb', line 37

def gen_token(sequence, scope = ParserScope.empty)
  with_backtracking do
    gen_children_matching(sequence, scope.nest) do |last_child, scope|
      @g.suffix(' &&') { gen_nested last_child, :intermediate_skip, scope }
      @g.newline << "@scanner.string[#{saved_pos_name}...(@scanner.pos)]"
    end
  end
end