Recognizer

io.github.edadma.recognizer.Recognizer
trait Recognizer[W, E]

Core trait providing pattern matching functionality over an input stream.

The Recognizer trait defines a composable pattern matching DSL with support for backtracking, value capture, and transformation. It implements a recursive descent parser with explicit backtracking control through choice points.

Type parameters

E

the type of elements in the input stream

W

the type of wrapped values associated with input elements

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait CharRecognizer[W]

Members list

Type members

Classlikes

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

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
protected trait Choice

Attributes

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

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

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

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
Self type
Cut.type
protected case object Fail extends Pattern

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
Self type
Fail.type
protected case object Fence extends Pattern, Choice

Attributes

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
Self type
Fence.type
protected case class LookBehind(p: E => Boolean) extends Pattern

Attributes

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

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

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

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
Self type
Nop.type
protected case class Not(p: Pattern) extends Pattern

Attributes

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

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

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

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all
Self type
Pointer.type
protected case class Push(v: Any) extends Pattern

Attributes

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

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

Attributes

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

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

Supertypes
trait Serializable
trait Product
trait Equals
trait Pattern
class Object
trait Matchable
class Any
Show all

Types

type I = Input[W, E]

Type alias for the input type used by this recognizer

Type alias for the input type used by this recognizer

Attributes

Value members

Concrete 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

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

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

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

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

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

def anyOf(es: E*): 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

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

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

def clas(c: E => 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

A pattern that always fails.

A pattern that always fails.

Attributes

Returns

a pattern that always fails

def fence: Pattern

Creates a fence marker for backtracking control.

Creates a fence marker for backtracking control.

Attributes

Returns

a pattern representing a fence

def lookBehind(p: E => 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

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

def noneOf(es: E*): 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

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

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

def notLookBehind(p: E => 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

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

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

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

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

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)

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)

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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

def seq(es: E*): 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

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

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

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

Concrete 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

Implicits

Implicits

implicit def elem(e: E): 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