Make End patterns instanced so expects() can be used on them
This commit is contained in:
parent
50df27c50e
commit
5c5884a39b
2 changed files with 15 additions and 11 deletions
4
notcl.js
4
notcl.js
|
@ -44,7 +44,7 @@ var Notcl = (() => {
|
|||
|
||||
const CommandTerminator = Sequence(
|
||||
PreWordWhitespace,
|
||||
Choose(/** @type {Peg.Pattern<unknown>} */ (Regex(/[\n;]/y)), End)
|
||||
Choose(/** @type {Peg.Pattern<unknown>} */ (Regex(/[\n;]/y)), End())
|
||||
);
|
||||
|
||||
/** @type {Peg.Pattern<Notcl.Command>} */
|
||||
|
@ -53,7 +53,7 @@ var Notcl = (() => {
|
|||
);
|
||||
|
||||
/** @type {Peg.Pattern<Notcl.Script>} */
|
||||
const Script = Sequence(AtLeast(0, Command), End).map(
|
||||
const Script = Sequence(AtLeast(0, Command), End()).map(
|
||||
([commands, _eof]) => commands
|
||||
);
|
||||
|
||||
|
|
22
peg.js
22
peg.js
|
@ -165,13 +165,17 @@ Peg.AtLeast = function (min, pattern) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Pattern that matches the end of input
|
||||
* @type {Peg.Pattern<true>}
|
||||
* Creates a pattern that matches the end of input
|
||||
* @return {Peg.Pattern<true>}
|
||||
*/
|
||||
Peg.End = Peg.WrapPattern(function End(source, index) {
|
||||
if (source.length == index) {
|
||||
return [true, /** @type {true} */ (true), index];
|
||||
} else {
|
||||
return [false, index, "<eof>"];
|
||||
}
|
||||
}).expects("<eof>");
|
||||
Peg.End = () => {
|
||||
/** @type {Peg.Pattern<true>} */
|
||||
const end = Peg.WrapPattern(function End(source, index) {
|
||||
if (source.length == index) {
|
||||
return [true, /** @type {true} */ (true), index];
|
||||
} else {
|
||||
return [false, index, end.expectLabel];
|
||||
}
|
||||
}).expects("<eof>");
|
||||
return end;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue