@@ -91,6 +91,20 @@ module.exports = function(api, tokens, EOF) {
91
91
this . expectEndOfStatement ( ) ;
92
92
return [ 'const' , result ] ;
93
93
}
94
+ /**
95
+ * Reads a list of constants declaration
96
+ * <ebnf>
97
+ * const_list ::= T_CONST T_STRING '=' expr (',' T_STRING '=' expr)*
98
+ * </ebnf>
99
+ */
100
+ , read_declare_list : function ( ) {
101
+ return this . read_list ( function ( ) {
102
+ this . expect ( tokens . T_STRING ) ;
103
+ var name = this . text ( ) ;
104
+ this . next ( ) . expect ( '=' ) . next ( ) ;
105
+ return [ name , this . read_expr ( ) ] ;
106
+ } , ',' ) ;
107
+ }
94
108
/**
95
109
* reads a simple inner statement
96
110
* <ebnf>
@@ -202,11 +216,12 @@ module.exports = function(api, tokens, EOF) {
202
216
return [ 'sys' , 'unset' , items ] ;
203
217
204
218
case tokens . T_DECLARE :
219
+ var result = this . node ( 'declare' ) ;
205
220
this . next ( ) . expect ( '(' ) . next ( ) ;
206
- var options = this . read_list ( this . read_const_list , ',' ) ;
221
+ var options = this . read_declare_list ( ) ;
207
222
this . expect ( ')' ) . next ( ) ;
208
223
var body = this . read_statement ( ) ;
209
- return [ 'declare' , options , body ]
224
+ return result ( options , body ) ;
210
225
break ;
211
226
212
227
case tokens . T_TRY :
@@ -225,8 +240,9 @@ module.exports = function(api, tokens, EOF) {
225
240
case tokens . T_STRING :
226
241
var label = this . text ( ) ;
227
242
if ( this . next ( ) . token === ':' ) {
243
+ var result = this . node ( 'label' ) ;
228
244
this . next ( ) ;
229
- return [ ' label' , label ] ;
245
+ return result ( label ) ;
230
246
} else {
231
247
// default fallback expr
232
248
this . lexer . unput ( label . length + this . text ( ) . length ) ;
@@ -236,9 +252,10 @@ module.exports = function(api, tokens, EOF) {
236
252
}
237
253
238
254
case tokens . T_GOTO :
255
+ var result = this . node ( 'goto' ) ;
239
256
var label = this . next ( ) . expect ( tokens . T_STRING ) . text ( ) ;
240
257
this . next ( ) . expectEndOfStatement ( ) ;
241
- return [ 'goto' , label ] ;
258
+ return result ( label ) ;
242
259
243
260
default : // default fallback expr
244
261
var expr = this . read_expr ( ) ;
0 commit comments