Skip to main content
Module

x/nearley/mod.ts>Parser

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
Latest
class Parser
import { Parser } from "https://deno.land/x/nearley@2.19.7-deno/mod.ts";

Constructors

new
Parser(grammar: Grammar, options?: ParserOptions)

Properties

current: number
grammar: Grammar
lexer: Lexer
optional
lexerState: LexerState
options: ParserOptions
results: any[]

An array of possible parsings. Each element is the thing returned by your grammar.

Note that this is undefined before the first feed() call. It isn't typed as any[] | undefined to spare you the null checks when it's definitely an array.

Methods

feed(chunk: string): this

The Parser object can be fed data in parts with .feed(data). You can then find an array of parsings with the .results property. If results is empty, then there are no parsings. If results contains multiple values, then that combination is ambiguous.

finish(): any[]
restore(column: { [key: string]: any; lexerState: LexerState; }): void
save(): { [key: string]: any; lexerState: LexerState; }

Static Properties

fail: { }

Reserved token for indicating a parse fail.