CharRecognizer

io.github.edadma.recognizer.CharRecognizer
trait CharRecognizer[W] extends Recognizer[W, Char]

A specialized recognizer trait for character-based input streams.

This trait extends Recognizer to provide convenient patterns and utilities for working with character input, such as string matching, whitespace handling, and common character classifications.

Type parameters

W

the wrapped value type

Attributes

Graph
Supertypes
trait Recognizer[W, Char]
class Object
trait Matchable
class Any

Members list

Type members

Inherited classlikes

protected case class Alternative(p: Pattern, q: Pattern) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected trait Choice

Attributes

Inherited from:
Recognizer
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class ChoicePoint
object Fence
protected case class ChoicePoint(input: I, pattern: Pattern, call: List[Pattern], value: List[Any]) extends Choice

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Choice
class Object
trait Matchable
class Any
Show all
protected case class Clas(c: E => Boolean) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case object Cut extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case object Fail extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case object Fence extends Pattern, Choice

Attributes

Inherited from:
Recognizer
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Choice
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class LookBehind(p: E => Boolean) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class Match(e: Seq[E]) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class NonStrict(p: () => Pattern) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case object Nop extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class Not(p: Pattern) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class NotLookBehind(p: E => Boolean) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
trait Pattern

The core pattern type representing a pattern to match.

The core pattern type representing a pattern to match.

Attributes

Inherited from:
Recognizer
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Alternative
class Clas
object Cut
object Fail
object Fence
class LookBehind
class Match
class NonStrict
object Nop
class Not
object Pointer
class Push
class Sequence
class Test
class Transform
Show all
protected case object Pointer extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class Push(v: Any) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
class Runstate

Represents the execution state during pattern matching.

Represents the execution state during pattern matching.

Value parameters

pat

the initial pattern to match

pointer

the current input position

Attributes

Inherited from:
Recognizer
Supertypes
class Object
trait Matchable
class Any
protected case class Sequence(p: Pattern, q: Pattern) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class Test(p: List[Any] => Boolean) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected case class Transform(arity: Int, f: Seq[Any] => Any) extends Pattern

Attributes

Inherited from:
Recognizer
Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all

Inherited types

type I = Input[W, Char]

Type alias for the input type used by this recognizer

Type alias for the input type used by this recognizer

Attributes

Inherited from:
Recognizer

Value members

Concrete methods

def kw(s: String): Pattern

Creates a pattern that matches a keyword followed by a non-alphanumeric character and whitespace.

Creates a pattern that matches a keyword followed by a non-alphanumeric character and whitespace.

This is useful for matching keywords in programming languages where keywords must be followed by something other than a letter, digit, or underscore.

Value parameters

s

the keyword string to match

Attributes

Returns

a pattern matching the keyword followed by a non-alphanumeric and whitespace

Captures the text matched by a pattern as a string.

Captures the text matched by a pattern as a string.

Value parameters

p

the pattern to match

Attributes

Returns

a pattern that captures the matched input as a string

def sym(s: String): Pattern

Creates a pattern that matches a symbol followed by whitespace.

Creates a pattern that matches a symbol followed by whitespace.

This is useful for matching syntactic elements like operators or punctuation in programming languages.

Value parameters

s

the symbol string to match

Attributes

Returns

a pattern matching the symbol followed by whitespace

Inherited methods

def !!: Pattern

Cut operator - disallows backtracking past this point.

Cut operator - disallows backtracking past this point.

Attributes

Returns

a pattern representing a cut point

Inherited from:
Recognizer
def action[A](f: A => Any): Pattern

Creates a pattern that applies an action to a single value on the stack.

Creates a pattern that applies an action to a single value on the stack.

Value parameters

f

the action function

Attributes

Returns

a pattern that applies the action

Inherited from:
Recognizer
def action2[A, B](f: (A, B) => Any): Pattern

Creates a pattern that applies an action to two values on the stack.

Creates a pattern that applies an action to two values on the stack.

Value parameters

f

the action function

Attributes

Returns

a pattern that applies the action

Inherited from:
Recognizer
def action3[A, B, C](f: (A, B, C) => Any): Pattern

Creates a pattern that applies an action to three values on the stack.

Creates a pattern that applies an action to three values on the stack.

Value parameters

f

the action function

Attributes

Returns

a pattern that applies the action

Inherited from:
Recognizer
def action4[A, B, C, D](f: (A, B, C, D) => Any): Pattern

Creates a pattern that applies an action to four values on the stack.

Creates a pattern that applies an action to four values on the stack.

Value parameters

f

the action function

Attributes

Returns

a pattern that applies the action

Inherited from:
Recognizer
def any: Pattern

Creates a pattern that matches any element.

Creates a pattern that matches any element.

Attributes

Returns

a pattern that matches any element

Inherited from:
Recognizer
def anyOf(es: Char*): Pattern

Creates a pattern that matches any element in a specified set.

Creates a pattern that matches any element in a specified set.

Value parameters

es

the elements to match against

Attributes

Returns

a pattern that matches any element in the set

Inherited from:
Recognizer
def capture(p: Pattern)(action: (I, I) => Any): Pattern

Creates a pattern that captures the region matched by a pattern and applies an action.

Creates a pattern that captures the region matched by a pattern and applies an action.

Value parameters

action

a function that processes the start and end positions

p

the pattern to match

Attributes

Returns

a pattern that captures the matched region

Inherited from:
Recognizer

Creates a pattern that captures the wrapped values matched by a pattern.

Creates a pattern that captures the wrapped values matched by a pattern.

Value parameters

p

the pattern to match

Attributes

Returns

a pattern that captures the wrapped values

Inherited from:
Recognizer
def clas(c: Char => Boolean): Pattern

Creates a pattern that matches any element satisfying a predicate.

Creates a pattern that matches any element satisfying a predicate.

Value parameters

c

the predicate function

Attributes

Returns

a pattern that matches elements satisfying the predicate

Inherited from:
Recognizer

A pattern that always fails.

A pattern that always fails.

Attributes

Returns

a pattern that always fails

Inherited from:
Recognizer
def fence: Pattern

Creates a fence marker for backtracking control.

Creates a fence marker for backtracking control.

Attributes

Returns

a pattern representing a fence

Inherited from:
Recognizer
def lookBehind(p: Char => Boolean): Pattern

Positive look-behind

Positive look-behind

Value parameters

p

the predicate

Attributes

Returns

a pattern that matches if there is a previous element that matches p

Inherited from:
Recognizer
def nonStrict(p: => Pattern): Pattern

Creates a pattern with lazy evaluation, useful for recursive pattern definitions.

Creates a pattern with lazy evaluation, useful for recursive pattern definitions.

Value parameters

p

a function that returns a pattern when called

Attributes

Returns

a non-strict pattern that evaluates p when needed

Inherited from:
Recognizer
def noneOf(es: Char*): Pattern

Creates a pattern that matches any element not in a specified set.

Creates a pattern that matches any element not in a specified set.

Value parameters

es

the elements to exclude

Attributes

Returns

a pattern that matches any element not in the set

Inherited from:
Recognizer
def nop: Pattern

A pattern that always succeeds without consuming input.

A pattern that always succeeds without consuming input.

Attributes

Returns

a pattern that always succeeds

Inherited from:
Recognizer
def not(p: Pattern): Pattern

Creates a negative lookahead pattern that succeeds only if the given pattern fails.

Creates a negative lookahead pattern that succeeds only if the given pattern fails.

Value parameters

p

the pattern to negate

Attributes

Returns

a pattern that succeeds only if p fails

Inherited from:
Recognizer
def notLookBehind(p: Char => Boolean): Pattern

Negative look-behind

Negative look-behind

Value parameters

p

the predicate

Attributes

Returns

a pattern that matches if there is no previous element that matches p

Inherited from:
Recognizer
def opt(p: Pattern): Pattern

Creates an optional pattern that succeeds even if the given pattern fails.

Creates an optional pattern that succeeds even if the given pattern fails.

Value parameters

p

the pattern that is optional

Attributes

Returns

a pattern that succeeds whether p matches or not

Inherited from:
Recognizer
def opta[A](p: Pattern)(f: A => Any): Pattern

Creates an optional pattern with action that applies a function to the matched value if the pattern succeeds, or pushes None if it fails.

Creates an optional pattern with action that applies a function to the matched value if the pattern succeeds, or pushes None if it fails.

Value parameters

f

the action function

p

the pattern that is optional

Attributes

Returns

a pattern that pushes Some(result) or None

Inherited from:
Recognizer
def opti[A](p: Pattern): Pattern

Creates an optional pattern that preserves the matched value if the pattern succeeds, or pushes None if it fails.

Creates an optional pattern that preserves the matched value if the pattern succeeds, or pushes None if it fails.

Value parameters

p

the pattern that is optional

Attributes

Returns

a pattern that pushes Some(value) or None

Inherited from:
Recognizer
def optr(p: Pattern): Pattern

Creates a right-associative optional pattern.

Creates a right-associative optional pattern.

This is like opt() but with reversed order of alternatives, which can affect the order of backtracking.

Value parameters

p

the pattern that is optional

Attributes

Returns

a right-associative optional pattern

Inherited from:
Recognizer
def optra[A](p: Pattern)(f: A => Any): Pattern

Creates a right-associative optional pattern with action.

Creates a right-associative optional pattern with action.

Value parameters

f

the action function

p

the pattern that is optional

Attributes

Returns

a pattern that pushes None or Some(result)

Inherited from:
Recognizer
def optri(p: Pattern): Pattern

Creates a right-associative optional pattern that preserves the matched value.

Creates a right-associative optional pattern that preserves the matched value.

Value parameters

p

the pattern that is optional

Attributes

Returns

a pattern that pushes None or Some(value)

Inherited from:
Recognizer
def optrt(p: Pattern, arity: Int)(f: Seq[Any] => Any): Pattern

Creates a right-associative optional pattern with transformation.

Creates a right-associative optional pattern with transformation.

Value parameters

arity

the number of values to transform

f

the transformation function

p

the pattern that is optional

Attributes

Returns

a pattern that pushes None or Some(result)

Inherited from:
Recognizer
def optt(p: Pattern, arity: Int)(f: Seq[Any] => Any): Pattern

Creates an optional pattern with transformation that applies a function to matched values if the pattern succeeds, or pushes None if it fails.

Creates an optional pattern with transformation that applies a function to matched values if the pattern succeeds, or pushes None if it fails.

Value parameters

arity

the number of values to transform

f

the transformation function

p

the pattern that is optional

Attributes

Returns

a pattern that pushes Some(result) or None

Inherited from:
Recognizer

Creates a pattern that pushes the current input position onto the value stack.

Creates a pattern that pushes the current input position onto the value stack.

Attributes

Returns

a pattern that captures the current position

Inherited from:
Recognizer
def push(v: Any): Pattern

Creates a pattern that pushes a value onto the value stack.

Creates a pattern that pushes a value onto the value stack.

Value parameters

v

the value to push

Attributes

Returns

a pattern that pushes the value

Inherited from:
Recognizer
def rep(p: Pattern): Pattern

Creates a pattern that matches zero or more repetitions of a given pattern.

Creates a pattern that matches zero or more repetitions of a given pattern.

Value parameters

p

the pattern to repeat

Attributes

Returns

a pattern matching zero or more occurrences of p

Inherited from:
Recognizer
def rep1(p: Pattern): Pattern

Creates a pattern that matches one or more repetitions of a given pattern.

Creates a pattern that matches one or more repetitions of a given pattern.

Value parameters

p

the pattern to repeat

Attributes

Returns

a pattern matching one or more occurrences of p

Inherited from:
Recognizer
def rep1a[A](p: Pattern)(f: A => Any): Pattern

Creates a pattern that matches one or more repetitions and collects transformed values.

Creates a pattern that matches one or more repetitions and collects transformed values.

Value parameters

f

the action function to apply to each match

p

the pattern to repeat

Attributes

Returns

a pattern that collects transformed values into a list

Inherited from:
Recognizer
def rep1i(p: Pattern): Pattern

Creates a pattern that matches one or more repetitions and collects the matched values.

Creates a pattern that matches one or more repetitions and collects the matched values.

Value parameters

p

the pattern to repeat

Attributes

Returns

a pattern that collects matched values into a list

Inherited from:
Recognizer
def rep1t(p: Pattern, arity: Int)(f: Seq[Any] => Any): Pattern

Creates a pattern that matches one or more repetitions and collects transformed values.

Creates a pattern that matches one or more repetitions and collects transformed values.

Value parameters

arity

the number of values to transform for each match

f

the transformation function

p

the pattern to repeat

Attributes

Returns

a pattern that collects transformed values into a list

Inherited from:
Recognizer
def repa[A](p: Pattern)(f: A => Any): Pattern

Creates a pattern that matches zero or more repetitions and collects transformed values.

Creates a pattern that matches zero or more repetitions and collects transformed values.

Value parameters

f

the action function to apply to each match

p

the pattern to repeat

Attributes

Returns

a pattern that collects transformed values into a list

Inherited from:
Recognizer
def repi(p: Pattern): Pattern

Creates a pattern that matches zero or more repetitions and collects the matched values.

Creates a pattern that matches zero or more repetitions and collects the matched values.

Value parameters

p

the pattern to repeat

Attributes

Returns

a pattern that collects matched values into a list

Inherited from:
Recognizer
def repr(p: Pattern): Pattern

Creates a right-associative pattern that matches zero or more repetitions.

Creates a right-associative pattern that matches zero or more repetitions.

Value parameters

p

the pattern to repeat

Attributes

Returns

a right-associative pattern matching zero or more occurrences of p

Inherited from:
Recognizer
def repr1(p: Pattern): Pattern

Creates a right-associative pattern that matches one or more repetitions.

Creates a right-associative pattern that matches one or more repetitions.

This is similar to rep1 but with right-associative nesting of repetitions.

Value parameters

p

the pattern to repeat

Attributes

Returns

a right-associative pattern matching one or more occurrences of p

Inherited from:
Recognizer
def repr1a[A](p: Pattern)(f: A => Any): Pattern

Creates a right-associative pattern that matches one or more repetitions and collects transformed values.

Creates a right-associative pattern that matches one or more repetitions and collects transformed values.

Value parameters

f

the action function to apply to each match

p

the pattern to repeat

Attributes

Returns

a right-associative pattern that collects transformed values into a list

Inherited from:
Recognizer

Creates a right-associative pattern that matches one or more repetitions and collects the matched values.

Creates a right-associative pattern that matches one or more repetitions and collects the matched values.

Value parameters

p

the pattern to repeat

Attributes

Returns

a right-associative pattern that collects matched values into a list

Inherited from:
Recognizer
def repr1t(p: Pattern, arity: Int)(f: Seq[Any] => Any): Pattern

Creates a right-associative pattern that matches one or more repetitions and collects transformed values.

Creates a right-associative pattern that matches one or more repetitions and collects transformed values.

Value parameters

arity

the number of values to transform for each match

f

the transformation function

p

the pattern to repeat

Attributes

Returns

a right-associative pattern that collects transformed values into a list

Inherited from:
Recognizer
def repra[A](p: Pattern)(f: A => Any): Pattern

Creates a right-associative pattern that matches zero or more repetitions and collects transformed values.

Creates a right-associative pattern that matches zero or more repetitions and collects transformed values.

Value parameters

f

the action function to apply to each match

p

the pattern to repeat

Attributes

Returns

a right-associative pattern that collects transformed values into a list

Inherited from:
Recognizer
def reprt(p: Pattern, arity: Int)(f: Seq[Any] => Any): Pattern

Creates a right-associative pattern that matches zero or more repetitions and collects transformed values.

Creates a right-associative pattern that matches zero or more repetitions and collects transformed values.

Value parameters

arity

the number of values to transform for each match

f

the transformation function

p

the pattern to repeat

Attributes

Returns

a right-associative pattern that collects transformed values into a list

Inherited from:
Recognizer
def rept(p: Pattern, arity: Int)(f: Seq[Any] => Any): Pattern

Creates a pattern that matches zero or more repetitions and collects transformed values.

Creates a pattern that matches zero or more repetitions and collects transformed values.

Value parameters

arity

the number of values to transform for each match

f

the transformation function

p

the pattern to repeat

Attributes

Returns

a pattern that collects transformed values into a list

Inherited from:
Recognizer
def rerun(state: Runstate): Option[(Option[Any], I, Runstate)]

Continues running from an existing runstate to find the next match.

Continues running from an existing runstate to find the next match.

Value parameters

state

the current execution state

Attributes

Returns

Some((value, remaining input, runstate)) if match succeeded, None if failed

Inherited from:
Recognizer
def run(state: Runstate): Option[(Option[Any], I, Runstate)]

Core pattern matching engine that executes patterns against input.

Core pattern matching engine that executes patterns against input.

Value parameters

state

the current execution state

Attributes

Returns

Some((value, remaining input, runstate)) if match succeeded, None if failed

Inherited from:
Recognizer
def run(input: I, pat: Pattern): Option[(Option[Any], I, Runstate)]

Runs a pattern on input and returns the first match.

Runs a pattern on input and returns the first match.

Value parameters

input

the input to match against

pat

the pattern to match

Attributes

Returns

Some((value, remaining input, runstate)) if match succeeded, None if failed

Inherited from:
Recognizer
def runAll(input: I, pat: Pattern): List[(Option[Any], I)]

Runs a pattern on input and returns all possible matches.

Runs a pattern on input and returns all possible matches.

Value parameters

input

the input to match against

pat

the pattern to match

Attributes

Returns

a list of all possible matches and remaining inputs

Inherited from:
Recognizer
def seq(es: Char*): Pattern

Creates a pattern that matches a sequence of elements.

Creates a pattern that matches a sequence of elements.

Value parameters

es

the elements to match in sequence

Attributes

Returns

a pattern matching the given sequence of elements

Inherited from:
Recognizer
def test[A](c: A => Boolean): Pattern

Creates a pattern that tests the top value on the stack against a predicate.

Creates a pattern that tests the top value on the stack against a predicate.

Value parameters

c

the predicate function

Attributes

Returns

a pattern that succeeds if the predicate returns true

Inherited from:
Recognizer
def testValues(c: List[Any] => Boolean): Pattern

Creates a pattern that tests values on the stack against a predicate.

Creates a pattern that tests values on the stack against a predicate.

Value parameters

c

the predicate function

Attributes

Returns

a pattern that succeeds if the predicate returns true

Inherited from:
Recognizer
def transform(arity: Int)(f: Seq[Any] => Any): Pattern

Creates a pattern that transforms values on the stack.

Creates a pattern that transforms values on the stack.

Value parameters

arity

the number of values to transform

f

the transformation function

Attributes

Returns

a pattern that applies the transformation

Inherited from:
Recognizer

Concrete fields

val alpha: Pattern

Pattern that matches any alphabetic character.

Pattern that matches any alphabetic character.

Attributes

Pattern that matches any alphanumeric character (letter or digit).

Pattern that matches any alphanumeric character (letter or digit).

Attributes

val digit: Pattern

Pattern that matches any digit character.

Pattern that matches any digit character.

Attributes

Pattern that matches one or more digit characters.

Pattern that matches one or more digit characters.

Attributes

val ident: Pattern

Pattern that matches an identifier: a letter or underscore followed by zero or more letters, digits, or underscores, followed by whitespace.

Pattern that matches an identifier: a letter or underscore followed by zero or more letters, digits, or underscores, followed by whitespace.

Attributes

Pattern that matches a numeric literal in various formats:

Pattern that matches a numeric literal in various formats:

  • Integer: one or more digits
  • Decimal: digits with decimal point
  • Scientific notation: decimal or integer with optional exponent

Attributes

Pattern that matches any whitespace character.

Pattern that matches any whitespace character.

Attributes

val ws: Pattern

Pattern that matches zero or more whitespace characters.

Pattern that matches zero or more whitespace characters.

Attributes

val ws1: Pattern

Pattern that matches one or more whitespace characters.

Pattern that matches one or more whitespace characters.

Attributes

Inherited fields

var runlimit: Int

Execution limit for pattern matching, useful for debugging infinite loops. Set to Int.MaxValue by default (effectively unlimited).

Execution limit for pattern matching, useful for debugging infinite loops. Set to Int.MaxValue by default (effectively unlimited).

Attributes

Inherited from:
Recognizer

Implicits

Implicits

implicit def str(s: String): Pattern

Implicitly converts a string to a pattern that matches that exact string.

Implicitly converts a string to a pattern that matches that exact string.

Value parameters

s

the string to match

Attributes

Returns

a pattern that matches the given string

Inherited implicits

implicit def elem(e: Char): Pattern

Implicitly converts an element to a pattern that matches that element.

Implicitly converts an element to a pattern that matches that element.

Value parameters

e

the element to match

Attributes

Returns

a pattern that matches the given element

Inherited from:
Recognizer