module Parslet
def self.included(base)
{Parslet::ClassMethods}.
Extends classes that include Parslet with the module
def self.included(base) base.extend(ClassMethods) end
def any
-
(Parslet::Atoms::Re)
- a parslet atom
def any Atoms::Re.new('.') end
def dynamic(&block)
dynamic { rand() < 0.5 ? str('a') : str('b') }
# Parses either 'a' or 'b', depending on the weather
Example:
abnormalitites - use sparingly where other constructs fail.
Dynamic parse pieces are never cached and can introduce performance
return a result from a parse.
either return a parser at runtime, which will be applied on the input, or
Designates a piece of the parser as being dynamic. Dynamic parsers can
def dynamic(&block) Parslet::Atoms::Dynamic.new(block) end
def exp(str)
-
(Parslet::Atoms::Base)
- the corresponding parslet parser
Parameters:
-
str
(String
) -- a treetop expression
def exp(str) Parslet::Expression.new(str).to_parslet end
def infix_expression(element, *operations, &reducer)
- See: Parslet::Atoms::Infix -
Parameters:
-
operations
(Array<(Parslet::Atoms::Base, Integer, {:left, :right})>
) -- -
element
(Parslet::Atoms::Base
) -- elements that take the NUMBER position
def infix_expression(element, *operations, &reducer) Parslet::Atoms::Infix.new(element, operations, &reducer) end
def match(str=nil)
-
(Parslet::Atoms::Re)
- a parslet atom
Parameters:
-
str
(String
) -- character class to match (regexp syntax)
Overloads:
-
match(str)
def match(str=nil) return DelayedMatchConstructor.new unless str return Atoms::Re.new(str) end
def scope(&block)
scope { str('a').capture(:a) }
# exists.
# :a from the outer scope will be available again, if such a thing
# :a will be available until the end of the block. Afterwards,
Example:
given and the old values will be restored after the block.
accessible, but new values stored will only be available during the block
Introduces a new capture scope. This means that all old captures stay
def scope(&block) Parslet::Atoms::Scope.new(block) end
def sequence(symbol)
see {Parslet::Transform}
:body => 'a'
.The above example would match
:body => ['a', 'b']
, but not{ :body => sequence(:declarations) }
# This would match a body element that contains several declarations.
matched sequence in the returned dictionary.
sequence of elements. The +symbol+ you specify will be the key for the
Returns a placeholder for a tree transformation that will only match a
def sequence(symbol) Pattern::SequenceBind.new(symbol) end
def simple(symbol)
see {Parslet::Transform}
{ :header => simple(:header) }
# Matches a single header.
doesn't match.
simple elements. This matches everything that
#sequence
Returns a placeholder for a tree transformation that will only match
def simple(symbol) Pattern::SimpleBind.new(symbol) end
def str(str)
-
(Parslet::Atoms::Str)
- a parslet atom
Parameters:
-
str
(String
) -- string to match verbatim
def str(str) Atoms::Str.new(str) end
def subtree(symbol)
{ :expression => subtree(:exp) }
any kind of subtree.
Returns a placeholder for tree transformation patterns that will match
def subtree(symbol) Pattern::SubtreeBind.new(symbol) end