Skip to content

Commit 5656d9d

Browse files
committed
feat(parsely): Add a fail() parser
I've found this useful for stubbing out parts of a grammar during development.
1 parent c9a43ce commit 5656d9d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/phoenix/packages/parsely/exports.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { adapt_parser, VALUE } from './parser.js';
22
import { Discard, FirstMatch, Optional, Repeat, Sequence } from './parsers/combinators.js';
3-
import { Literal, None, StringOf, Symbol } from './parsers/terminals.js';
3+
import { Fail, Literal, None, StringOf, Symbol } from './parsers/terminals.js';
44

55
class ParserWithAction {
66
#parser;
@@ -81,6 +81,7 @@ export class GrammarContext {
8181
export const standard_parsers = () => {
8282
return {
8383
discard: Discard,
84+
fail: Fail,
8485
firstMatch: FirstMatch,
8586
literal: Literal,
8687
none: None,

packages/phoenix/packages/parsely/parsers/terminals.js

+11
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,14 @@ export class None extends Parser {
9191
return { status: VALUE, $: 'none', $discard: true };
9292
}
9393
}
94+
95+
/**
96+
* Always fails parsing.
97+
*/
98+
export class Fail extends Parser {
99+
_create () {}
100+
101+
_parse (stream) {
102+
return UNRECOGNIZED;
103+
}
104+
}

0 commit comments

Comments
 (0)