Class: Parslet::Parser::Visitors::Citrus

Inherits:
Object
  • Object
show all
Defined in:
lib/parslet/export.rb

Direct Known Subclasses

Treetop

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Citrus

Returns a new instance of Citrus.



10
11
12
# File 'lib/parslet/export.rb', line 10

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/parslet/export.rb', line 9

def context
  @context
end

#outputObject (readonly)

Returns the value of attribute output.



9
10
11
# File 'lib/parslet/export.rb', line 9

def output
  @output
end

Instance Method Details

#visit_alternative(alternatives) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/parslet/export.rb', line 40

def visit_alternative(alternatives)
  '(' <<
  alternatives.
    map { |el| el.accept(self) }.
    join(' | ') <<
  ')'
end

#visit_entity(name, block) ⇒ Object



21
22
23
24
25
# File 'lib/parslet/export.rb', line 21

def visit_entity(name, block)
  context.deferred(name, block)

  "(#{context.mangle_name(name)})"
end

#visit_lookahead(positive, bound_parslet) ⇒ Object



48
49
50
51
# File 'lib/parslet/export.rb', line 48

def visit_lookahead(positive, bound_parslet)
  (positive ? '&' : '!') <<
  bound_parslet.accept(self)
end

#visit_named(name, parslet) ⇒ Object



26
27
28
# File 'lib/parslet/export.rb', line 26

def visit_named(name, parslet)
  parslet.accept(self)
end

#visit_re(match) ⇒ Object



17
18
19
# File 'lib/parslet/export.rb', line 17

def visit_re(match)
  match.to_s
end

#visit_repetition(tag, min, max, parslet) ⇒ Object



37
38
39
# File 'lib/parslet/export.rb', line 37

def visit_repetition(tag, min, max, parslet)
  parslet.accept(self) << "#{min}*#{max}"
end

#visit_sequence(parslets) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/parslet/export.rb', line 30

def visit_sequence(parslets)
  '(' <<
  parslets.
    map { |el| el.accept(self) }.
    join(' ') <<
  ')'
end

#visit_str(str) ⇒ Object



14
15
16
# File 'lib/parslet/export.rb', line 14

def visit_str(str)
  "\"#{str.inspect[1..-2]}\""
end