Class: Rattler::Compiler::ParserGenerator::MatchGenerator

Inherits:
ExprGenerator
  • Object
show all
Defined in:
lib/rattler/compiler/parser_generator/match_generator.rb

Direct Known Subclasses

NestedMatchGenerator, TopLevelMatchGenerator

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExprGenerator

#gen_intermediate, #initialize

Constructor Details

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

Class Method Details

.nested(*args) ⇒ Object



56
57
58
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 56

def MatchGenerator.nested(*args)
  NestedMatchGenerator.new(*args)
end

.top_level(*args) ⇒ Object



65
66
67
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 65

def MatchGenerator.top_level(*args)
  TopLevelMatchGenerator.new(*args)
end

Instance Method Details

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



12
13
14
15
16
17
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 12

def gen_assert(match, scope = ParserScope.empty)
  expr do
    gen_intermediate_assert match, scope
    @g << ' && true'
  end
end

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

:nodoc:



8
9
10
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 8

def gen_basic(match, scope = ParserScope.empty)
  @g << "@scanner.scan(#{match.re.inspect})"
end

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



19
20
21
22
23
24
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 19

def gen_disallow(match, scope = ParserScope.empty)
  expr do
    gen_intermediate_disallow match, scope
    @g << ' && true'
  end
end

#gen_intermediate_assert(match, scope = ParserScope.empty) ⇒ Object



37
38
39
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 37

def gen_intermediate_assert(match, scope = ParserScope.empty)
  @g << "@scanner.skip(#{/(?=#{match.re.source})/.inspect})"
end

#gen_intermediate_disallow(match, scope = ParserScope.empty) ⇒ Object



41
42
43
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 41

def gen_intermediate_disallow(match, scope = ParserScope.empty)
  @g << "@scanner.skip(#{/(?!#{match.re.source})/.inspect})"
end

#gen_intermediate_skip(match, scope = ParserScope.empty) ⇒ Object



45
46
47
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 45

def gen_intermediate_skip(match, scope = ParserScope.empty)
  @g << "@scanner.skip(#{match.re.inspect})"
end

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



30
31
32
33
34
35
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 30

def gen_skip(match, scope = ParserScope.empty)
  expr do
    gen_intermediate_skip match, scope
    @g << ' && true'
  end
end

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



26
27
28
# File 'lib/rattler/compiler/parser_generator/match_generator.rb', line 26

def gen_token(match, scope = ParserScope.empty)
  gen_basic match, scope
end