nex

package
v0.0.0-...-2fc8d58 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpectedLBrace    = errors.New("expected '{'")
	ErrUnmatchedLBrace   = errors.New("unmatched '{'")
	ErrUnexpectedEOF     = errors.New("unexpected EOF")
	ErrUnexpectedNewline = errors.New("unexpected newline")
	ErrUnexpectedLAngle  = errors.New("unexpected '<'")
	ErrUnmatchedRAngle   = errors.New("unmatched '>'")
)

Functions

func Exec

func Exec(name string, args ...string)

func ExecWithParams

func ExecWithParams(p *ExecParams)

Types

type BuildResult

type BuildResult struct {
	Lexer  []byte
	NfaDot []byte
	DfaDot []byte
}

type Builder

type Builder struct {
	Standalone   bool
	CustomError  bool
	CustomPrefix string
	Result       BuildResult
	// contains filtered or unexported fields
}

func (*Builder) Process

func (b *Builder) Process(inputSource io.Reader) error

type Dfa

type Dfa struct {
	Nodes []*node
	Start *node
}

Dfa - DFA: Deterministic Finite Automaton

func BuildDfa

func BuildDfa(nfa *Nfa) *Dfa

BuildDfa NFA -> DFA

type ExecParams

type ExecParams struct {
	Standalone           bool
	CustomError          bool
	CustomPrefix         string
	InputFilename        string
	OutputFilename       string
	NfaDotOutputFilename string
	DfaDotOutputFilename string
	RunProgram           bool
	Stdin                io.Reader
	Stdout               io.Writer
	Stderr               io.Writer
}

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(in io.Reader) *Lexer

NewLexer creates a new lexer without init.

func NewLexerWithInit

func NewLexerWithInit(in io.Reader, initFun func(*Lexer)) *Lexer

NewLexerWithInit creates a new Lexer object, runs the given callback on it, then returns it.

func (*Lexer) Column

func (yylex *Lexer) Column() int

Column returns the current column number. The first column is 0.

func (*Lexer) Error

func (yylex *Lexer) Error(e string)

func (*Lexer) Lex

func (yylex *Lexer) Lex(lval *yySymType) int

Lex runs the lexer. Always returns 0. When the -s option is given, this function is not generated; instead, the NN_FUN macro runs the lexer.

func (*Lexer) Line

func (yylex *Lexer) Line() int

Line returns the current line number. The first line is 0.

func (*Lexer) Stop

func (yylex *Lexer) Stop()

func (*Lexer) Text

func (yylex *Lexer) Text() string

Text returns the matched text.

type Nfa

type Nfa struct {
	Start   *node
	Nodes   []*node
	Lim     []rune
	Singles []rune
}

Nfa - NFA: Nondeterministic Finite Automaton

func BuildNfa

func BuildNfa(root *rule) (*Nfa, error)

BuildNfa Regex -> NFA We cannot have our alphabet be all Unicode characters. Instead, we compute an alphabet for each regex:

  1. Singles: we add single runes used in the regex: any rune not in a range. These are held in `singles`.

  2. Ranges: entire ranges become elements of the alphabet. If ranges in the same expression overlap, we break them up into non-overlapping ranges. The generated code checks singles before ranges, so there's no need to break up a range if it contains a single. These are maintained in sorted order in `lim`.

  3. Wild: we add an element representing all other runes.

e.g. the alphabet of /[0-9]*[Ee][2-5]*/ is singles: { E, e }, lim: { [0-1], [2-5], [6-9] } and the wild element.

Jump to

Keyboard shortcuts

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