class Parslet::Accelerator::Expression

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

Attributes

args[R]
type[R]

Public Class Methods

new(type, *args) click to toggle source
# File lib/parslet/accelerator.rb, line 41
def initialize(type, *args)
  @type = type
  @args = args
end

Public Instance Methods

>>(other_expr) click to toggle source

@return [Expression]

# File lib/parslet/accelerator.rb, line 47
def >> other_expr
  join_or_new :seq, other_expr
end
absent?() click to toggle source

@return [Expression]

# File lib/parslet/accelerator.rb, line 57
def absent?
  Expression.new(:absent, self)
end
as(name) click to toggle source

@return [Expression]

# File lib/parslet/accelerator.rb, line 71
def as name
  Expression.new(:as, name)
end
join_or_new(tag, other_expr) click to toggle source

@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
present?() click to toggle source

@return [Expression]

# File lib/parslet/accelerator.rb, line 61
def present?
  Expression.new(:present, self)
end
repeat(min=0, max=nil) click to toggle source

@return [Expression]

# File lib/parslet/accelerator.rb, line 66
def repeat min=0, max=nil
  Expression.new(:rep, min, max, self)
end
|(other_expr) click to toggle source

@return [Expression]

# File lib/parslet/accelerator.rb, line 52
def | other_expr
  join_or_new :alt, other_expr
end