DefaultErrorBuilder

parsley.errors.DefaultErrorBuilder
See theDefaultErrorBuilder companion object
abstract class DefaultErrorBuilder extends ErrorBuilder[String]

This class us used to build Parsley's default error messages.

While it compiles with the ErrorBuilder typeclass, it should not be considered a stable contract: the formatting can be changed at any time and without notice. The API, however, will remain stable.

Attributes

Since

3.0.0

Note

this class is abstract as it does not implement unexpectedToken: when creating an instance mix-in an appropriate token extractor from parsley.errors.tokenextractors.

Companion
object
Source
DefaultErrorBuilder.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Grouped members

item

def unexpectedToken(cs: Iterable[Char], amountOfInputParserWanted: Int, lexicalError: Boolean): Token

Extracts an unexpected token from the remaining input.

Extracts an unexpected token from the remaining input.

When a parser fails, by default an error reports an unexpected token of a specific width. This works well for some parsers, but often it is nice to have the illusion of a dedicated lexing pass: instead of reporting the next few characters as unexpected, an unexpected token can be reported instead. This can take many forms, for instance trimming the token to the next whitespace, only taking one character, or even trying to lex a token out of the stream.

This method can be easily implemented by mixing in an appropriate token extractor from parsley.errors.tokenextractors into this builder.

Value parameters

amountOfInputParserWanted

the input the parser tried to read when it failed (this is not guaranteed to be smaller than the length of cs, but is guaranteed to be greater than 0)

cs

the remaining input at point of failure (this is guaranteed to be non-empty)

lexicalError

was this error generated as part of "lexing", or in a wider parser (see markAsToken)

Attributes

Returns

a token extracted from cs that will be used as part of the unexpected message.

Since

4.0.0

Inherited from:
ErrorBuilder
Source
ErrorBuilder.scala

Type members

Types

Represents the end of the input.

Represents the end of the input.

Attributes

Source
DefaultErrorBuilder.scala

The representation type of the main body within the error message.

The representation type of the main body within the error message.

Attributes

Source
DefaultErrorBuilder.scala

The representation of all the different possible tokens that could have prevented an error.

The representation of all the different possible tokens that could have prevented an error.

Attributes

Source
DefaultErrorBuilder.scala

The representation of the information regarding the solving tokens.

The representation of the information regarding the solving tokens.

Attributes

Source
DefaultErrorBuilder.scala
type Item = String

The base type of Raw, Named and EndOfInput that represents the individual items within the error.

The base type of Raw, Named and EndOfInput that represents the individual items within the error.

Attributes

Source
DefaultErrorBuilder.scala
type LineInfo = Seq[String]

The representation of the line of input where the error occurred.

The representation of the line of input where the error occurred.

Attributes

Source
DefaultErrorBuilder.scala
type Message = String

The representation of a reason or a message generated by the parser.

The representation of a reason or a message generated by the parser.

Attributes

Source
DefaultErrorBuilder.scala
type Messages = Seq[Message]

The representation of the combined reasons or failure messages from the parser.

The representation of the combined reasons or failure messages from the parser.

Attributes

Source
DefaultErrorBuilder.scala
type Named = String

This represents "named" tokens, which have been provided with a label.

This represents "named" tokens, which have been provided with a label.

Attributes

Source
DefaultErrorBuilder.scala
type Position = String

The representation type of position information within the generated message.

The representation type of position information within the generated message.

Attributes

Source
DefaultErrorBuilder.scala
type Raw = String

This represents "raw" tokens, where are those without labels: they come direct from the input, or the characters that the parser is trying to read.

This represents "raw" tokens, where are those without labels: they come direct from the input, or the characters that the parser is trying to read.

Attributes

Source
DefaultErrorBuilder.scala
type Source = Option[String]

The representation of the file information.

The representation of the file information.

Attributes

Source
DefaultErrorBuilder.scala

The representation of the information regarding the problematic token.

The representation of the information regarding the problematic token.

Attributes

Source
DefaultErrorBuilder.scala

Value members

Concrete methods

override def combineExpectedItems(alts: Set[Item]): ExpectedItems

Details how to combine the various expected items into a single representation.

Details how to combine the various expected items into a single representation.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def combineMessages(alts: Seq[Message]): Messages

Details how to combine any reasons or messages generated within a single error.

Details how to combine any reasons or messages generated within a single error. Reasons are used by vanilla messages and messages are used by specialised messages.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def expected(alts: ExpectedItems): ExpectedLine

Describes how to handle the information about the tokens that could have avoided the error.

Describes how to handle the information about the tokens that could have avoided the error.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def format(pos: Position, source: Source, lines: ErrorInfoLines): String

This is the top level function, which finally compiles all the formatted sub-parts into a finished value of type Err.

This is the top level function, which finally compiles all the formatted sub-parts into a finished value of type Err.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def lineInfo(line: String, linesBefore: Seq[String], linesAfter: Seq[String], errorPointsAt: Int, errorWidth: Int): LineInfo

Describes how to format the information about the line that the error occured on.

Describes how to format the information about the line that the error occured on.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def message(msg: String): Message

Describes how to represent the messages produced by the fail combinator (or any that are implemented using it).

Describes how to represent the messages produced by the fail combinator (or any that are implemented using it).

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def named(item: String): Named

Formats a named item generated by a label.

Formats a named item generated by a label.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def pos(line: Int, col: Int): Position

Formats a position into the representation type given by Position.

Formats a position into the representation type given by Position.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def raw(item: String): Raw

Formats a raw item generated by either the input string or a input reading combinator without a label.

Formats a raw item generated by either the input string or a input reading combinator without a label.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def reason(reason: String): Message

Describes how to represent the reasons behind a parser fail.

Describes how to represent the reasons behind a parser fail. These reasons originate from the explain combinator.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def source(sourceName: Option[String]): Source

Formats the name of the file if it exists into the type give by Source

Formats the name of the file if it exists into the type give by Source

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def specialisedError(msgs: Messages, lines: LineInfo): ErrorInfoLines

Specialised errors are triggered by fail and any combinators that are implemented in terms of fail.

Specialised errors are triggered by fail and any combinators that are implemented in terms of fail. These errors take precedence over the vanilla errors, and contain less, more specialised, information

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def unexpected(item: Option[Item]): UnexpectedLine

Describes how to handle the (potentially missing) information about what token(s) caused the error.

Describes how to handle the (potentially missing) information about what token(s) caused the error.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala
override def vanillaError(unexpected: UnexpectedLine, expected: ExpectedLine, reasons: Messages, lines: LineInfo): ErrorInfoLines

Vanilla errors are those produced such that they have information about both expected and unexpected tokens.

Vanilla errors are those produced such that they have information about both expected and unexpected tokens. These are usually the default, and are not produced by fail (or any derivative) combinators.

Attributes

Definition Classes
Source
DefaultErrorBuilder.scala

Concrete fields

override val endOfInput: EndOfInput

Value that represents the end of the input in the error message.

Value that represents the end of the input in the error message.

Attributes

Source
DefaultErrorBuilder.scala
override val numLinesAfter: Int

The number of lines of input to request after an error occured.

The number of lines of input to request after an error occured.

Attributes

Source
DefaultErrorBuilder.scala
override val numLinesBefore: Int

The number of lines of input to request before an error occured.

The number of lines of input to request before an error occured.

Attributes

Source
DefaultErrorBuilder.scala