lexer

package
v1.0.75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lexer

type Lexer[T comparable, V any] struct {
	// contains filtered or unexported fields
}

Lexer is a simple trie-based lexer

func New

func New[T comparable, V any]() *Lexer[T, V]

New creates a new Lexer instance

func (*Lexer[T, V]) FirstMatch

func (l *Lexer[T, V]) FirstMatch(input iter.Seq[T]) (V, int, bool)

FirstMatch returns the first (shortest) pattern that matches a prefix of the input. Returns the value, number of elements consumed, and whether a match was found.

func (*Lexer[T, V]) FirstMatchSlice

func (l *Lexer[T, V]) FirstMatchSlice(input []T) (V, int, bool)

FirstMatchSlice returns the first (shortest) pattern that matches a prefix of the input.

func (*Lexer[T, V]) InsertIter

func (l *Lexer[T, V]) InsertIter(pattern iter.Seq[T], value V)

InsertIter inserts a pattern into the trie with the associated value.

func (*Lexer[T, V]) InsertSlice

func (l *Lexer[T, V]) InsertSlice(pattern []T, value V)

InsertSlice inserts a slice pattern into the trie with the associated value.

func (*Lexer[T, V]) LongestMatch

func (l *Lexer[T, V]) LongestMatch(input iter.Seq[T]) (V, int, bool)

LongestMatch returns the longest pattern that matches a prefix of the input. Returns the value, number of elements consumed, and whether a match was found.

func (*Lexer[T, V]) LongestMatchSlice

func (l *Lexer[T, V]) LongestMatchSlice(input []T) (V, int, bool)

LongestMatchSlice returns the longest pattern that matches a prefix of the input.

func (*Lexer[T, V]) Match

func (l *Lexer[T, V]) Match(input iter.Seq[T]) (V, bool)

Match returns the value if the entire input exactly matches a pattern.

func (*Lexer[T, V]) MatchSlice

func (l *Lexer[T, V]) MatchSlice(input []T) (V, bool)

MatchSlice returns the value if the entire input exactly matches a pattern.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL