fastparse
package fastparse
- Alphabetic
- By Inheritance
- fastparse
- SharedPackageDefs
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- trait BufferedParserInput extends ParserInput
- final class ByNameOps[T] extends AnyVal
- implicit final class EagerOps[T] extends AnyVal
- case class IndexedParserInput(data: String) extends ParserInput with Product with Serializable
-
trait
IsReachable extends AnyRef
Trait that represents classes with isReachable method
Trait that represents classes with isReachable method
Currently the only use of it is to avoid the cyclic dependencies between Utils and ParserInput
-
case class
IteratorParserInput(data: Iterator[String]) extends ParserInput with BufferedParserInput with Product with Serializable
Contains buffer - queue of elements that extends from given iterator when particular elements are requested; and shrinks by calling
dropBuffer
method.Contains buffer - queue of elements that extends from given iterator when particular elements are requested; and shrinks by calling
dropBuffer
method.Generally, at any specific time this buffer contains "suffix" of given iterator, e.g. some piece of data from past calls of
next
, which extends by requesting new batches from iterator. Therefore we can denote the same notation of indices as for regularArray
or more abstractIndexedSeq
. The only difference is when index doesn't fit into the bounds of current buffer either the new batches are requested to extend the buffer, either it's inaccessible at all, so calling ofdropBuffer
should guarantee that there won't be any attempts to access to the elements in dropped part of input. -
implicit
class
LogByNameOps[T] extends AnyRef
Separated out from ByNameOps because
.log
isn't easy to make an AnyVal extension method, but it doesn't matter since.log
calls are only for use in development while the other ByNameOps operators are more performance-sensitive - trait LowestPriSequencer[Sequencer[_, _, _]] extends AnyRef
-
type
P[+T] = ParsingRun[T]
Shorthand alias for ParsingRun; this is both the parameter-to and the return type for all Fastparse's parsing methods.
-
type
P0 = ParsingRun[Unit]
Shorthand for
P[Unit]
Shorthand for
P[Unit]
- Definition Classes
- SharedPackageDefs
-
sealed abstract
class
Parsed[+T] extends AnyRef
The outcome of a ParsingRun run, either a success (with value and index) or failure (with associated debugging metadata to help figure out what went wrong).
The outcome of a ParsingRun run, either a success (with value and index) or failure (with associated debugging metadata to help figure out what went wrong).
Doesn't contain any information not already present in ParsingRun, but packages it up nicely in an immutable case class that's easy for external code to make use of.
-
abstract
class
ParserInput extends IsReachable
ParserInput class represents data that is needed to parse.
ParserInput class represents data that is needed to parse.
It can be regular
IndexedSeq
that behaves as simple array orIterator
ofIndexedSeq
batches which is optimized bydropBuffer
method. - trait ParserInputSource extends AnyRef
- trait ParserInputSourceLowPri extends AnyRef
-
final
class
ParsingRun[+T] extends AnyRef
Models an in-progress parsing run; contains all the mutable state that may be necessary during the parse, in order to avoid the individual parsers needing to perform their own allocations and instantiations, and greatly improving performance
Models an in-progress parsing run; contains all the mutable state that may be necessary during the parse, in order to avoid the individual parsers needing to perform their own allocations and instantiations, and greatly improving performance
There are a few patterns that let us program with these mutable variables in a sort-of-pure-functional way:
- If a parser that wishes to ignore changes to a field within their child parsers, a common pattern is to save the value of the field before the wrapped parser runs, and then re-set the field. e.g. this can be used to backtrack index after a lookahead parser finishes
- If a parser wants to read the value of the field "returned" by multiple child parsers, make sure to read the field into a local variable after each child parser is complete to make sure the value you want from an earlier child isn't stomped over by a later child
In general, for a parser to "return" a value in a mutable field, it is sufficient to simply set the value of that field before returning. It is the parent-parser's responsibility to make sure it reads out the value of the field to a local variable before running another child parser that will over-write the mutable field
-
case class
ReaderParserInput(data: Reader, bufferSize: Int) extends ParserInput with BufferedParserInput with Product with Serializable
A ParserInput that pulls data from a given
java.io.Reader
.A ParserInput that pulls data from a given
java.io.Reader
. Typically not used alone, and instead is used as part of a ParserInputSource.FromReadable - trait SequencerGen[Sequencer[_, _, _]] extends LowestPriSequencer[Sequencer]
- trait SharedPackageDefs extends AnyRef
- trait Whitespace extends AnyRef
Value Members
-
def
&(parse: ⇒ P[_])(implicit ctx: P[_]): P[Unit]
Positive lookahead operator: succeeds if the wrapped parser succeeds and fails if the wrapped parser fails, but in all cases consumes zero characters.
-
def
AnyChar(implicit ctx: P[_]): P[Unit]
Parses a single character, any character, as long as there is at least one character for it to parse (i.e.
Parses a single character, any character, as long as there is at least one character for it to parse (i.e. the input isn't at its end)
- Definition Classes
- SharedPackageDefs
- implicit def ByNameOps[T](parse0: ⇒ P[T]): ByNameOps[T]
-
implicit macro
def
ByNameOpsStr(parse0: String)(implicit ctx: P[Any]): ByNameOps[Unit]
Provides ByNameOps extension methods on Strings
-
macro
def
CharIn(s: String*)(implicit ctx: P[_]): P[Unit]
Parses a single character in one of the input strings representing character classes
-
macro
def
CharPred(p: (Char) ⇒ Boolean)(implicit ctx: P[_]): P[Unit]
Parses a single character satisfying the given predicate
-
macro
def
CharsWhile(p: (Char) ⇒ Boolean, min: Int)(implicit ctx: P[_]): P[Unit]
Parses
min
or more characters as long as they satisfy the given predicate -
macro
def
CharsWhile(p: (Char) ⇒ Boolean)(implicit ctx: P[_]): P[Unit]
Parses one or more characters as long as they satisfy the given predicate
-
macro
def
CharsWhileIn(s: String, min: Int)(implicit ctx: P[_]): P[Unit]
Parses
min
or more characters as long as they are contained in one of the input strings representing character classes -
macro
def
CharsWhileIn(s: String)(implicit ctx: P[_]): P[Unit]
Parses one or more characters as long as they are contained in one of the input strings representing character classes
- implicit def DiscardParserValue(p: P[_]): P[Unit]
-
implicit macro
def
EagerOpsStr(parse0: String)(implicit ctx: P[Any]): EagerOps[Unit]
Provides EagerOps extension methods on String
-
def
End(implicit ctx: P[_]): P[Unit]
Parser that is only successful at the end of the input.
Parser that is only successful at the end of the input. Useful to ensure your parser parses the whole file.
- Definition Classes
- SharedPackageDefs
-
def
Fail(msg: String)(implicit ctx: P[_]): P[Nothing]
No-op parser with a custom error message that always fails, consuming zero characters
No-op parser with a custom error message that always fails, consuming zero characters
- Definition Classes
- SharedPackageDefs
-
def
Fail(implicit ctx: P[_]): P[Nothing]
No-op parser that always fails, consuming zero characters
No-op parser that always fails, consuming zero characters
- Definition Classes
- SharedPackageDefs
-
def
IgnoreCase(s: String)(implicit ctx: P[Any]): P[Unit]
Parses a string value case-insensitively
Parses a string value case-insensitively
- Definition Classes
- SharedPackageDefs
-
def
Index(implicit ctx: P[_]): P[Int]
Parser that always succeeds and returns the current index into the parsed input.
Parser that always succeeds and returns the current index into the parsed input. Useful for e.g. capturing source locations so when downstream valiation raises errors you can tell the user where in the input the error originated from
- Definition Classes
- SharedPackageDefs
-
implicit macro
def
LiteralStr(s: String)(implicit ctx: P[Any]): P[Unit]
Parses an exact string value.
-
implicit macro
def
LogOpsStr(parse0: String)(implicit ctx: P[Any]): LogByNameOps[Unit]
Provides logging-related LogByNameOps implicits on String.
-
def
NoCut[T](parse: ⇒ P[T])(implicit ctx: P[_]): P[T]
Allows backtracking regardless of whether cuts happen within the wrapped parser; this is useful for re-using an existing parser with cuts within it, in other parts of your grammar where backtracking is necessary and unavoidable.
Allows backtracking regardless of whether cuts happen within the wrapped parser; this is useful for re-using an existing parser with cuts within it, in other parts of your grammar where backtracking is necessary and unavoidable.
- Definition Classes
- SharedPackageDefs
-
def
NoTrace[T](p: ⇒ P[T])(implicit ctx: P[_]): P[T]
Wraps a parser and ensures that none of the parsers within it leave failure traces in terminalMsgs, though unlike ByNameOps.opaque if there is a failure *within* the wrapped parser the failure's location and error message will still be shown
Wraps a parser and ensures that none of the parsers within it leave failure traces in terminalMsgs, though unlike ByNameOps.opaque if there is a failure *within* the wrapped parser the failure's location and error message will still be shown
Useful for wrapping things like whitespace, code-comment, etc. parsers which can be applied everywhere and are not useful to display to the user as part of the error message.
- Definition Classes
- SharedPackageDefs
-
macro
def
P[T](t: P[T])(implicit name: Name, ctx: P[_]): P[T]
Delimits a named parser.
Delimits a named parser. This name will appear in the parser failure messages and stack traces, and by default is taken from the name of the enclosing method.
- val P: ParsingRun.type
-
def
Pass[T](v: T)(implicit ctx: P[_]): P[T]
No-op parser that always succeeds with the given value, consuming zero characters
No-op parser that always succeeds with the given value, consuming zero characters
- Definition Classes
- SharedPackageDefs
-
def
Pass(implicit ctx: P[_]): P[Unit]
No-op parser that always succeeds, consuming zero characters
No-op parser that always succeeds, consuming zero characters
- Definition Classes
- SharedPackageDefs
-
def
SingleChar(implicit ctx: P[_]): P[Char]
Like AnyChar, but returns the single character it parses.
Like AnyChar, but returns the single character it parses. Useful together with EagerOps.flatMapX to provide one-character-lookahead style parsing: SingleChar consumes the single character, and then EagerOps.flatMapX can
match
on that single character and decide which downstream parser you wish to invoke- Definition Classes
- SharedPackageDefs
-
def
Start(implicit ctx: P[_]): P[Unit]
Parser that is only successful at the start of the input.
Parser that is only successful at the start of the input.
- Definition Classes
- SharedPackageDefs
-
macro
def
StringIn(s: String*)(implicit ctx: P[_]): P[Unit]
Efficiently parses any one of the given Strings; more efficient than chaining EagerOps.| together
-
macro
def
StringInIgnoreCase(s: String*)(implicit ctx: P[_]): P[Unit]
Efficiently parses any one of the given Strings, case-insensitively; more efficient than chaining EagerOps.| together with IgnoreCase
-
def
parse[T](input: ParserInputSource, parser: (P[_]) ⇒ P[T], verboseFailures: Boolean = false, startIndex: Int = 0, instrument: Instrument = null): Parsed[T]
Parses the given input ParserInput using the given parser and returns a Parsed result containing the success value or failure metadata.
Parses the given input ParserInput using the given parser and returns a Parsed result containing the success value or failure metadata.
Can take either a String, an Iterator or strings or a fastparse.ParserInput object
- input
the input to parse
- parser
the parser method to use to parse the input
- verboseFailures
enable this to show a more detailed error message if a parser fails, without needing to run
.traced.trace
. Defaults tofalse
as it slows down parsing considerably- startIndex
where in the input to start parsing
- instrument
Callbacks that get run before and after every named
P(...)
parser
- Definition Classes
- SharedPackageDefs
-
def
parseInputRaw[T](input: ParserInput, parser: (P[_]) ⇒ P[T], verboseFailures: Boolean = false, startIndex: Int = 0, traceIndex: Int = -1, instrument: Instrument = null, enableLogging: Boolean = true): ParsingRun[T]
- Definition Classes
- SharedPackageDefs
-
object
CharPredicates
Fast, pre-computed character predicates for charactes from 0 to 65535
Fast, pre-computed character predicates for charactes from 0 to 65535
Useful because FastParse does it's parsing character by character, so although this doesn't have the full range of the java
Character.getType(c: Int)
functions, it still is good enough for a wide range of use cases -
object
Implicits
Container for all the type-level logic around appending things to tuples or flattening
Seq[Unit]
s intoUnit
s.Container for all the type-level logic around appending things to tuples or flattening
Seq[Unit]
s intoUnit
s.Some of these implicits make liberal use of mutable state, so as to minimize allocations while parsing.
-
object
JavaWhitespace
Whitespace syntax that supports // line-comments and /* */ multiline-comments, *without nesting* of /* */ comments, as is the case in the Java programming language
-
object
JsonnetWhitespace
Whitespace syntax that supports // and # line comments, and /* */ multiline-comments, but *without* nesting of /* */ comments.
Whitespace syntax that supports // and # line comments, and /* */ multiline-comments, but *without* nesting of /* */ comments. This is the case in the Jsonnet programming language
-
object
MultiLineWhitespace
Whitespace syntax that consumes both single-line " " and "\t" and multiline "\r" and "\n" whitespace characters.
-
object
NoWhitespace
No-op whitespace syntax that doesn't consume anything
- object Parsed
- object ParserInput
- object ParserInputSource extends ParserInputSourceLowPri
- object ParsingRun
-
object
ScalaWhitespace
Whitespace syntax that supports // line-comments and /* */ multiline-comments, *including nesting* of /* */ comments, as is the case in the Scala programming language
-
object
ScriptWhitespace
Whitespace syntax that supports # line-comments, as in the case in programming languages such as Bash, Ruby, or Python
- object SharedPackageDefs
-
object
SingleLineWhitespace
Whitespace syntax that consumes only single-line " " and "\t" whitespace characters.