Result

halotukozak.alpaca.Result
enum Result[+Ctx, +Value, +Err]

The outcome of tokenizing or parsing: the value, or the errors met on the way.

Both cases carry the context (lexer or parser) as it was when the run ended. A Result.Failure may still hold a value in recovered, when an error-handling strategy skipped past the errors and the run went on to the end; otherwise recovered is None.

MyParser.parse(lexemes) match
 case Result.Success(ctx, value) => println(value)
 case Result.Failure(ctx, recovered, errors) => errors.foreach(e => println(e.message))

For Alpaca's own error types, getOrThrow returns the value or throws the errors as an exception (LexerException for LexerErrors, ParserException for ParserErrors).

Type parameters

Ctx

the lexer or parser context type

Err

the error type: LexerError for tokenize, ParserError for parse

Value

the value: the lexemes for tokenize, the root rule's result for parse

Attributes

Source
Result.scala
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

final case class Failure[+Ctx, +Value, +Err](ctx: Ctx, recovered: Option[Value], errors: ::[Err])

Some input was not accepted; errors says what and where, in input order. recovered is the value produced anyway when an error-handling strategy skipped past the errors, None when the run stopped at the first one. errors is never empty, and as a :: it is a plain List.

Some input was not accepted; errors says what and where, in input order. recovered is the value produced anyway when an error-handling strategy skipped past the errors, None when the run stopped at the first one. errors is never empty, and as a :: it is a plain List.

Attributes

Source
Result.scala
final case class Success[+Ctx, +Value, +Err](ctx: Ctx, value: Value)

The whole input was accepted and produced value.

The whole input was accepted and produced value.

Attributes

Source
Result.scala