module ParsletCombining
# Convenience method.
def memoizing_parse string, options = {}
- self.to_parseable.memoizing_parse string, options
+ to_parseable.memoizing_parse string, options
end
# Convenience method.
def parse string, options = {}
- self.to_parseable.parse string, options
+ to_parseable.parse string, options
end
# Defines a sequence of Parslets (or ParsletCombinations).
# Returns a ParsletSequence instance.
def sequence first, second, *others
- Walrat::ParsletSequence.new first.to_parseable,
+ ParsletSequence.new first.to_parseable,
second.to_parseable, *others
end
# Shorthand for ParsletCombining.sequence(first, second).
def &(next_parslet)
- self.sequence self, next_parslet
+ sequence self, next_parslet
end
# Defines a sequence of Parslets similar to the sequence method but with
# 'foo' >> 'bar'.one_or_more # returns results like ['foo', 'bar', 'bar', 'bar']
#
def merge first, second, *others
- Walrat::ParsletMerge.new first.to_parseable,
+ ParsletMerge.new first.to_parseable,
second.to_parseable, *others
end
# Shorthand for ParsletCombining.sequence(first, second)
def >>(next_parslet)
- self.merge self, next_parslet
+ merge self, next_parslet
end
# Defines a choice of Parslets (or ParsletCombinations).
# Returns a ParsletChoice instance.
def choice left, right, *others
- Walrat::ParsletChoice.new left.to_parseable,
+ ParsletChoice.new left.to_parseable,
right.to_parseable, *others
end
# Shorthand for ParsletCombining.choice(left, right)
def |(alternative_parslet)
- self.choice self, alternative_parslet
+ choice self, alternative_parslet
end
# Defines a repetition of the supplied Parslet (or ParsletCombination).
# Returns a ParsletRepetition instance.
def repetition parslet, min, max
- Walrat::ParsletRepetition.new parslet.to_parseable, min, max
+ ParsletRepetition.new parslet.to_parseable, min, max
end
# Shorthand for ParsletCombining.repetition.
def repeat min = nil, max = nil
- self.repetition self, min, max
+ repetition self, min, max
end
def repetition_with_default parslet, min, max, default
- Walrat::ParsletRepetitionDefault.new parslet.to_parseable, min,
+ ParsletRepetitionDefault.new parslet.to_parseable, min,
max, default
end
def repeat_with_default min = nil, max = nil, default = nil
- self.repetition_with_default self, min, max, default
+ repetition_with_default self, min, max, default
end
# Shorthand for ParsletCombining.repetition(0, 1).
# explicitly passing an "ArrayResult.new")
def optional default_return_value = NoParameterMarker.instance
if default_return_value == NoParameterMarker.instance
- self.repeat 0, 1 # default behaviour
+ repeat 0, 1 # default behaviour
else
- self.repeat_with_default 0, 1, default_return_value
+ repeat_with_default 0, 1, default_return_value
end
end
# Alternative to optional.
def zero_or_one
- self.optional
+ optional
end
# possible synonym "star"
def zero_or_more default_return_value = NoParameterMarker.instance
if default_return_value == NoParameterMarker.instance
- self.repeat 0 # default behaviour
+ repeat 0 # default behaviour
else
- self.repeat_with_default 0, nil, default_return_value
+ repeat_with_default 0, nil, default_return_value
end
end
# possible synonym "plus"
def one_or_more
- self.repeat 1
+ repeat 1
end
# Parsing Expression Grammar support.
# Succeeds if parslet succeeds but consumes no input (throws an
# :AndPredicateSuccess symbol).
def and_predicate parslet
- Walrat::AndPredicate.new parslet.to_parseable
+ AndPredicate.new parslet.to_parseable
end
# Shorthand for and_predicate
# that "?" at the end of a method name should indicate a method that
# returns true or false.
def and?
- self.and_predicate self
+ and_predicate self
end
# Parsing Expression Grammar support.
# operator, like this:
# rule :foo, :p1 & :p2.not_predicate
# rule :foo, :p1 & :p2.not!
- def not_predicate parslet
- Walrat::NotPredicate.new parslet.to_parseable
+ def not_predicate parslet = self
+ NotPredicate.new parslet.to_parseable
end
# Shorthand for not_predicate.
# that "!" at the end of a method name should indicate a destructive
# behaviour on (mutation of) the receiver.
def not!
- self.not_predicate self
+ not_predicate self
end
# Succeeds if parsing succeeds, consuming the output, but doesn't actually
# This is for elements which are required but which shouldn't appear in the
# final AST.
def omission parslet
- Walrat::ParsletOmission.new parslet.to_parseable
+ ParsletOmission.new parslet.to_parseable
end
# Shorthand for ParsletCombining.omission
def skip
- self.omission self
+ omission self
end
end # module ParsletCombining
end # module Walrat