@@ -13,7 +13,8 @@ const reserved_none_blacketmode = [
13
13
] ;
14
14
15
15
const isNumber = ( c ) => "0123456789" . indexOf ( c ) >= 0 ;
16
- const isOperator = ( c ) => "+-*/%=!<>,.:" . indexOf ( c ) >= 0 ;
16
+ const isSymbol = ( c ) => "{}()[].:" . indexOf ( c ) >= 0 ;
17
+ const isOperator = ( c ) => "+-*/%=!<>," . indexOf ( c ) >= 0 ;
17
18
const isWhite = ( c ) => " \t\n" . indexOf ( c ) >= 0 ;
18
19
19
20
export class Parser {
@@ -93,7 +94,7 @@ export class Parser {
93
94
return { pos, type : "var" , name : "print" } ;
94
95
} else if ( c == "#" ) {
95
96
state = STATE_COMMENT ;
96
- } else if ( c == "{" || c == "}" || c == "(" || c == ")" || c == "[" || c == "]" ) {
97
+ } else if ( isSymbol ( c ) ) {
97
98
return { pos, type : c } ;
98
99
} else if ( c == '"' ) {
99
100
state = STATE_STRING ;
@@ -108,7 +109,7 @@ export class Parser {
108
109
state = STATE_WORD ;
109
110
}
110
111
} else if ( state == STATE_WORD ) {
111
- if ( c == " " || c == "\t" || c == "\n" || isOperator ( c ) || c == "(" || c == ")" || c == "[" || c == "]" || c === undefined ) {
112
+ if ( c == " " || c == "\t" || c == "\n" || isOperator ( c ) || isSymbol ( c ) || c === undefined ) {
112
113
this . p -- ;
113
114
const w = res . join ( "" ) ;
114
115
if ( this . reserved . indexOf ( w ) >= 0 ) {
@@ -281,7 +282,7 @@ export class Parser {
281
282
if ( t2 . type != "var" ) throw new Error ( "オブジェクトの定義には名前が必要です" ) ;
282
283
const name = t2 . name ;
283
284
const t4 = this . getToken ( ) ;
284
- if ( t4 . operator != ":" ) throw new Error ( "オブジェクトの定義は名前の後に : が必要です" ) ;
285
+ if ( t4 . type != ":" ) throw new Error ( "オブジェクトの定義は名前の後に : が必要です" ) ;
285
286
const value = this . getExpression ( ) ;
286
287
properties . push ( {
287
288
type : "Property" ,
@@ -449,14 +450,23 @@ export class Parser {
449
450
450
451
const array = [ ] ;
451
452
for ( ; ; ) {
452
- if ( op . type != "[" ) {
453
+ if ( op . type != "[" && op . type != "." ) {
453
454
this . backToken ( op ) ;
454
455
break ;
455
456
}
456
- const idx = this . getExpression ( ) ;
457
- const op2 = this . getToken ( ) ;
458
- if ( op2 . type != "]" ) throw new Error ( "配列の要素指定が ] で囲われていません" ) ;
459
- array . push ( idx ) ;
457
+ if ( op . type == "[" ) {
458
+ const idx = this . getExpression ( ) ;
459
+ const op2 = this . getToken ( ) ;
460
+ if ( op2 . type != "]" ) throw new Error ( "配列の要素指定が ] で囲われていません" ) ;
461
+ array . push ( idx ) ;
462
+ } else {
463
+ const id = this . getToken ( ) ;
464
+ if ( id . type != "var" ) throw new Error ( "オブジェクトの要素指定が名前ではありません" ) ;
465
+ array . push ( {
466
+ type : "Identifier" ,
467
+ name : id . name ,
468
+ } ) ;
469
+ }
460
470
op = this . getToken ( ) ;
461
471
}
462
472
if ( array . length == 0 ) {
0 commit comments