"use strict"; const { NoMatch, NotEnoughInput } = require("../symbols"); module.exports = function* until(instruction, state, context) { while (state.currentIndex < state.currentInput.length) { let attemptIndex = state.currentIndex; let result = yield instruction.rule; if (result === NoMatch) { state.currentIndex += 1; continue; } else { // Un-consume the terminator we've matched, and continue parsing other rules state.currentIndex = attemptIndex; if (state.currentIndex > context.startIndex) { return state.currentInput.slice(context.startIndex, state.currentIndex); } else { // Zero-width match; that's a fail return NoMatch; } } } // Reached the end of the currently available input, and we still haven't encountered our terminator return NotEnoughInput; };