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.

17 lines
457 B
JavaScript

"use strict";
const { NoMatch, NotEnoughInput } = require("../symbols");
module.exports = function* literal(instruction, state) {
let { string } = instruction;
if (state.currentIndex + string.length > state.currentInput.length) {
return NotEnoughInput;
} else if (state.currentInput.slice(state.currentIndex, state.currentIndex + string.length) === string) {
state.currentIndex += string.length;
return string;
} else {
return NoMatch;
}
};