diff --git a/packages/phoenix/packages/parsely/exports.js b/packages/phoenix/packages/parsely/exports.js index b729a589..29f956b9 100644 --- a/packages/phoenix/packages/parsely/exports.js +++ b/packages/phoenix/packages/parsely/exports.js @@ -1,6 +1,6 @@ import { adapt_parser, VALUE } from './parser.js'; import { Discard, FirstMatch, Optional, Repeat, Sequence } from './parsers/combinators.js'; -import { Literal, None, StringOf, Symbol } from './parsers/terminals.js'; +import { Fail, Literal, None, StringOf, Symbol } from './parsers/terminals.js'; class ParserWithAction { #parser; @@ -81,6 +81,7 @@ export class GrammarContext { export const standard_parsers = () => { return { discard: Discard, + fail: Fail, firstMatch: FirstMatch, literal: Literal, none: None, diff --git a/packages/phoenix/packages/parsely/parsers/terminals.js b/packages/phoenix/packages/parsely/parsers/terminals.js index 10936540..62c19df6 100644 --- a/packages/phoenix/packages/parsely/parsers/terminals.js +++ b/packages/phoenix/packages/parsely/parsers/terminals.js @@ -91,3 +91,14 @@ export class None extends Parser { return { status: VALUE, $: 'none', $discard: true }; } } + +/** + * Always fails parsing. + */ +export class Fail extends Parser { + _create () {} + + _parse (stream) { + return UNRECOGNIZED; + } +}