ErrorMethods

final class ErrorMethods[P, +A](p: => P)(con: P => Parsley[A])

This class exposes helpful combinators that are specialised for generating more helpful errors messages. For a description of why the library is designed in this way, see: the Parsley wiki

This class exposes helpful combinators that are specialised for generating more helpful errors messages. For a description of why the library is designed in this way, see: the Parsley wiki

Value Params
con

A conversion (if required) to turn p into a parser

p

The parser which serves as the method receiver

Version

3.0.0

class Object
trait Matchable
class Any

Value members

Concrete methods

def !(msggen: A => String): Parsley[Nothing]

Same as fail, except allows for a message generated from the result of the failed parser. In essence, this is equivalent to p >>= (x => fail(msggen(x)) but requires no expensive computations from the use of >>=.

Same as fail, except allows for a message generated from the result of the failed parser. In essence, this is equivalent to p >>= (x => fail(msggen(x)) but requires no expensive computations from the use of >>=.

Value Params
msggen

The generator function for error message, creating a message based on the result of invokee

Returns

A parser that fails if it succeeds, with the given generator used to produce the error message

def ?(msg: String): Parsley[A]

Alias for label

Alias for label

Since

3.0.0

def collectMsg[B](msg: String)(pf: PartialFunction[A, B]): Parsley[B]

Attempts to first filter the parser to ensure that pf is defined over it. If it is, then the function pf is mapped over its result. Roughly the same as a guard then a map.

Attempts to first filter the parser to ensure that pf is defined over it. If it is, then the function pf is mapped over its result. Roughly the same as a guard then a map.

Value Params
msg

The message used for the error if the input failed the check

pf

The partial function

Returns

The result of applying pf to this parsers value (if possible), or fails

Since

3.0.0

def collectMsg[B](msggen: A => String)(pf: PartialFunction[A, B]): Parsley[B]

Attempts to first filter the parser to ensure that pf is defined over it. If it is, then the function pf is mapped over its result. Roughly the same as a guard then a map.

Attempts to first filter the parser to ensure that pf is defined over it. If it is, then the function pf is mapped over its result. Roughly the same as a guard then a map.

Value Params
msggen

Generator function for error message, generating a message based on the result of the parser

pf

The partial function

Returns

The result of applying pf to this parsers value (if possible), or fails

Since

3.0.0

def explain(reason: String): Parsley[A]

Similar to label, except instead of providing an expected message replacing the original tag, this combinator adds a ''reason'' that the error occurred. This is in complement to the label. The reason is only added when the parser fails, and will disappear if any further progress in the parser is made (unlike labels, which may reappear as "hints").

Similar to label, except instead of providing an expected message replacing the original tag, this combinator adds a ''reason'' that the error occurred. This is in complement to the label. The reason is only added when the parser fails, and will disappear if any further progress in the parser is made (unlike labels, which may reappear as "hints").

Value Params
reason

The reason why a parser failed

Since

3.0.0

def filterOut(pred: PartialFunction[A, String]): Parsley[A]

Filter the value of a parser; if the value returned by the parser is defined for the given partial function, then the filterOut fails, using the result of the function as the ''reason'' (see explain), otherwise the parser succeeds

Filter the value of a parser; if the value returned by the parser is defined for the given partial function, then the filterOut fails, using the result of the function as the ''reason'' (see explain), otherwise the parser succeeds

Value Params
pred

The predicate that is tested against the parser result

Returns

The result of the invokee if the value failed the predicate

Since

3.0.0

def guardAgainst(pred: PartialFunction[A, String]): Parsley[A]

Similar to filterOut, except the error message generated yields a ''true failure''. This means that it will uses the same mechanism as fail, as opposed to the reason provided by filterOut

Similar to filterOut, except the error message generated yields a ''true failure''. This means that it will uses the same mechanism as fail, as opposed to the reason provided by filterOut

Value Params
pred

The predicate that is tested against the parser result and produces error messages

Returns

The result of the invokee if it fails the predicate

Since

2.8.0

def hide: Parsley[A]

Hides the "expected" error message for a parser.

Hides the "expected" error message for a parser.

Since

3.0.0

def label(msg: String): Parsley[A]

Sets the expected message for a parser. If the parser fails then expected msg will added to the error. The label is only applied if the error message does not observe any consumption of input.

Sets the expected message for a parser. If the parser fails then expected msg will added to the error. The label is only applied if the error message does not observe any consumption of input.

Since

3.0.0

def unexpected(msggen: A => String): Parsley[Nothing]

Same as unexpected, except allows for a message generated from the result of the failed parser. In essence, this is equivalent to p >>= (x => unexpected(x)) but requires no expensive computations from the use of >>=

Same as unexpected, except allows for a message generated from the result of the failed parser. In essence, this is equivalent to p >>= (x => unexpected(x)) but requires no expensive computations from the use of >>=

Value Params
msggen

The generator function for error message, creating a message based on the result of invokee

Returns

A parser that fails if it succeeds, with the given generator used to produce an unexpected message