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.
- Source
- DefaultErrorBuilder.scala
- 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 fromparsley.errors.tokenextractors.
- Grouped
- Alphabetic
- By Inheritance
- DefaultErrorBuilder
- ErrorBuilder
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new DefaultErrorBuilder()
Type Members
-
type
EndOfInput = String
Represents the end of the input.
Represents the end of the input.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
ErrorInfoLines = Seq[String]
The representation type of the main body within the error message.
The representation type of the main body within the error message.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
ExpectedItems = Option[String]
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
ExpectedLine = Option[String]
The representation of the information regarding the solving tokens.
The representation of the information regarding the solving tokens.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
Item = String
The base type of
Raw,NamedandEndOfInputthat represents the individual items within the error.The base type of
Raw,NamedandEndOfInputthat represents the individual items within the error.- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
Position = String
The representation type of position information within the generated message.
The representation type of position information within the generated message.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
Source = Option[String]
The representation of the file information.
The representation of the file information.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
type
UnexpectedLine = Option[String]
The representation of the information regarding the problematic token.
The representation of the information regarding the problematic token.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
Abstract Value Members
-
abstract
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.tokenextractorsinto this builder.- cs
the remaining input at point of failure (this is guaranteed to be non-empty)
- amountOfInputParserWanted
the input the parser tried to read when it failed (this is not guaranteed to be smaller than the length of
cs)- lexicalError
was this error generated as part of "lexing", or in a wider parser (see
markAsToken)- returns
a token extracted from
csthat will be used as part of the unexpected message.
- Definition Classes
- ErrorBuilder
- Since
4.0.0
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
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.
- alts
The possible items that fix the error
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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
vanillamessages and messages are used byspecialisedmessages.- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
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.
- alts
the tokens that could have prevented the error (see the
combineExpectedItemsmethod).
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
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.- pos
this is the representation of the position of the error in the input (see the
posmethod).- source
this is the representation of the filename, if it exists (see the
sourcemethod).- lines
this is the main body of the error message (see
vanillaErrororspecialisedErrormethods).- returns
the final assembled error message.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
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.
- line
the full line of input that produced this error message.
- linesBefore
the lines of input just before the one that produced this message (up to
numLinesBefore).- linesAfter
the lines of input just after the one that produced this message (up to
numLinesAfter).- errorPointsAt
the offset into the line that the error points at.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
def
message(msg: String): Message
Describes how to represent the messages produced by the
failcombinator (or any that are implemented using it).Describes how to represent the messages produced by the
failcombinator (or any that are implemented using it).- msg
the message produced by the parser.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
def
named(item: String): Named
Formats a named item generated by a label.
Formats a named item generated by a label.
- item
the name given to the label.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.- line
the line the error occurred at.
- col
the column the error occurred at.
- returns
a representation of the position.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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.
- item
the raw, unprocessed input.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
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
explaincombinator.- reason
the reason produced by the parser.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
def
source(sourceName: Option[String]): Source
Formats the name of the file if it exists into the type give by
SourceFormats the name of the file if it exists into the type give by
Source- sourceName
the source name of the file, if any.
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
def
specialisedError(msgs: Messages, lines: LineInfo): ErrorInfoLines
Specialised errors are triggered by
failand any combinators that are implemented in terms offail.Specialised errors are triggered by
failand any combinators that are implemented in terms offail. These errors take precedence over the vanilla errors, and contain less, more specialised, information- msgs
information detailing the error (see the
combineMessagesmethod).
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
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.
- item
The
Itemthat caused this error
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
def
vanillaError(unexpected: UnexpectedLine, expected: ExpectedLine, reasons: Messages, lines: LineInfo): ErrorInfoLines
Vanilla errors are those produced such that they have information about both
expectedandunexpectedtokens.Vanilla errors are those produced such that they have information about both
expectedandunexpectedtokens. These are usually the default, and are not produced byfail(or any derivative) combinators.- unexpected
information about which token(s) caused the error (see the
unexpectedmethod).- expected
information about which token(s) would have avoided the error (see the
expectedmethod).- reasons
additional information about why the error occured (see the
combineMessagesmethod).
- Definition Classes
- DefaultErrorBuilder → ErrorBuilder
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
Top-Level Formatting
These methods help assembly the final products of the error messages. The format method will return the desired Err types,
whereas specialisedError and vanillaError both assemble an ErrorInfoLines that the format method can consume.
Error Preamble
These methods control the formatting of the preamble of an error message, which is the position and source info.
These are then consumed by format itself.
Contextual Input Lines
These methods control how many lines of input surrounding the error are requested, and direct how these should be put
together to form a LineInfo.
Shared Components
These methods control any components or structure shared by both types of messages. In particular, the representation of reasons and messages is shared, as well as how they are combined together to form a unified block of content lines.
Specialised-Specific Components
These methods control the Specialised-specific components, namely the formatting of a bespoke error message.
Vanilla-Specific Components
These methods control the Vanilla-specific error components, namely how expected error items
should be combined, how to format the unexpected line, and how to format reasons generated from
explain.
Error Items
These methods control how error items within Vanilla errors are formatted. These are either
the end of input, a named label generated by the label combinator,
or a raw piece of input intrinsically associated with a combinator.