package parse
- Alphabetic
- Public
- All
Type Members
-
class
BlockSource extends SourceFragment
A block source represents the source for a block level element where each individual line might have a different x-offset to the root source.
A block source represents the source for a block level element where each individual line might have a different x-offset to the root source.
This type of source is essential to preserve position tracking in recursive block parsing. For block level markup the first passes have to identify the type of block and remove their markup decoration. The remaining inline markup is then passed to inline parsers, but the input to those parsers is no longer a consecutive substring of the root input, making it hard to provide exact positions in error messages.
This type of source cursor solves this issue by providing a view to parsers that looks like a consecutive string of inline markup without the stripped decoration, while maintaining the x- and y-offsets of each line in relation to the root source.
Such a source will be used in multi-pass parsers, where the root parser might strip some markup decoration from each line and then pass the result down to the next recursion. In such a case each line might have a different x-offset from the root input. The use of this instance ensures that the correct position can still be tracked.
-
case class
Failure(msgProvider: Message, next: SourceCursor, maxOffset: Int) extends Parsed[Nothing] with Product with Serializable
The failure case of
Parsed
containing an error message and the remaining input.The failure case of
Parsed
containing an error message and the remaining input.Implementation note: The message property is of type
Message
, to allow for lazy message creation. The former SDK parser combinators which this API is partially inspired by contained a lot of unnecessary string concatenations for messages which were then never read. This implementation avoids this extra cost and the result is measurable (about 15% performance gain for a typical Markdown document for example).- msgProvider
A provider that produces an error message for this failure based on its SourceCursor
- next
The unconsumed input at the point where the failing parser started
- maxOffset
The offset position the parser could successfully read to before failing
-
class
LineSource extends SourceFragment
A line source represents all or part of a single line from the root input source.
A line source represents all or part of a single line from the root input source.
Such a source will be used in multi-pass parsers, particularly block-level parsers, where the root parser might strip some markup decoration from each line and then pass the result down to the next recursion. In such a case each line might have a different x-offset from the root input. The use of this instance ensures that the correct position can still be tracked.
A
LineSource
is usually used as part of aBlockSource
and less frequently on its own. -
trait
Message extends AnyRef
Represents a lazy failure message.
Represents a lazy failure message. Implementations can use the specified
SourceCursor
to construct the actual message, e.g. for adding parts of the input to the message. -
sealed abstract
class
Parsed[+T] extends AnyRef
Represents the result of a
Parser
, a value of typeT
in case of success, a message in case of failure as well as theSourceCursor
for the remaining input. -
abstract
class
Parser[+T] extends AnyRef
The abstract base for all parser implementations.
The abstract base for all parser implementations.
Contains the main
parse
function as well as various combinator function to create a new parser based on this one. -
class
Position extends AnyRef
Represents an offset into a source string.
Represents an offset into a source string. Its main purpose is error reporting, e.g. printing a visual representation of the line containing the error.
-
class
RootSource extends SourceCursor
A root source represents the full input string of a parsing operation.
A root source represents the full input string of a parsing operation.
In a single-pass parser like those for HOCON or CSS, only
RootCursor
instances will be used for the entire parsing operation.In a multi-pass parser like those for text markup, a
RootCursor
is only used for the first pass, whereas the subsequent passes on parts of the input are performed with the otherSourceCursor
implementations.For this reason this type of cursor is only meant to be used for creating a root cursor for the input holding the whole document (e.g. the entire markup document or the full template).
For creating a cursor for a fragment of the input, either
BlockSource
orLineSource
must be used to preserve position tracking in relation to the root input. -
trait
SourceCursor extends AnyRef
Represents the state and context of a parsing operation, containing the input string as well as positional information.
-
trait
SourceFragment extends SourceCursor
Represents any source cursor other than the root cursor and it is mandated by some APIs that solely deal with recursive parsing where the root input will never be used as the source for the parser.
-
case class
Success[+T](result: T, next: SourceCursor) extends Parsed[T] with Product with Serializable
The success case of
Parsed
containing the result and the remaining input.
Value Members
-
object
BlockSource
Companion for creating BlockSource instances.
- object Failure extends Serializable
-
object
GeneratedSource extends SourceFragment
Represents a generated source, where an AST node has been created programmatically and cannot be traced back to the corresponding input source.
-
object
LineSource
Companion for creating LineSource instances.
-
object
Message
Message companion providing several pre-built messages and factory methods.
-
object
Parser
Companion factory for creating new parser instances.
-
object
SourceCursor
Companion for creating new
SourceCursor
instances.Companion for creating new
SourceCursor
instances. This type of constructor is only meant to be used for creating a root cursor for the input holding the whole document (e.g. the entire markup document or the full template).For creating a cursor for a fragment of the input, either
BlockSource
orLineSource
must be used to preserve position tracking in relation to the root input. -
object
builders extends TextParsers with InlineParsers with BlockParsers
Grouping of all parser builders that allows to construct most common parsers with a single import.
Grouping of all parser builders that allows to construct most common parsers with a single import.
These include the base parsers like
opt
andnot
, the text parsers likeliteral
andanyOf(Char*)
, as well as the more specialized parsers for text markup likespans
andblocks
.Alternatively these groups can be brought into scope individually.
-
object
implicits
Collection of extension methods that helps keeping parser definitions concise.
Collection of extension methods that helps keeping parser definitions concise.
It includes extension methods on string that allows to use string literals in parser definitions like
"{" ~ anyNot('}') ~ "}"
and extensions for parsers for particular target types, e.g.concat
for aParser[Seq[A], Seq[A]]
andmapN
for any parserParser[A ~ B ~ C]
(up to 5 concatenated elements).