Class: Parslet::Accelerator::Expression
- Inherits:
-
Object
- Object
- Parslet::Accelerator::Expression
- Defined in:
- lib/parslet/accelerator.rb
Overview
An expression to match against a tree of parser atoms. Normally, an expression is produced by Parslet::Accelerator.any, Parslet::Accelerator.str or Parslet::Accelerator.re.
Expressions can be chained much like parslet atoms can be:
expr.repeat(1) # matching repetition
expr.absent? # matching absent?
expr.present? # matching present?
expr1 >> expr2 # matching a sequence
expr1 | expr2 # matching an alternation
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #>>(other_expr) ⇒ Expression
- #absent? ⇒ Expression
- #as(name) ⇒ Expression
-
#initialize(type, *args) ⇒ Expression
constructor
A new instance of Expression.
- #join_or_new(tag, other_expr) ⇒ Expression private
- #present? ⇒ Expression
- #repeat(min = 0, max = nil) ⇒ Expression
- #|(other_expr) ⇒ Expression
Constructor Details
#initialize(type, *args) ⇒ Expression
Returns a new instance of Expression.
41 42 43 44 |
# File 'lib/parslet/accelerator.rb', line 41 def initialize(type, *args) @type = type @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
39 40 41 |
# File 'lib/parslet/accelerator.rb', line 39 def args @args end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
38 39 40 |
# File 'lib/parslet/accelerator.rb', line 38 def type @type end |
Instance Method Details
#>>(other_expr) ⇒ Expression
47 48 49 |
# File 'lib/parslet/accelerator.rb', line 47 def >> other_expr join_or_new :seq, other_expr end |
#absent? ⇒ Expression
57 58 59 |
# File 'lib/parslet/accelerator.rb', line 57 def absent? Expression.new(:absent, self) end |
#as(name) ⇒ Expression
71 72 73 |
# File 'lib/parslet/accelerator.rb', line 71 def as name Expression.new(:as, name) end |
#join_or_new(tag, other_expr) ⇒ Expression
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.
77 78 79 80 81 82 83 84 |
# File 'lib/parslet/accelerator.rb', line 77 def join_or_new tag, other_expr if type == tag @args << other_expr self else Expression.new(tag, self, other_expr) end end |
#present? ⇒ Expression
61 62 63 |
# File 'lib/parslet/accelerator.rb', line 61 def present? Expression.new(:present, self) end |
#repeat(min = 0, max = nil) ⇒ Expression
66 67 68 |
# File 'lib/parslet/accelerator.rb', line 66 def repeat min=0, max=nil Expression.new(:rep, min, max, self) end |
#|(other_expr) ⇒ Expression
52 53 54 |
# File 'lib/parslet/accelerator.rb', line 52 def | other_expr join_or_new :alt, other_expr end |