SpecialisedGen

parsley.errors.SpecialisedGen
class SpecialisedGen[-A] extends ErrorGen[A]

An error generate for Specialised errors, which can tune the freeform messages of the error.

Attributes

Since

4.4.0

Source
ErrorGen.scala
Graph
Supertypes
class ErrorGen[A]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def messages(x: A): Seq[String]

What should the messages of the error message be based on the result the offending parser produced?

What should the messages of the error message be based on the result the offending parser produced?

Attributes

Since

4.4.0

Source
ErrorGen.scala

Inherited methods

def adjustWidth(x: A, width: Int): Int

This method can be overridden to control how wide an error is based on the value and width that produces it.

This method can be overridden to control how wide an error is based on the value and width that produces it.

The width provides to this error generator likely comes directly from the span of the parser used to produce the required result. However, this may not be entirely accurate for how the user might want the error to be sized (perhaps there was whitespace, or the parser consumed more input than was necessary to pin-point the problem). In these cases, this method allows for custom logic to derive the actual width of the error message. By default, just returns the given width.

Attributes

Since

4.4.0

Inherited from:
ErrorGen
Source
ErrorGen.scala
final def apply(p: Parsley[(A, Int)]): Parsley[Nothing]

This combinator takes a given parser and raises an error based on its returned results.

This combinator takes a given parser and raises an error based on its returned results.

The given parser produces a value and a width, which are used to synthesise and raise an error message derived from the value with the given width. This is a safe way of using parser, since it ensures that the result of the given parser p is not optimised out. errGen(p) is similar to withWidth(p).flatMap { case (x, w) => failCombinator(...) }, in that it generates errors in a context-sensitive way. However, this is much more efficient than using the expensive flatMap, so it is provided as a primitive operation.

Attributes

Since

4.4.0

Inherited from:
ErrorGen
Source
ErrorGen.scala
final def parser: Parsley[((A, Int)) => Nothing]

This parser can be applied (postfix) to a parser returning a value and a width to generate an error message tailored to them.

This parser can be applied (postfix) to a parser returning a value and a width to generate an error message tailored to them.

This is not a generally safe operation to be performing, and should only be used within a combinator that is guaranteed to use its results. The optimiser is not aware that the results of the parser this will be applied to will actually be needed, and so may optimise them out. Using this parser inside an arm of select or branch, say, would be safe, because these combinators force the result of their condition to be generated, but p <**> this.parser is not generally safe without a use of impure to guard it. This is what apply accomplishes more safely.

Attributes

Since

4.4.0

Inherited from:
ErrorGen
Source
ErrorGen.scala