halotukozak.alpaca.internal.lexer

Members list

Type members

Experimental classlikes

object Column

Attributes

Experimental
true
Source
Column.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Column.type
object ErrorHandling

Provides mechanisms for defining error-handling strategies when processing input. This object contains a sealed enumeration Strategy that specifies the different ways errors can be addressed during tokenization or parsing workflows.

Provides mechanisms for defining error-handling strategies when processing input. This object contains a sealed enumeration Strategy that specifies the different ways errors can be addressed during tokenization or parsing workflows.

Attributes

Companion
trait
Experimental
true
Source
ErrorHandling.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait ErrorHandling[-Ctx <: LexerCtx] extends Ctx => Strategy

Trait representing error handling strategies for a lexer context.

Trait representing error handling strategies for a lexer context.

This trait allows the specification of error handling strategies for various lexer contexts by transforming a given lexer context to an instance of ErrorHandling.Strategy. The strategies determine how the lexer should proceed when it encounters an error, such as invalid tokens or characters during parsing.

Error handling is essential for customizing lexer behavior in response to specific scenarios, including ignoring or stopping on errors, or throwing specific exceptions.

Users must define an implicit instance of this trait to provide the error handling behavior for a custom lexer context.

Type parameters

Ctx

The lexer context that this error handling strategy applies to. Must be a subtype of LexerCtx.

Attributes

Companion
object
Experimental
true
Source
ErrorHandling.scala
Supertypes
trait Ctx => Strategy
class Object
trait Matchable
class Any
final class LazyReader(reader: Reader, var size: Long) extends CharSequence, Closeable

A lazy character sequence that reads from a Reader on demand.

A lazy character sequence that reads from a Reader on demand.

This class is useful for tokenizing large files without loading them entirely into memory. It buffers characters as they are accessed and can efficiently skip over processed characters.

Value parameters

reader

the underlying Reader to read from

size

the total size of the input (if known)

Attributes

Companion
object
Experimental
true
Source
LazyReader.scala
Supertypes
trait Closeable
trait AutoCloseable
trait CharSequence
class Object
trait Matchable
class Any
Show all
object LazyReader

Factory methods for creating LazyReader instances.

Factory methods for creating LazyReader instances.

Attributes

Companion
class
Experimental
true
Source
LazyReader.scala
Supertypes
class Object
trait Matchable
class Any
Self type
LazyReader.type
object Line

Attributes

Experimental
true
Source
Line.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Line.type
sealed trait Token[+Name <: ValidName, +Ctx <: LexerCtx, +Value]

Base trait for all token types.

Base trait for all token types.

A token represents a lexical unit matched by the lexer. It contains information about the token's name, pattern, and how to manipulate the lexer context when matched.

Type parameters

Ctx

the global context type

Name

the token name type

Value

the value type extracted from the matched text

Attributes

Experimental
true
Source
Token.scala
Supertypes
class Object
trait Matchable
class Any
abstract transparent class Tokenization[Ctx <: LexerCtx](onTokenMatch: (Token[_, Ctx, _], String, Ctx) => Ctx)(using errorHandling: ErrorHandling[Ctx], empty: Empty[Ctx]) extends Selectable

The result of compiling a lexer definition.

The result of compiling a lexer definition.

This abstract class represents a compiled lexer that can tokenize input. It is generated by the lexer macro and provides methods to access tokens and perform tokenization.

Type parameters

Ctx

the global context type

Attributes

Experimental
true
Source
Tokenization.scala
Supertypes
trait Selectable
class Object
trait Matchable
class Any
trait Tracking[F]

A per-token update for a single lexer-context field (a "fragment" such as Line or Column).

A per-token update for a single lexer-context field (a "fragment" such as Line or Column).

Tracking.materialize applies one Tracking instance to each case field of the context whose type provides a given, threading the result through a functional copy; fields whose type has no Tracking given are left untouched by the hook (they only change in rule bodies).

This is how tracking composes without inheritance: define a distinct field type and a given Tracking[YourType] in its companion, then use it as a context field.

Type parameters

F

the fragment field type

Attributes

Companion
object
Experimental
true
Source
Tracking.scala
Supertypes
class Object
trait Matchable
class Any
object Tracking

Attributes

Companion
trait
Experimental
true
Source
Tracking.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Tracking.type

Types

opaque type Column

A context fragment that tracks the current 1-based column position within the line, resetting to 1 on a newline.

A context fragment that tracks the current 1-based column position within the line, resetting to 1 on a newline.

Use it as a field of a lexer context:

case class MyCtx(position: Column = Column.Start) extends LexerCtx

Tracking.materialize finds the given Tracking[Column] below and applies it to that field after every match, threading a functional copy -- so position stays an immutable val. Column &lt;: Int, so ctx.position reads as a plain Int everywhere; assigning it inside a rule body (ctx.position = Column(...)) is rewritten to a copy too.

(Named Column, not Position, to avoid shadowing the unrelated source Position type used throughout this library's own error reporting.)

Attributes

Source
Column.scala
opaque type Line

A context fragment that tracks the current 1-based line number.

A context fragment that tracks the current 1-based line number.

Use it as a field of a lexer context:

case class MyCtx(line: Line = Line.Start) extends LexerCtx

Tracking.materialize finds the given Tracking[Line] below and applies it to that field after every match, threading a functional copy -- so line stays an immutable val. Line &lt;: Int, so ctx.line reads as a plain Int everywhere; assigning it inside a rule body (ctx.line = Line(...)) is rewritten to a copy too.

Attributes

Source
Line.scala

Value members

Experimental methods

def lexerImpl[Ctx <: LexerCtx, lexemeFields <: AnyNamedTuple](rules: Expr[Ctx ?=> LexerDefinition[Ctx]], onTokenMatch: Expr[(Token[_, Ctx, _], String, Ctx) => Ctx], errorHandling: Expr[ErrorHandling[Ctx]], empty: Expr[Empty[Ctx]])(using evidence$1: Type[Ctx], evidence$2: Type[lexemeFields], quotes: Quotes): Expr[Tokenization[Ctx] { type LexemeFields = lexemeFields; }]

Attributes

Experimental
true
Source
Lexer.scala