@@ -62,6 +62,18 @@ infix('[', 80, function(left) {
62
62
this . type = 'binary'
63
63
return this
64
64
} )
65
+ infix ( '(' , 80 , function ( left ) {
66
+ this . children = [ left ]
67
+ this . type = 'call'
68
+
69
+ if ( token . data !== ')' ) while ( 1 ) {
70
+ this . children . push ( expression ( 0 ) )
71
+ if ( token . data !== ',' ) break
72
+ advance ( ',' )
73
+ }
74
+ advance ( ')' )
75
+ return this
76
+ } )
65
77
66
78
prefix ( '-' )
67
79
prefix ( '+' )
@@ -90,21 +102,23 @@ assignment('^=')
90
102
assignment ( '>>=' )
91
103
assignment ( '<<=' )
92
104
93
-
94
-
95
105
module . exports = function ( incoming_state , incoming_tokens ) {
96
106
state = incoming_state
97
107
tokens = incoming_tokens
98
108
idx = 0
109
+ var result
99
110
100
111
if ( ! tokens . length ) return
101
112
102
113
advance ( )
103
- var result = expression ( 0 )
104
-
114
+ result = expression ( 0 )
105
115
result . parent = state [ 0 ]
106
116
emit ( result )
107
117
118
+ if ( idx < tokens . length ) throw new Error ( 'did not use all tokens' )
119
+
120
+ result . parent . children = [ result ]
121
+
108
122
function emit ( node ) {
109
123
state . unshift ( node , false )
110
124
for ( var i = 0 , len = node . children . length ; i < len ; ++ i ) {
@@ -118,8 +132,10 @@ module.exports = function(incoming_state, incoming_tokens) {
118
132
function symbol ( id , binding_power ) {
119
133
var sym = symbol_table [ id ]
120
134
binding_power = binding_power || 0
121
- if ( sym && binding_power > sym . lbp ) {
122
- sym . lbp = binding_power
135
+ if ( sym ) {
136
+ if ( binding_power > sym . lbp ) {
137
+ sym . lbp = binding_power
138
+ }
123
139
} else {
124
140
sym = Object . create ( original_symbol )
125
141
sym . id = id
@@ -183,7 +199,7 @@ function assignment(id) {
183
199
return infixr ( id , 10 , function ( left ) {
184
200
this . children = [ left , expression ( 9 ) ]
185
201
this . assignment = true
186
- this . type = 'type '
202
+ this . type = 'assign '
187
203
return this
188
204
} )
189
205
}
@@ -195,7 +211,7 @@ function advance(id) {
195
211
, output
196
212
197
213
if ( id && token . data !== id ) {
198
- return state . unexpected ( 'expected `' + id + '`' )
214
+ return state . unexpected ( 'expected `' + id + '`, got `' + token . data + '` ')
199
215
}
200
216
201
217
if ( idx >= tokens . length ) {
@@ -233,7 +249,7 @@ function advance(id) {
233
249
output = Object . create ( output )
234
250
output . token = next
235
251
output . type = type
236
- output . value = value
252
+ if ( ! output . data ) output . data = value
237
253
238
254
return token = output
239
255
}
0 commit comments