laika.parse

package laika.parse

Members list

Type members

Classlikes

class BlockSource(inputRef: InputString, val lines: Type[LineSource], val offset: Int, val nestLevel: Int) 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.

Attributes

Companion
object
Source
SourceCursor.scala
Supertypes
trait SourceCursor
class Object
trait Matchable
class Any
object BlockSource

Companion for creating BlockSource instances.

Companion for creating BlockSource instances.

Attributes

Companion
class
Source
SourceCursor.scala
Supertypes
class Object
trait Matchable
class Any
Self type
case class Failure(msgProvider: Message, next: SourceCursor, maxOffset: Int) extends Parsed[Nothing]

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).

Value parameters

maxOffset

The offset position the parser could successfully read to before failing

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

Attributes

Companion
object
Source
Parsed.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Parsed[Nothing]
class Object
trait Matchable
class Any
Show all
object Failure

Attributes

Companion
class
Source
Parsed.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Failure.type
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 a BlockSource and less frequently on its own.

Attributes

Companion
object
Source
SourceCursor.scala
Supertypes
trait SourceCursor
class Object
trait Matchable
class Any
object LineSource

Companion for creating LineSource instances.

Companion for creating LineSource instances.

Attributes

Companion
class
Source
SourceCursor.scala
Supertypes
class Object
trait Matchable
class Any
Self type
LineSource.type
trait Message

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.

Attributes

Companion
object
Source
Parsed.scala
Supertypes
class Object
trait Matchable
class Any
object Message

Message companion providing several pre-built messages and factory methods.

Message companion providing several pre-built messages and factory methods.

Attributes

Companion
trait
Source
Parsed.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Message.type
sealed abstract class Parsed[+T]

Represents the result of a Parser, a value of type T in case of success, a message in case of failure as well as the SourceCursor for the remaining input.

Represents the result of a Parser, a value of type T in case of success, a message in case of failure as well as the SourceCursor for the remaining input.

Attributes

Source
Parsed.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Failure
class Success[T]
abstract class Parser[+T]

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.

Attributes

Companion
object
Source
Parser.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Repeat[T]
trait InlineParser[Elem, To]
class Characters[T]
trait PrefixedParser[T]
class IdParser
class PrefixCharacters[T]
Show all
object Parser

Companion factory for creating new parser instances.

Companion factory for creating new parser instances.

Attributes

Companion
class
Source
Parser.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Parser.type
class Position(s: InputString, offset: Int)

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.

Value parameters

offset

the offset into the source string

s

the source for this position

Attributes

Source
SourceCursor.scala
Supertypes
class Object
trait Matchable
class Any
trait SourceCursor

Represents the state and context of a parsing operation, containing the input string as well as positional information.

Represents the state and context of a parsing operation, containing the input string as well as positional information.

Attributes

Companion
object
Source
SourceCursor.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class BlockSource
class LineSource
object Generated
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 or LineSource must be used to preserve position tracking in relation to the root input.

Attributes

Companion
trait
Source
SourceCursor.scala
Supertypes
class Object
trait Matchable
class Any
Self type

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.

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.

Attributes

Source
SourceCursor.scala
Supertypes
trait SourceCursor
class Object
trait Matchable
class Any
Known subtypes
class BlockSource
class LineSource
object Generated
case class Success[+T](result: T, next: SourceCursor) extends Parsed[T]

The success case of Parsed containing the result and the remaining input.

The success case of Parsed containing the result and the remaining input.

Attributes

Source
Parsed.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Parsed[T]
class Object
trait Matchable
class Any
Show all

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 and not, the text parsers like literal and anyOf(Char*), as well as the more specialized parsers for text markup like spans and blocks.

Alternatively these groups can be brought into scope individually.

Attributes

Source
builders.scala
Supertypes
trait BlockParsers
trait TextParsers
trait Parsers
class Object
trait Matchable
class Any
Show all
Self type
builders.type
object syntax

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 a Parser[Seq[A], Seq[A]] and mapN for any parser Parser[A ~ B ~ C] (up to 5 concatenated elements).

Attributes

Source
syntax.scala
Supertypes
class Object
trait Matchable
class Any
Self type
syntax.type