Skip to main content
Module

x/moo/mod.ts>Rule

Optimised tokenizer/lexer generator! 🐄 Uses /y for performance. Moo.
Latest
interface Rule
import { type Rule } from "https://deno.land/x/moo@0.5.1-deno.2/mod.ts";

Properties

optional
match: RegExp | string | string[]
optional
lineBreaks: boolean

Moo tracks detailed information about the input for you. It will track line numbers, as long as you apply the lineBreaks: true option to any tokens which might contain newlines. Moo will try to warn you if you forget to do this.

optional
push: string

Moves the lexer to a new state, and pushes the old state onto the stack.

optional
pop: number

Returns to a previous state, by removing one or more states from the stack.

optional
next: string

Moves to a new state, but does not affect the stack.

optional
error: true

You can have a token type that both matches tokens and contains error values.

optional
value: (x: string) => string

Moo doesn't allow capturing groups, but you can supply a transform function, value(), which will be called on the value before storing it in the Token object.

optional
type: TypeMapper

Used for mapping one set of types to another. See https://github.com/no-context/moo#keywords for an example