You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
499 B
JavaScript
29 lines
499 B
JavaScript
2 years ago
|
"use strict";
|
||
|
|
||
|
const { NoMatch } = require("../symbols");
|
||
|
const coreOps = require("./index");
|
||
|
|
||
|
module.exports = function* zeroOrMore(instruction, state, context) {
|
||
|
let { rule } = instruction;
|
||
|
|
||
|
let matches = [];
|
||
|
|
||
|
while (true) {
|
||
|
let reachedEnd = yield coreOps.internalCall.endOfInput({}, state, context);
|
||
|
|
||
|
if (reachedEnd === true) {
|
||
|
break;
|
||
|
} else {
|
||
|
let result = yield rule;
|
||
|
|
||
|
if (result === NoMatch) {
|
||
|
break;
|
||
|
} else {
|
||
|
matches.push(result);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return matches;
|
||
|
};
|