WIP
parent
22a8505797
commit
0a74f6824e
@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
const mapObject = require("map-obj");
|
||||
const yieldcore = require("../yieldcore");
|
||||
|
||||
let coreOps = {
|
||||
literal: require("./literal"),
|
||||
characterRange: require("./character-range"),
|
||||
endOfInput: require("./end-of-input"),
|
||||
either: require("./either"),
|
||||
peek: require("./peek"),
|
||||
test: require("./test"),
|
||||
zeroOrMore: require("./zero-or-more"),
|
||||
oneOrMore: require("./one-or-more"),
|
||||
optional: require("./optional"),
|
||||
until: require("./until"),
|
||||
wholeMatch: require("./whole-match"),
|
||||
// FIXME: Implement trackPosition
|
||||
};
|
||||
|
||||
Object.assign(module.exports, {
|
||||
... coreOps,
|
||||
internalCall: mapObject(coreOps, (name, func) => {
|
||||
return [
|
||||
name,
|
||||
function (properties, state, context) {
|
||||
let instruction = {
|
||||
__protocolKitInstruction: true,
|
||||
type: name,
|
||||
... properties,
|
||||
};
|
||||
|
||||
return yieldcore.Internal(func(instruction, state, context), instruction);
|
||||
}
|
||||
];
|
||||
})
|
||||
});
|
@ -1,23 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
const { NotEnoughInput, NoMatch } = require("../symbols");
|
||||
const { NoMatch } = require("../symbols");
|
||||
const coreOps = require("./index");
|
||||
|
||||
module.exports = function* zeroOrMore(instruction, state, context) {
|
||||
let { rule } = instruction;
|
||||
|
||||
module.exports = function* zeroOrMore(instruction, state) {
|
||||
let matches = [];
|
||||
|
||||
while (true) {
|
||||
let reachedEnd = yield coreOps.internalCall.endOfInput({ rule: rule }, state, context);
|
||||
// yieldcore.Internal(endOfInput(instruction, state, context), "endOfInput");
|
||||
|
||||
if (reachedEnd === true) {
|
||||
break;
|
||||
} else {
|
||||
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) {
|
||||
if (result === NoMatch) {
|
||||
break;
|
||||
} else {
|
||||
matches.push(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
};
|
||||
|
Loading…
Reference in New Issue