Class: Parslet::Accelerator::Application Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(atom, rules) ⇒ Application

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Application.


5
6
7
8
# File 'lib/parslet/accelerator/application.rb', line 5

def initialize atom, rules
  @atom = atom
  @rules = rules
end

Instance Method Details

#callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

def call
  @atom.accept(self)
end

#transform(atom) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/parslet/accelerator/application.rb', line 44

def transform atom
  @rules.each do |expr, action|
    # Try and match each rule in turn
    binding = Parslet::Accelerator.match(atom, expr)
    if binding
      # On a successful match, allow the rule action to transform the
      # parslet into something new. 
      ctx = Parslet::Context.new(binding)
      return ctx.instance_eval(&action)
    end
  end # rules.each 

  # If no rule matches, this is the fallback - a clean new parslet atom.
  return atom
end

#visit_alternative(alternatives) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


26
27
28
29
# File 'lib/parslet/accelerator/application.rb', line 26

def visit_alternative(alternatives)
  transform Parslet::Atoms::Alternative.new(
    *alternatives.map { |atom| atom.accept(self) })
end

#visit_entity(name, block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

def visit_entity(name, block)
  transform Parslet::Atoms::Entity.new(name) { block.call.accept(self) }
end

#visit_lookahead(positive, atom) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


34
35
36
# File 'lib/parslet/accelerator/application.rb', line 34

def visit_lookahead(positive, atom)
  transform Parslet::Atoms::Lookahead.new(atom, positive)
end

#visit_named(name, atom) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


20
21
22
# File 'lib/parslet/accelerator/application.rb', line 20

def visit_named(name, atom)
  transform Parslet::Atoms::Named.new(atom.accept(self), name)
end

#visit_parser(root) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

def visit_parser(root)
  transform root.accept(self)
end

#visit_re(regexp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

def visit_re(regexp)
  transform Parslet::Atoms::Re.new(regexp)
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


23
24
25
# File 'lib/parslet/accelerator/application.rb', line 23

def visit_repetition(tag, min, max, atom)
  transform Parslet::Atoms::Repetition.new(atom.accept(self), min, max, tag)
end

#visit_sequence(sequence) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


30
31
32
33
# File 'lib/parslet/accelerator/application.rb', line 30

def visit_sequence(sequence)
  transform Parslet::Atoms::Sequence.new(
    *sequence.map { |atom| atom.accept(self) })
end

#visit_str(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


40
41
42
# File 'lib/parslet/accelerator/application.rb', line 40

def visit_str(str)
  transform Parslet::Atoms::Str.new(str)
end