ErrorHandling

halotukozak.alpaca.ErrorHandling$package.ErrorHandling
object ErrorHandling

Attributes

Source
ErrorHandling.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

enum Strategy

What to do with input that is not accepted: one character for the lexer, one lexeme for the parser.

What to do with input that is not accepted: one character for the lexer, one lexeme for the parser.

Attributes

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

Value members

Concrete methods

transparent inline def forLexer[Ctx <: LexerCtx](inline handler: Of[Ctx] ?=> Of[Ctx] => Strategy): () => Ctx

A lexer error handler. In handler, the error carries the context's fields with their types (error.line). It can also change the context. In handler, ctx is the lexer context as in a rule body: assigning its fields (ctx.count += 1) changes the context the lexer goes on with, so they can stay vals.

A lexer error handler. In handler, the error carries the context's fields with their types (error.line). It can also change the context. In handler, ctx is the lexer context as in a rule body: assigning its fields (ctx.count += 1) changes the context the lexer goes on with, so they can stay vals.

case class MyCtx(line: Line = Line.Start, skipped: Int = 0) extends LexerCtx

given ErrorHandling[MyCtx] = ErrorHandling.forLexer: error =>
 ctx.skipped += 1
 ErrorHandling.Strategy.SkipOne

The error reported for the input keeps the context from before the handler ran.

Type parameters

Ctx

the lexer context

Value parameters

handler

the strategy for an error, written directly as a lambda

Attributes

Source
ErrorHandling.scala
inline def forParser[Ctx <: ParserCtx](inline handler: Of[Ctx] ?=> ParserError => Strategy): () => Ctx

A parser error handler, which can change the context. In handler, ctx is the parser context as in an action: assigning its fields (ctx.skipsLeft -= 1) changes the context the parser goes on with, so they can stay vals.

A parser error handler, which can change the context. In handler, ctx is the parser context as in an action: assigning its fields (ctx.skipsLeft -= 1) changes the context the parser goes on with, so they can stay vals.

case class MyCtx(skipsLeft: Int = 3) extends ParserCtx

given ErrorHandling[MyCtx] = ErrorHandling.forParser: error =>
 if ctx.skipsLeft == 0 then ErrorHandling.Strategy.Stop
 else
   ctx.skipsLeft -= 1
   ErrorHandling.Strategy.SkipOne

Type parameters

Ctx

the parser context

Value parameters

handler

the strategy for an error, written directly as a lambda

Attributes

Source
ErrorHandling.scala