FastParse extensions
Small utility extensions for fastparse.
importfastparse_ext._defUntil(parser: =>P[_]):P[Unit]Moves the index just to just before
parsersucceeds.Convenience for:
(!parser ~ AnyChar).rep ~ &(parser)
defUpTo[T](parser: =>P[T]):P[T]Ignores anything up to
parsersuccess.Convenience for:
(!parser ~ AnyChar).rep ~ parser
defSetIndex(index: Int)Moves the parsing index to a certain position.
Warning: use with caution.
defWithin[I](outer: =>P[_], inner: P[_] =>P[I], endAtOuter: Boolean=false):P[I]
defWithin2[O,I](outer: =>P[O], inner: P[_] =>P[I], endAtOuter: Boolean=false):P[_] =>P[I]):P[(O, I)]
defNotWithin[O](outer: =>P[O], inner: P[_] =>P[I]):P[_] =>P[_]):P[O]Constrains an inner parser to run only inside an outer parser range.
IMPORTANT NOTE
Inner parser is always passed as partially applied function, because it will be run with a new index-delimited input.
Define your inner parser as a function
def someInner[_: P] = ...and provide it partially applied:someInner(_)If
outersucceeds, theinnerparser is run from outer's start position, but it can never get past outer's end position. By default, the end position is that of theinnerparser, unlessendAtOuter = trueis explicitly given.The result of Whithin2 is a tuple with the result of both parsers.
NotWithin succeeds only when inner fails inside of outer.
See tests for runnable examples.