ohm-js 17.1.0-pre → 17.1.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 +10 -21
- package/dist/ohm-extras.js +10 -21
- package/dist/ohm.cjs +1 -1
- package/dist/ohm.cjs.map +1 -1
- package/dist/ohm.js +2 -2
- package/dist/ohm.min.js +1 -1
- package/extras/extractExamples.js +10 -21
- package/package.json +1 -1
- package/src/version.js +1 -1
package/dist/ohm-extras.cjs
CHANGED
|
@@ -5845,13 +5845,7 @@ const grammarsSource = String.raw`
|
|
|
5845
5845
|
// Example:
|
|
5846
5846
|
//+ "//+ \"x\"\nG {\n//- \"\"\nstart = \"x\"}"
|
|
5847
5847
|
OhmWithExamples <: Ohm {
|
|
5848
|
-
|
|
5849
|
-
// When the start rule is a syntactic rule, there's no way to get access to
|
|
5850
|
-
// leading space (including comments). So, for this grammar to be useful,
|
|
5851
|
-
// you have to explicit use this rule as the start rule.
|
|
5852
|
-
grammarsWithExamples = (exampleComments applySyntactic<Grammar>)*
|
|
5853
|
-
|
|
5854
|
-
Grammar := ident SuperGrammar? "{" (#exampleComments Rule)* "}"
|
|
5848
|
+
Grammar := ident SuperGrammar? "{" (#exampleComments Rule)* #exampleComments "}"
|
|
5855
5849
|
|
|
5856
5850
|
exampleComments = (spacesNoExampleComment exampleComment)*
|
|
5857
5851
|
|
|
@@ -5915,19 +5909,10 @@ const semantics = grammars.OhmWithExamples.createSemantics().addOperation('hasEx
|
|
|
5915
5909
|
});
|
|
5916
5910
|
|
|
5917
5911
|
semantics.addOperation('examples', {
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
for (const [i, child] of Object.entries(grammarIter.children)) {
|
|
5921
|
-
if (exampleCommentsIter.hasExamples()) {
|
|
5922
|
-
const defaultExamples = exampleCommentsIter.child(i).examples();
|
|
5923
|
-
const grammar = child.grammarName();
|
|
5924
|
-
result.push(...defaultExamples.map(ex => ({...ex, grammar, rule: ''})));
|
|
5925
|
-
}
|
|
5926
|
-
result.push(...child.examples());
|
|
5927
|
-
}
|
|
5928
|
-
return result;
|
|
5912
|
+
Grammars(grammarIter) {
|
|
5913
|
+
return grammarIter.children.flatMap(c => c.examples());
|
|
5929
5914
|
},
|
|
5930
|
-
Grammar(name, _, _open, exampleCommentsIter, ruleIter, _close) {
|
|
5915
|
+
Grammar(name, _, _open, exampleCommentsIter, ruleIter, trailingCommentsIter, _close) {
|
|
5931
5916
|
const result = [];
|
|
5932
5917
|
const grammar = this.grammarName();
|
|
5933
5918
|
for (let i = 0; i < ruleIter.numChildren; i++) {
|
|
@@ -5939,6 +5924,10 @@ semantics.addOperation('examples', {
|
|
|
5939
5924
|
|
|
5940
5925
|
result.push(...augmentedExamples);
|
|
5941
5926
|
}
|
|
5927
|
+
if (trailingCommentsIter.hasExamples()) {
|
|
5928
|
+
const defaultExamples = trailingCommentsIter.examples();
|
|
5929
|
+
result.push(...defaultExamples.map(ex => ({...ex, grammar, rule: ''})));
|
|
5930
|
+
}
|
|
5942
5931
|
return result;
|
|
5943
5932
|
},
|
|
5944
5933
|
exampleComments(_, commentIter) {
|
|
@@ -5964,7 +5953,7 @@ semantics.addOperation('examples', {
|
|
|
5964
5953
|
});
|
|
5965
5954
|
|
|
5966
5955
|
semantics.addOperation('grammarName', {
|
|
5967
|
-
Grammar(name, _, _open, exampleCommentsIter, ruleIter, _close) {
|
|
5956
|
+
Grammar(name, _, _open, exampleCommentsIter, ruleIter, trailingCommentsIter, _close) {
|
|
5968
5957
|
return name.sourceString;
|
|
5969
5958
|
},
|
|
5970
5959
|
});
|
|
@@ -5988,7 +5977,7 @@ semantics.addOperation('ruleName', {
|
|
|
5988
5977
|
* @return {[Example]}
|
|
5989
5978
|
*/
|
|
5990
5979
|
function extractExamples(grammarsDef) {
|
|
5991
|
-
const matchResult = grammars.OhmWithExamples.match(grammarsDef
|
|
5980
|
+
const matchResult = grammars.OhmWithExamples.match(grammarsDef);
|
|
5992
5981
|
if (matchResult.failed()) {
|
|
5993
5982
|
throw new Error(matchResult.message);
|
|
5994
5983
|
}
|
package/dist/ohm-extras.js
CHANGED
|
@@ -5847,13 +5847,7 @@
|
|
|
5847
5847
|
// Example:
|
|
5848
5848
|
//+ "//+ \"x\"\nG {\n//- \"\"\nstart = \"x\"}"
|
|
5849
5849
|
OhmWithExamples <: Ohm {
|
|
5850
|
-
|
|
5851
|
-
// When the start rule is a syntactic rule, there's no way to get access to
|
|
5852
|
-
// leading space (including comments). So, for this grammar to be useful,
|
|
5853
|
-
// you have to explicit use this rule as the start rule.
|
|
5854
|
-
grammarsWithExamples = (exampleComments applySyntactic<Grammar>)*
|
|
5855
|
-
|
|
5856
|
-
Grammar := ident SuperGrammar? "{" (#exampleComments Rule)* "}"
|
|
5850
|
+
Grammar := ident SuperGrammar? "{" (#exampleComments Rule)* #exampleComments "}"
|
|
5857
5851
|
|
|
5858
5852
|
exampleComments = (spacesNoExampleComment exampleComment)*
|
|
5859
5853
|
|
|
@@ -5917,19 +5911,10 @@
|
|
|
5917
5911
|
});
|
|
5918
5912
|
|
|
5919
5913
|
semantics.addOperation('examples', {
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
for (const [i, child] of Object.entries(grammarIter.children)) {
|
|
5923
|
-
if (exampleCommentsIter.hasExamples()) {
|
|
5924
|
-
const defaultExamples = exampleCommentsIter.child(i).examples();
|
|
5925
|
-
const grammar = child.grammarName();
|
|
5926
|
-
result.push(...defaultExamples.map(ex => ({...ex, grammar, rule: ''})));
|
|
5927
|
-
}
|
|
5928
|
-
result.push(...child.examples());
|
|
5929
|
-
}
|
|
5930
|
-
return result;
|
|
5914
|
+
Grammars(grammarIter) {
|
|
5915
|
+
return grammarIter.children.flatMap(c => c.examples());
|
|
5931
5916
|
},
|
|
5932
|
-
Grammar(name, _, _open, exampleCommentsIter, ruleIter, _close) {
|
|
5917
|
+
Grammar(name, _, _open, exampleCommentsIter, ruleIter, trailingCommentsIter, _close) {
|
|
5933
5918
|
const result = [];
|
|
5934
5919
|
const grammar = this.grammarName();
|
|
5935
5920
|
for (let i = 0; i < ruleIter.numChildren; i++) {
|
|
@@ -5941,6 +5926,10 @@
|
|
|
5941
5926
|
|
|
5942
5927
|
result.push(...augmentedExamples);
|
|
5943
5928
|
}
|
|
5929
|
+
if (trailingCommentsIter.hasExamples()) {
|
|
5930
|
+
const defaultExamples = trailingCommentsIter.examples();
|
|
5931
|
+
result.push(...defaultExamples.map(ex => ({...ex, grammar, rule: ''})));
|
|
5932
|
+
}
|
|
5944
5933
|
return result;
|
|
5945
5934
|
},
|
|
5946
5935
|
exampleComments(_, commentIter) {
|
|
@@ -5966,7 +5955,7 @@
|
|
|
5966
5955
|
});
|
|
5967
5956
|
|
|
5968
5957
|
semantics.addOperation('grammarName', {
|
|
5969
|
-
Grammar(name, _, _open, exampleCommentsIter, ruleIter, _close) {
|
|
5958
|
+
Grammar(name, _, _open, exampleCommentsIter, ruleIter, trailingCommentsIter, _close) {
|
|
5970
5959
|
return name.sourceString;
|
|
5971
5960
|
},
|
|
5972
5961
|
});
|
|
@@ -5990,7 +5979,7 @@
|
|
|
5990
5979
|
* @return {[Example]}
|
|
5991
5980
|
*/
|
|
5992
5981
|
function extractExamples(grammarsDef) {
|
|
5993
|
-
const matchResult = grammars.OhmWithExamples.match(grammarsDef
|
|
5982
|
+
const matchResult = grammars.OhmWithExamples.match(grammarsDef);
|
|
5994
5983
|
if (matchResult.failed()) {
|
|
5995
5984
|
throw new Error(matchResult.message);
|
|
5996
5985
|
}
|
package/dist/ohm.cjs
CHANGED