File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -26,8 +26,11 @@ const arithmetic = ohm.grammar(`
2626// eslint-disable-next-line ava/no-skip-test
2727test ( '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 ,
You can’t perform that action at this time.
0 commit comments