mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
feat(parsely): Add a fail() parser
I've found this useful for stubbing out parts of a grammar during development.
This commit is contained in:
parent
c9a43ce5c0
commit
5656d9d42f
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user