Skip to content

Commit

Permalink
feat(parsely): Add a fail() parser
Browse files Browse the repository at this point in the history
I've found this useful for stubbing out parts of a grammar during
development.
  • Loading branch information
AtkinsSJ committed May 31, 2024
1 parent c9a43ce commit 5656d9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/phoenix/packages/parsely/exports.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -81,6 +81,7 @@ export class GrammarContext {
export const standard_parsers = () => {
return {
discard: Discard,
fail: Fail,
firstMatch: FirstMatch,
literal: Literal,
none: None,
Expand Down
11 changes: 11 additions & 0 deletions packages/phoenix/packages/parsely/parsers/terminals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 5656d9d

Please sign in to comment.