Regex pattern returns custom expects() if set
This commit is contained in:
parent
5c5884a39b
commit
3bb125dd8c
1 changed files with 4 additions and 2 deletions
6
peg.js
6
peg.js
|
@ -69,13 +69,15 @@ Peg.Use = function (getPattern) {
|
|||
* @return {Peg.Pattern<RegExpExecArray>}
|
||||
*/
|
||||
Peg.Regex = function (regex) {
|
||||
return Peg.WrapPattern(function (source, index) {
|
||||
/** @type {Peg.Pattern<RegExpExecArray>} */
|
||||
const pattern = Peg.WrapPattern(function (source, index) {
|
||||
regex.lastIndex = index;
|
||||
const matches = regex.exec(source);
|
||||
return matches
|
||||
? [true, matches, regex.lastIndex]
|
||||
: [false, index, regex.source];
|
||||
: [false, index, pattern.expectLabel];
|
||||
}).expects(regex.source);
|
||||
return pattern;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue