pegisland
Version:
General PEG-based parser supporting island grammars with lake symbols
29 lines • 827 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rule = void 0;
const ParseTree_1 = require("./ParseTree");
class Rule {
constructor(symbol, rhs, isWater = false) {
this.symbol = symbol;
this.rhs = rhs;
this.isWater = isWater;
}
parse(env, pos) {
return this.parseWithoutMemo(env, pos);
}
parseWithoutMemo(env, pos) {
env.push();
const result = env.parse(this.rhs, pos);
env.pop();
if (result === null) {
return null;
}
const [childNode, nextIndex] = result;
return [
new ParseTree_1.NodeNonterminal(this.symbol, new ParseTree_1.Range(pos, nextIndex), childNode),
nextIndex,
];
}
}
exports.Rule = Rule;
//# sourceMappingURL=Rule.js.map