Skip to content

Commit dad65af

Browse files
committed
wasm: Change toAST to have the same interface as the original
1 parent db98667 commit dad65af

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/miniohm-js/toAST.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Visitor {
133133
// for the given match result `res` containg a concrete syntax tree (CST) and grammar.
134134
// The optional `mapping` parameter can be used to customize how the nodes of the CST
135135
// are mapped to the AST (see /doc/extras.md#toastmatchresult-mapping).
136-
export function toAST(matcher, mapping) {
136+
export function toAST(result, mapping) {
137137
mapping = Object.assign({}, defaultMapping, mapping);
138138
// pd: Unclear if/how this is actually being used?
139139
// const operation = Object.assign({}, defaultOperation);
@@ -143,5 +143,5 @@ export function toAST(matcher, mapping) {
143143
// delete mapping[termName];
144144
// }
145145
// }
146-
return new Visitor(mapping).visit(matcher.getCstRoot(), 0);
146+
return new Visitor(mapping).visit(result._cst, 0);
147147
}

packages/wasm/test/test-toAST.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ const arithmetic = ohm.grammar(`
2626
// eslint-disable-next-line ava/no-skip-test
2727
test('toAST basic', async t => {
2828
const m = await wasmMatcherForGrammar(arithmetic);
29-
t.is(matchWithInput(m, '10 + 20'), 1);
30-
const ast = toAST(m, {
29+
const match = str => (m.setInput(str), m.match(str));
30+
31+
const r = match('10 + 20');
32+
t.true(r.succeeded());
33+
const ast = toAST(r, {
3134
AddExp_plus: {
3235
expr1: 0,
3336
expr2: 2,

0 commit comments

Comments
 (0)