vic/fastparse_ext
{ "defaultBranch": "master", "description": "FastParse extensions", "fullName": "vic/fastparse_ext", "homepage": "http://www.lihaoyi.com/fastparse/", "language": "Scala", "name": "fastparse_ext", "pushedAt": "2025-07-15T04:40:24Z", "stargazersCount": 4, "updatedAt": "2025-07-15T04:40:27Z", "url": "https://github.com/vic/fastparse_ext"}Small utility extensions for fastparse.
import fastparse_ext._def Until(parser: => P[_]): P[Unit]Moves the index just to just before
parsersucceeds.Convenience for:
(!parser ~ AnyChar).rep ~ &(parser)
def UpTo[T]!(parser: => P[T]): P[T]Ignores anything up to
parsersuccess.Convenience for:
(!parser ~ AnyChar).rep ~ parser
SetIndex
Section titled “SetIndex”def SetIndex(index: Int)Moves the parsing index to a certain position.
Warning: use with caution.
Within
Section titled “Within”def Within[I]!(outer: => P[_], inner: P[_] => P[I], endAtOuter: Boolean = false): P[I]def Within2[O,I]!(outer: => P[O], inner: P[_] => P[I], endAtOuter: Boolean = false): P[_] => P[I]): P[(O, I)]def NotWithin[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]!(fastparse_ext/test/src/fastparse_ext/FastparseExtTest.scala) for runnable examples.