Add End to Peg
This commit is contained in:
parent
347af33bf1
commit
a3cdc53330
1 changed files with 13 additions and 1 deletions
14
peg.js
14
peg.js
|
@ -84,7 +84,7 @@ var Peg = {
|
|||
* If the given pattern does not consume input, the matching will be terminated to prevent an eternal loop.
|
||||
*
|
||||
* Note that if the minimum run is zero, this pattern will always succeed, but might not consume any input.
|
||||
* @template {unknown[]} T
|
||||
* @template {unknown} T
|
||||
* @param {number} min
|
||||
* @param {Peg.Pattern<T>} pattern
|
||||
* @return {Peg.Pattern<T[]>}
|
||||
|
@ -106,4 +106,16 @@ var Peg = {
|
|||
}
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Pattern that matches the end of input
|
||||
* @type {Peg.Pattern<true>}
|
||||
*/
|
||||
End(source, index) {
|
||||
if (source.length == index) {
|
||||
return [true, index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue