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
502 B
JavaScript

"use strict";
const { NoMatch } = require("../symbols");
module.exports = function* either(instruction, state, context) {
let { options } = instruction;
for (let option of options) {
let result = yield option;
if (result === NoMatch) {
// Restore index and try again with the next option
state.currentIndex = context.startIndex;
continue;
} else {
// Don't restore index; the match has been consumed
return result;
}
}
// None of the options matched
return NoMatch;
};