@@ -302,6 +302,8 @@ var NODE_IDENTIFIER = 86;
302
302
var NODE_CURLYNAME = 87 ;
303
303
var NODE_ENV = 88 ;
304
304
var NODE_REG = 89 ;
305
+ var NODE_CURLYNAMEPART = 90 ;
306
+ var NODE_CURLYNAMEEXPR = 91 ;
305
307
var TOKEN_EOF = 1 ;
306
308
var TOKEN_EOL = 2 ;
307
309
var TOKEN_SPACE = 3 ;
@@ -561,6 +563,8 @@ function ExArg() {
561
563
// CURLYNAME .value
562
564
// ENV .value
563
565
// REG .value
566
+ // CURLYNAMEPART .value
567
+ // CURLYNAMEEXPR .value
564
568
function Node ( type ) {
565
569
return { "type" :type } ;
566
570
}
@@ -3101,46 +3105,68 @@ ExprParser.prototype.parse_dot = function(token, left) {
3101
3105
}
3102
3106
3103
3107
ExprParser . prototype . parse_identifier = function ( ) {
3104
- var id = [ ] ;
3105
3108
this . reader . skip_white ( ) ;
3106
3109
var npos = this . reader . getpos ( ) ;
3110
+ var curly_parts = this . parse_curly_parts ( ) ;
3111
+ if ( viml_len ( curly_parts ) == 1 && curly_parts [ 0 ] . type == NODE_CURLYNAMEPART ) {
3112
+ var node = Node ( NODE_IDENTIFIER ) ;
3113
+ node . pos = npos ;
3114
+ node . value = curly_parts [ 0 ] . value ;
3115
+ }
3116
+ else {
3117
+ var node = Node ( NODE_CURLYNAME ) ;
3118
+ node . pos = npos ;
3119
+ node . value = curly_parts ;
3120
+ }
3121
+ return node ;
3122
+ }
3123
+
3124
+ ExprParser . prototype . parse_curly_parts = function ( ) {
3125
+ var curly_parts = [ ] ;
3107
3126
var c = this . reader . peek ( ) ;
3127
+ var pos = this . reader . getpos ( ) ;
3108
3128
if ( c == "<" && viml_equalci ( this . reader . peekn ( 5 ) , "<SID>" ) ) {
3109
3129
var name = this . reader . getn ( 5 ) ;
3110
- viml_add ( id , { "curly" :0 , "value" :name } ) ;
3130
+ var node = Node ( NODE_CURLYNAMEPART ) ;
3131
+ node . curly = 0 ;
3132
+ // Keep backword compatibility for the curly attribute
3133
+ node . pos = pos ;
3134
+ node . value = name ;
3135
+ viml_add ( curly_parts , node ) ;
3111
3136
}
3112
3137
while ( 1 ) {
3113
3138
var c = this . reader . peek ( ) ;
3114
3139
if ( isnamec ( c ) ) {
3140
+ var pos = this . reader . getpos ( ) ;
3115
3141
var name = this . reader . read_name ( ) ;
3116
- viml_add ( id , { "curly" :0 , "value" :name } ) ;
3142
+ var node = Node ( NODE_CURLYNAMEPART ) ;
3143
+ node . curly = 0 ;
3144
+ // Keep backword compatibility for the curly attribute
3145
+ node . pos = pos ;
3146
+ node . value = name ;
3147
+ viml_add ( curly_parts , node ) ;
3117
3148
}
3118
3149
else if ( c == "{" ) {
3119
3150
this . reader . get ( ) ;
3120
- var node = this . parse_expr1 ( ) ;
3151
+ var pos = this . reader . getpos ( ) ;
3152
+ var node = Node ( NODE_CURLYNAMEEXPR ) ;
3153
+ node . curly = 1 ;
3154
+ // Keep backword compatibility for the curly attribute
3155
+ node . pos = pos ;
3156
+ node . value = this . parse_expr1 ( ) ;
3157
+ viml_add ( curly_parts , node ) ;
3121
3158
this . reader . skip_white ( ) ;
3122
3159
var c = this . reader . p ( 0 ) ;
3123
3160
if ( c != "}" ) {
3124
3161
throw Err ( viml_printf ( "unexpected token: %s" , c ) , this . reader . getpos ( ) ) ;
3125
3162
}
3126
3163
this . reader . seek_cur ( 1 ) ;
3127
- viml_add ( id , { "curly" :1 , "value" :node } ) ;
3128
3164
}
3129
3165
else {
3130
3166
break ;
3131
3167
}
3132
3168
}
3133
- if ( viml_len ( id ) == 1 && id [ 0 ] . curly == 0 ) {
3134
- var node = Node ( NODE_IDENTIFIER ) ;
3135
- node . pos = npos ;
3136
- node . value = id [ 0 ] . value ;
3137
- }
3138
- else {
3139
- var node = Node ( NODE_CURLYNAME ) ;
3140
- node . pos = npos ;
3141
- node . value = id ;
3142
- }
3143
- return node ;
3169
+ return curly_parts ;
3144
3170
}
3145
3171
3146
3172
function LvalueParser ( ) { ExprParser . apply ( this , arguments ) ; this . __init__ . apply ( this , arguments ) ; }
@@ -3772,6 +3798,12 @@ Compiler.prototype.compile = function(node) {
3772
3798
else if ( node . type == NODE_REG ) {
3773
3799
return this . compile_reg ( node ) ;
3774
3800
}
3801
+ else if ( node . type == NODE_CURLYNAMEPART ) {
3802
+ return this . compile_curlynamepart ( node ) ;
3803
+ }
3804
+ else if ( node . type == NODE_CURLYNAMEEXPR ) {
3805
+ return this . compile_curlynameexpr ( node ) ;
3806
+ }
3775
3807
else {
3776
3808
throw viml_printf ( "Compiler: unknown node: %s" , viml_string ( node ) ) ;
3777
3809
}
@@ -4224,18 +4256,7 @@ Compiler.prototype.compile_identifier = function(node) {
4224
4256
}
4225
4257
4226
4258
Compiler . prototype . compile_curlyname = function ( node ) {
4227
- var name = "" ;
4228
- var __c11 = node . value ;
4229
- for ( var __i11 = 0 ; __i11 < __c11 . length ; ++ __i11 ) {
4230
- var x = __c11 [ __i11 ] ;
4231
- if ( x . curly ) {
4232
- name += "{" + this . compile ( x . value ) + "}" ;
4233
- }
4234
- else {
4235
- name += x . value ;
4236
- }
4237
- }
4238
- return name ;
4259
+ return viml_join ( node . value . map ( ( function ( vval ) { return this . compile ( vval ) ; } ) . bind ( this ) ) , "" ) ;
4239
4260
}
4240
4261
4241
4262
Compiler . prototype . compile_env = function ( node ) {
@@ -4246,6 +4267,14 @@ Compiler.prototype.compile_reg = function(node) {
4246
4267
return node . value ;
4247
4268
}
4248
4269
4270
+ Compiler . prototype . compile_curlynamepart = function ( node ) {
4271
+ return node . value ;
4272
+ }
4273
+
4274
+ Compiler . prototype . compile_curlynameexpr = function ( node ) {
4275
+ return "{" + this . compile ( node . value ) + "}" ;
4276
+ }
4277
+
4249
4278
// TODO: under construction
4250
4279
function RegexpParser ( ) { this . __init__ . apply ( this , arguments ) ; }
4251
4280
RegexpParser . prototype . RE_VERY_NOMAGIC = 1 ;
@@ -4926,9 +4955,9 @@ RegexpParser.prototype.get_token_sq_char_class = function() {
4926
4955
var r = this . reader . read_alpha ( ) ;
4927
4956
if ( this . reader . p ( 0 ) == ":" && this . reader . p ( 1 ) == "]" ) {
4928
4957
this . reader . seek_cur ( 2 ) ;
4929
- var __c12 = class_names ;
4930
- for ( var __i12 = 0 ; __i12 < __c12 . length ; ++ __i12 ) {
4931
- var name = __c12 [ __i12 ] ;
4958
+ var __c11 = class_names ;
4959
+ for ( var __i11 = 0 ; __i11 < __c11 . length ; ++ __i11 ) {
4960
+ var name = __c11 [ __i11 ] ;
4932
4961
if ( r == name ) {
4933
4962
return "[:" + name + ":]" ;
4934
4963
}
@@ -5061,9 +5090,9 @@ RegexpParser.prototype.getoctchrs = function() {
5061
5090
5062
5091
RegexpParser . prototype . gethexchrs = function ( n ) {
5063
5092
var r = "" ;
5064
- var __c13 = viml_range ( n ) ;
5065
- for ( var __i13 = 0 ; __i13 < __c13 . length ; ++ __i13 ) {
5066
- var i = __c13 [ __i13 ] ;
5093
+ var __c12 = viml_range ( n ) ;
5094
+ for ( var __i12 = 0 ; __i12 < __c12 . length ; ++ __i12 ) {
5095
+ var i = __c12 [ __i12 ] ;
5067
5096
var c = this . reader . peek ( ) ;
5068
5097
if ( ! isxdigit ( c ) ) {
5069
5098
break ;
0 commit comments