@@ -191,6 +191,23 @@ function viml_stridx(a, b) {
191
191
return a . indexOf ( b ) ;
192
192
}
193
193
194
+ function viml_type ( obj ) {
195
+ if ( typeof obj == 'number' && Math . round ( obj ) == obj ) {
196
+ return 0 ;
197
+ } else if ( typeof obj == 'string' ) {
198
+ return 1 ;
199
+ } else if ( typeof obj == 'function' ) {
200
+ return 2 ;
201
+ } else if ( obj instanceof Array ) {
202
+ return 3 ;
203
+ } else if ( obj instanceof Object ) {
204
+ return 4 ;
205
+ } else if ( typeof obj == 'number' ) {
206
+ return 5 ;
207
+ }
208
+ throw 'Unknown Type' ;
209
+ }
210
+
194
211
var NIL = [ ] ;
195
212
var NODE_TOPLEVEL = 1 ;
196
213
var NODE_COMMENT = 2 ;
@@ -380,10 +397,6 @@ function isnamec1(c) {
380
397
return viml_eqregh ( c , "^[A-Za-z_]$" ) ;
381
398
}
382
399
383
- function isattrc ( c ) {
384
- return viml_eqregh ( c , "^[0-9A-Za-z_]$" ) ;
385
- }
386
-
387
400
function isargname ( s ) {
388
401
return viml_eqregh ( s , "^[A-Za-z_][0-9A-Za-z_]*$" ) ;
389
402
}
@@ -2862,14 +2875,12 @@ ExprParser.prototype.parse_expr8 = function() {
2862
2875
}
2863
2876
var left = node ;
2864
2877
}
2865
- else if ( ! iswhite ( c ) && token . type == TOKEN_DOT && isattrc ( this . reader . p ( 0 ) ) && ( left . type == NODE_IDENTIFIER || left . type == NODE_CURLYNAME || left . type == NODE_DICT || left . type == NODE_SUBSCRIPT || left . type == NODE_CALL || left . type == NODE_DOT ) ) {
2866
- // SUBSCRIPT or CONCAT
2867
- var node = Node ( NODE_DOT ) ;
2868
- node . pos = token . pos ;
2869
- node . left = left ;
2870
- node . right = Node ( NODE_IDENTIFIER ) ;
2871
- node . right . pos = this . reader . getpos ( ) ;
2872
- node . right . value = this . reader . read_attr ( ) ;
2878
+ else if ( ! iswhite ( c ) && token . type == TOKEN_DOT ) {
2879
+ var node = this . parse_dot ( token , left ) ;
2880
+ if ( node === NIL ) {
2881
+ this . reader . seek_set ( pos ) ;
2882
+ break ;
2883
+ }
2873
2884
var left = node ;
2874
2885
}
2875
2886
else {
@@ -3023,6 +3034,31 @@ ExprParser.prototype.parse_expr9 = function() {
3023
3034
return node ;
3024
3035
}
3025
3036
3037
+ // SUBSCRIPT or CONCAT
3038
+ // dict "." [0-9A-Za-z_]+ => (subscript dict key)
3039
+ // str "." expr6 => (concat str expr6)
3040
+ ExprParser . prototype . parse_dot = function ( token , left ) {
3041
+ if ( left . type != NODE_IDENTIFIER && left . type != NODE_CURLYNAME && left . type != NODE_DICT && left . type != NODE_SUBSCRIPT && left . type != NODE_CALL && left . type != NODE_DOT ) {
3042
+ return NIL ;
3043
+ }
3044
+ if ( ! iswordc ( this . reader . p ( 0 ) ) ) {
3045
+ return NIL ;
3046
+ }
3047
+ var pos = this . reader . getpos ( ) ;
3048
+ var name = this . reader . read_word ( ) ;
3049
+ if ( isnamec ( this . reader . p ( 0 ) ) ) {
3050
+ // foo.s:bar or foo.bar#baz
3051
+ return NIL ;
3052
+ }
3053
+ var node = Node ( NODE_DOT ) ;
3054
+ node . pos = token . pos ;
3055
+ node . left = left ;
3056
+ node . right = Node ( NODE_IDENTIFIER ) ;
3057
+ node . right . pos = pos ;
3058
+ node . right . value = name ;
3059
+ return node ;
3060
+ }
3061
+
3026
3062
ExprParser . prototype . parse_identifier = function ( ) {
3027
3063
var id = [ ] ;
3028
3064
this . reader . skip_white ( ) ;
@@ -3128,14 +3164,12 @@ LvalueParser.prototype.parse_lv8 = function() {
3128
3164
}
3129
3165
var left = node ;
3130
3166
}
3131
- else if ( ! iswhite ( c ) && token . type == TOKEN_DOT && isattrc ( this . reader . p ( 0 ) ) && ( left . type == NODE_IDENTIFIER || left . type == NODE_CURLYNAME || left . type == NODE_DICT || left . type == NODE_SUBSCRIPT || left . type == NODE_CALL || left . type == NODE_DOT ) ) {
3132
- // SUBSCRIPT or CONCAT
3133
- var node = Node ( NODE_DOT ) ;
3134
- node . pos = token . pos ;
3135
- node . left = left ;
3136
- node . right = Node ( NODE_IDENTIFIER ) ;
3137
- node . right . pos = this . reader . getpos ( ) ;
3138
- node . right . value = this . reader . read_attr ( ) ;
3167
+ else if ( ! iswhite ( c ) && token . type == TOKEN_DOT ) {
3168
+ var node = this . parse_dot ( token , left ) ;
3169
+ if ( node === NIL ) {
3170
+ this . reader . seek_set ( pos ) ;
3171
+ break ;
3172
+ }
3139
3173
var left = node ;
3140
3174
}
3141
3175
else {
@@ -3190,7 +3224,7 @@ LvalueParser.prototype.parse_lv9 = function() {
3190
3224
3191
3225
function StringReader ( ) { this . __init__ . apply ( this , arguments ) ; }
3192
3226
StringReader . prototype . __init__ = function ( lines ) {
3193
- this . lines = lines ;
3227
+ var lines = viml_type ( lines ) == 3 ? lines : [ lines ] ;
3194
3228
this . buf = [ ] ;
3195
3229
this . pos = [ ] ;
3196
3230
var lnum = 0 ;
@@ -3406,14 +3440,6 @@ StringReader.prototype.read_name = function() {
3406
3440
return r ;
3407
3441
}
3408
3442
3409
- StringReader . prototype . read_attr = function ( ) {
3410
- var r = "" ;
3411
- while ( isattrc ( this . peekn ( 1 ) ) ) {
3412
- r += this . getn ( 1 ) ;
3413
- }
3414
- return r ;
3415
- }
3416
-
3417
3443
StringReader . prototype . skip_white = function ( ) {
3418
3444
while ( iswhite ( this . peekn ( 1 ) ) ) {
3419
3445
this . seek_cur ( 1 ) ;
0 commit comments