ohm-js 17.3.0 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ohm-extras.cjs +51 -0
- package/dist/ohm-extras.js +51 -0
- package/dist/ohm.cjs +2 -1
- package/dist/ohm.cjs.map +1 -1
- package/dist/ohm.js +3 -2
- package/dist/ohm.min.js +1 -1
- package/extras/index.d.ts +7 -11
- package/extras/index.mjs +1 -0
- package/extras/recoverSourceOrder.js +48 -0
- package/package.json +1 -1
- package/src/pexprs-eval.js +1 -0
- package/src/version.js +1 -1
package/dist/ohm-extras.cjs
CHANGED
|
@@ -2567,6 +2567,7 @@ Apply.prototype.reallyEval = function (state) {
|
|
|
2567
2567
|
}
|
|
2568
2568
|
if (memoRec) {
|
|
2569
2569
|
memoRec.failuresAtRightmostPosition = state.cloneRecordedFailures();
|
|
2570
|
+
memoRec.rightmostFailureOffset = state._getRightmostFailureOffset();
|
|
2570
2571
|
}
|
|
2571
2572
|
}
|
|
2572
2573
|
|
|
@@ -6042,9 +6043,59 @@ function extractExamples(grammarsDef) {
|
|
|
6042
6043
|
return semantics(matchResult).examples();
|
|
6043
6044
|
}
|
|
6044
6045
|
|
|
6046
|
+
/*
|
|
6047
|
+
To find iter nodes that are derived from the same repetition expression, we
|
|
6048
|
+
look for adjacent iter nodes that have the same source interval and the same
|
|
6049
|
+
number of children.
|
|
6050
|
+
|
|
6051
|
+
A few things to note:
|
|
6052
|
+
- The children of `*` and `+` nodes can't be nullable, so the associated iter
|
|
6053
|
+
nodes always consume some input, and therefore consecutive nodes that have
|
|
6054
|
+
the same interval must come from the same repetition expression.
|
|
6055
|
+
- We *could* mistake `a? b?` for (a b)?`, if neither of them comsume any input.
|
|
6056
|
+
However, for the purposes of this module, those two cases are equivalent
|
|
6057
|
+
anyways, since we only care about finding the correct order of the non-iter
|
|
6058
|
+
nodes, and both interpretations yield the same order.
|
|
6059
|
+
*/
|
|
6060
|
+
const isIterSibling = (refNode, n) => {
|
|
6061
|
+
return (
|
|
6062
|
+
n.isIteration() &&
|
|
6063
|
+
n.source.startIdx === refNode.source.startIdx &&
|
|
6064
|
+
n.source.endIdx === refNode.source.endIdx &&
|
|
6065
|
+
n.children.length === refNode.children.length
|
|
6066
|
+
);
|
|
6067
|
+
};
|
|
6068
|
+
|
|
6069
|
+
function recoverSourceOrder(nodes, depth = 0) {
|
|
6070
|
+
const ans = [];
|
|
6071
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
6072
|
+
const n = nodes[i];
|
|
6073
|
+
if (!n.isIteration()) {
|
|
6074
|
+
ans.push(n);
|
|
6075
|
+
continue;
|
|
6076
|
+
}
|
|
6077
|
+
|
|
6078
|
+
// We found an iter node, now find its siblings.
|
|
6079
|
+
const siblings = [n];
|
|
6080
|
+
// Find the first node that's *not* part of the current list.
|
|
6081
|
+
for (let j = i + 1; j < nodes.length && isIterSibling(n, nodes[j]); j++) {
|
|
6082
|
+
siblings.push(nodes[j]);
|
|
6083
|
+
i = j;
|
|
6084
|
+
}
|
|
6085
|
+
const cousins = [];
|
|
6086
|
+
const numRows = siblings[0].children.length;
|
|
6087
|
+
for (let row = 0; row < numRows; row++) {
|
|
6088
|
+
cousins.push(...siblings.map(sib => sib.children[row]));
|
|
6089
|
+
}
|
|
6090
|
+
ans.push(...recoverSourceOrder(cousins, depth + 1));
|
|
6091
|
+
}
|
|
6092
|
+
return ans;
|
|
6093
|
+
}
|
|
6094
|
+
|
|
6045
6095
|
exports.VisitorFamily = VisitorFamily;
|
|
6046
6096
|
exports.extractExamples = extractExamples;
|
|
6047
6097
|
exports.getLineAndColumn = getLineAndColumn;
|
|
6048
6098
|
exports.getLineAndColumnMessage = getLineAndColumnMessage;
|
|
6099
|
+
exports.recoverSourceOrder = recoverSourceOrder;
|
|
6049
6100
|
exports.semanticsForToAST = semanticsForToAST;
|
|
6050
6101
|
exports.toAST = toAST;
|
package/dist/ohm-extras.js
CHANGED
|
@@ -2569,6 +2569,7 @@
|
|
|
2569
2569
|
}
|
|
2570
2570
|
if (memoRec) {
|
|
2571
2571
|
memoRec.failuresAtRightmostPosition = state.cloneRecordedFailures();
|
|
2572
|
+
memoRec.rightmostFailureOffset = state._getRightmostFailureOffset();
|
|
2572
2573
|
}
|
|
2573
2574
|
}
|
|
2574
2575
|
|
|
@@ -6044,10 +6045,60 @@
|
|
|
6044
6045
|
return semantics(matchResult).examples();
|
|
6045
6046
|
}
|
|
6046
6047
|
|
|
6048
|
+
/*
|
|
6049
|
+
To find iter nodes that are derived from the same repetition expression, we
|
|
6050
|
+
look for adjacent iter nodes that have the same source interval and the same
|
|
6051
|
+
number of children.
|
|
6052
|
+
|
|
6053
|
+
A few things to note:
|
|
6054
|
+
- The children of `*` and `+` nodes can't be nullable, so the associated iter
|
|
6055
|
+
nodes always consume some input, and therefore consecutive nodes that have
|
|
6056
|
+
the same interval must come from the same repetition expression.
|
|
6057
|
+
- We *could* mistake `a? b?` for (a b)?`, if neither of them comsume any input.
|
|
6058
|
+
However, for the purposes of this module, those two cases are equivalent
|
|
6059
|
+
anyways, since we only care about finding the correct order of the non-iter
|
|
6060
|
+
nodes, and both interpretations yield the same order.
|
|
6061
|
+
*/
|
|
6062
|
+
const isIterSibling = (refNode, n) => {
|
|
6063
|
+
return (
|
|
6064
|
+
n.isIteration() &&
|
|
6065
|
+
n.source.startIdx === refNode.source.startIdx &&
|
|
6066
|
+
n.source.endIdx === refNode.source.endIdx &&
|
|
6067
|
+
n.children.length === refNode.children.length
|
|
6068
|
+
);
|
|
6069
|
+
};
|
|
6070
|
+
|
|
6071
|
+
function recoverSourceOrder(nodes, depth = 0) {
|
|
6072
|
+
const ans = [];
|
|
6073
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
6074
|
+
const n = nodes[i];
|
|
6075
|
+
if (!n.isIteration()) {
|
|
6076
|
+
ans.push(n);
|
|
6077
|
+
continue;
|
|
6078
|
+
}
|
|
6079
|
+
|
|
6080
|
+
// We found an iter node, now find its siblings.
|
|
6081
|
+
const siblings = [n];
|
|
6082
|
+
// Find the first node that's *not* part of the current list.
|
|
6083
|
+
for (let j = i + 1; j < nodes.length && isIterSibling(n, nodes[j]); j++) {
|
|
6084
|
+
siblings.push(nodes[j]);
|
|
6085
|
+
i = j;
|
|
6086
|
+
}
|
|
6087
|
+
const cousins = [];
|
|
6088
|
+
const numRows = siblings[0].children.length;
|
|
6089
|
+
for (let row = 0; row < numRows; row++) {
|
|
6090
|
+
cousins.push(...siblings.map(sib => sib.children[row]));
|
|
6091
|
+
}
|
|
6092
|
+
ans.push(...recoverSourceOrder(cousins, depth + 1));
|
|
6093
|
+
}
|
|
6094
|
+
return ans;
|
|
6095
|
+
}
|
|
6096
|
+
|
|
6047
6097
|
exports.VisitorFamily = VisitorFamily;
|
|
6048
6098
|
exports.extractExamples = extractExamples;
|
|
6049
6099
|
exports.getLineAndColumn = getLineAndColumn;
|
|
6050
6100
|
exports.getLineAndColumnMessage = getLineAndColumnMessage;
|
|
6101
|
+
exports.recoverSourceOrder = recoverSourceOrder;
|
|
6051
6102
|
exports.semanticsForToAST = semanticsForToAST;
|
|
6052
6103
|
exports.toAST = toAST;
|
|
6053
6104
|
|
package/dist/ohm.cjs
CHANGED
|
@@ -2276,6 +2276,7 @@ Apply.prototype.reallyEval = function (state) {
|
|
|
2276
2276
|
}
|
|
2277
2277
|
if (memoRec) {
|
|
2278
2278
|
memoRec.failuresAtRightmostPosition = state.cloneRecordedFailures();
|
|
2279
|
+
memoRec.rightmostFailureOffset = state._getRightmostFailureOffset();
|
|
2279
2280
|
}
|
|
2280
2281
|
}
|
|
2281
2282
|
|
|
@@ -5599,7 +5600,7 @@ Object.assign(IndentationSensitive, {
|
|
|
5599
5600
|
});
|
|
5600
5601
|
|
|
5601
5602
|
// Generated by scripts/prebuild.js
|
|
5602
|
-
const version = '17.
|
|
5603
|
+
const version = '17.4.0';
|
|
5603
5604
|
|
|
5604
5605
|
Grammar.initApplicationParser(ohmGrammar, buildGrammar);
|
|
5605
5606
|
|