Skip to content

Commit

Permalink
fix: grammars containing super-splice not working in editor (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdubroy authored Mar 23, 2022
1 parent 1a518b2 commit 6f2f498
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ohm-js/src/MatchState.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ MatchState.prototype = {
// Returns the memoized trace entry for `expr` at `pos`, if one exists, `null` otherwise.
getMemoizedTraceEntry(pos, expr) {
const posInfo = this.memoTable[pos];
if (posInfo && expr.ruleName) {
if (posInfo && expr instanceof pexprs.Apply) {
const memoRec = posInfo.memo[expr.toMemoKey()];
if (memoRec && memoRec.traceEntry) {
const entry = memoRec.traceEntry.cloneWithExpr(expr);
Expand Down
11 changes: 11 additions & 0 deletions packages/ohm-js/test/test-tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,14 @@ test.failing('bindings', t => {
const notX = alt.children[1];
t.deepEqual(notX.children.map(succeeded), [true, true], 'both children succeeded');
});

// https://github.com/harc/ohm-editor/issues/72
test('tracing with "..."', t => {
const g = ohm.grammar('G { letter := "@" | ... }');
const trace = g.trace('x', 'letter');
const splice = trace.children[0].children[0];
t.is(splice.expr.constructor, ohm.pexprs.Splice);
t.is(splice.displayString, '"@" | ...');
const alt = splice.children[1];
t.is(alt.expr.constructor, ohm.pexprs.Alt);
});

0 comments on commit 6f2f498

Please sign in to comment.