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
@see Parslet::Accelerator#str @see Parslet::Accelerator#re @see Parslet::Accelerator#any
@see Parslet::Accelerator
# File lib/parslet/accelerator.rb, line 41 def initialize(type, *args) @type = type @args = args end
@return [Expression]
# File lib/parslet/accelerator.rb, line 47 def >> other_expr join_or_new :seq, other_expr end
@return [Expression]
# File lib/parslet/accelerator.rb, line 57 def absent? Expression.new(:absent, self) end
@return [Expression]
# File lib/parslet/accelerator.rb, line 71 def as name Expression.new(:as, name) end
@api private @return [Expression]
# 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
@return [Expression]
# File lib/parslet/accelerator.rb, line 61 def present? Expression.new(:present, self) end
@return [Expression]
# File lib/parslet/accelerator.rb, line 66 def repeat min=0, max=nil Expression.new(:rep, min, max, self) end
@return [Expression]
# File lib/parslet/accelerator.rb, line 52 def | other_expr join_or_new :alt, other_expr end