1
1
'use strict' ;
2
2
3
- // --------------------------------------------------------------------
4
- // Imports
5
- // --------------------------------------------------------------------
6
-
7
- const pexprs = require ( '../src/pexprs' ) ;
8
- const MatchResult = require ( '../src/MatchResult' ) ;
9
- const Grammar = require ( '../src/Grammar' ) ;
10
-
11
3
// --------------------------------------------------------------------
12
4
// Operations
13
5
// --------------------------------------------------------------------
@@ -23,11 +15,6 @@ const defaultOperation = {
23
15
24
16
// without customization
25
17
if ( ! Object . prototype . hasOwnProperty . call ( mapping , ctorName ) ) {
26
- // intermediate node
27
- if ( this . _node instanceof pexprs . Alt || this . _node instanceof pexprs . Apply ) {
28
- return children [ 0 ] . toAST ( mapping ) ;
29
- }
30
-
31
18
// lexical rule
32
19
if ( this . isLexical ( ) ) {
33
20
return this . sourceString ;
@@ -111,8 +98,8 @@ const defaultOperation = {
111
98
// The optional `mapping` parameter can be used to customize how the nodes of the CST
112
99
// are mapped to the AST (see /doc/extras.md#toastmatchresult-mapping).
113
100
function toAST ( res , mapping ) {
114
- if ( ! ( res instanceof MatchResult ) || res . failed ( ) ) {
115
- throw new Error ( 'toAST() expects a succesfull MatchResult as first parameter' ) ;
101
+ if ( typeof res . failed !== 'function' || res . failed ( ) ) {
102
+ throw new Error ( 'toAST() expects a succesful MatchResult as first parameter' ) ;
116
103
}
117
104
118
105
mapping = Object . assign ( { } , mapping ) ;
@@ -130,7 +117,7 @@ function toAST(res, mapping) {
130
117
131
118
// Returns a semantics containg the toAST(mapping) operation for the given grammar g.
132
119
function semanticsForToAST ( g ) {
133
- if ( ! ( g instanceof Grammar ) ) {
120
+ if ( typeof g . createSemantics !== 'function' ) {
134
121
throw new Error ( 'semanticsToAST() expects a Grammar as parameter' ) ;
135
122
}
136
123
0 commit comments