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.
24 lines
522 B
JavaScript
24 lines
522 B
JavaScript
2 years ago
|
"use strict";
|
||
|
|
||
|
const { NotEnoughInput, NoMatch } = require("../symbols");
|
||
|
|
||
|
module.exports = function* zeroOrMore(instruction, state) {
|
||
|
let matches = [];
|
||
|
|
||
|
while (true) {
|
||
|
let result = yield instruction.rule;
|
||
|
|
||
|
// FIXME: is NotEnoughInput handling actually necessary here? Wouldn't that be handled by the runtime hook?
|
||
|
if (result === NotEnoughInput) {
|
||
|
// Propagate, reparse later
|
||
|
return NotEnoughInput;
|
||
|
} else if (result === NoMatch) {
|
||
|
break;
|
||
|
} else {
|
||
|
matches.push(result);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return matches;
|
||
|
};
|