Skip to content

Commit 6f2f498

Browse files
authored
fix: grammars containing super-splice not working in editor (#370)
1 parent 1a518b2 commit 6f2f498

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/ohm-js/src/MatchState.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ MatchState.prototype = {
219219
// Returns the memoized trace entry for `expr` at `pos`, if one exists, `null` otherwise.
220220
getMemoizedTraceEntry(pos, expr) {
221221
const posInfo = this.memoTable[pos];
222-
if (posInfo && expr.ruleName) {
222+
if (posInfo && expr instanceof pexprs.Apply) {
223223
const memoRec = posInfo.memo[expr.toMemoKey()];
224224
if (memoRec && memoRec.traceEntry) {
225225
const entry = memoRec.traceEntry.cloneWithExpr(expr);

packages/ohm-js/test/test-tracing.js

+11
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,14 @@ test.failing('bindings', t => {
480480
const notX = alt.children[1];
481481
t.deepEqual(notX.children.map(succeeded), [true, true], 'both children succeeded');
482482
});
483+
484+
// https://github.com/harc/ohm-editor/issues/72
485+
test('tracing with "..."', t => {
486+
const g = ohm.grammar('G { letter := "@" | ... }');
487+
const trace = g.trace('x', 'letter');
488+
const splice = trace.children[0].children[0];
489+
t.is(splice.expr.constructor, ohm.pexprs.Splice);
490+
t.is(splice.displayString, '"@" | ...');
491+
const alt = splice.children[1];
492+
t.is(alt.expr.constructor, ohm.pexprs.Alt);
493+
});

0 commit comments

Comments
 (0)