Skip to content

Commit 55f97af

Browse files
authored
Merge pull request #55 from haya14busa/add-scope-hack-for-compiler
Add scope hack for compiler
2 parents a48032a + a76da1c commit 55f97af

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

autoload/vimlparser.vim

+16-6
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,10 @@ function! s:VimLParser.parse_command_modifiers()
530530
let modifiers = []
531531
while s:TRUE
532532
let pos = self.reader.tell()
533+
let d = ''
533534
if s:isdigit(self.reader.peekn(1))
534535
let d = self.reader.read_digit()
535536
call self.reader.skip_white()
536-
else
537-
let d = ''
538537
endif
539538
let k = self.reader.read_alpha()
540539
let c = self.reader.peekn(1)
@@ -900,6 +899,7 @@ endfunction
900899

901900
function! s:VimLParser.find_command()
902901
let c = self.reader.peekn(1)
902+
let name = ''
903903

904904
if c ==# 'k'
905905
call self.reader.getn(1)
@@ -1087,6 +1087,7 @@ endfunction
10871087

10881088
" TODO:
10891089
function! s:VimLParser.parse_cmd_common()
1090+
let end = self.reader.getpos()
10901091
if self.ea.cmd.flags =~# '\<TRLBAR\>' && !self.ea.usefilter
10911092
let end = self.separate_nextcmd()
10921093
elseif self.ea.cmd.name ==# '!' || self.ea.cmd.name ==# 'global' || self.ea.cmd.name ==# 'vglobal' || self.ea.usefilter
@@ -1232,6 +1233,7 @@ function! s:VimLParser.parse_cmd_loadkeymap()
12321233
endfunction
12331234

12341235
function! s:VimLParser.parse_cmd_lua()
1236+
let lines = []
12351237
call self.reader.skip_white()
12361238
if self.reader.peekn(2) ==# '<<'
12371239
call self.reader.getn(2)
@@ -1352,6 +1354,7 @@ function! s:VimLParser.parse_cmd_function()
13521354
else
13531355
let named = {}
13541356
while s:TRUE
1357+
let varnode = s:Node(s:NODE_IDENTIFIER)
13551358
let token = tokenizer.get()
13561359
if token.type == s:TOKEN_IDENTIFIER
13571360
if !s:isargname(token.value) || token.value ==# 'firstline' || token.value ==# 'lastline'
@@ -1360,7 +1363,6 @@ function! s:VimLParser.parse_cmd_function()
13601363
throw s:Err(printf('E853: Duplicate argument name: %s', token.value), token.pos)
13611364
endif
13621365
let named[token.value] = 1
1363-
let varnode = s:Node(s:NODE_IDENTIFIER)
13641366
let varnode.pos = token.pos
13651367
let varnode.value = token.value
13661368
call add(node.rlist, varnode)
@@ -1381,7 +1383,6 @@ function! s:VimLParser.parse_cmd_function()
13811383
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
13821384
endif
13831385
elseif token.type == s:TOKEN_DOTDOTDOT
1384-
let varnode = s:Node(s:NODE_IDENTIFIER)
13851386
let varnode.pos = token.pos
13861387
let varnode.value = token.value
13871388
call add(node.rlist, varnode)
@@ -2770,6 +2771,7 @@ function! s:ExprTokenizer.get2()
27702771
" @<EOL> is treated as @"
27712772
return self.token(s:TOKEN_REG, r.getn(2), pos)
27722773
elseif c ==# '&'
2774+
let s = ''
27732775
if (r.p(1) ==# 'g' || r.p(1) ==# 'l') && r.p(2) ==# ':'
27742776
let s = r.getn(3) . r.read_word()
27752777
else
@@ -3256,6 +3258,7 @@ function! s:ExprParser.parse_expr8()
32563258
if token.type != s:TOKEN_SQCLOSE
32573259
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
32583260
endif
3261+
let left = node
32593262
else
32603263
let right = self.parse_expr1()
32613264
if self.tokenizer.peek().type == s:TOKEN_COLON
@@ -3272,6 +3275,7 @@ function! s:ExprParser.parse_expr8()
32723275
if token.type != s:TOKEN_SQCLOSE
32733276
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
32743277
endif
3278+
let left = node
32753279
else
32763280
let node = s:Node(s:NODE_SUBSCRIPT)
32773281
let node.pos = npos
@@ -3281,9 +3285,9 @@ function! s:ExprParser.parse_expr8()
32813285
if token.type != s:TOKEN_SQCLOSE
32823286
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
32833287
endif
3288+
let left = node
32843289
endif
32853290
endif
3286-
let left = node
32873291
unlet node
32883292
elseif token.type == s:TOKEN_POPEN
32893293
let node = s:Node(s:NODE_CALL)
@@ -3348,6 +3352,7 @@ endfunction
33483352
function! s:ExprParser.parse_expr9()
33493353
let pos = self.reader.tell()
33503354
let token = self.tokenizer.get()
3355+
let node = s:Node(-1)
33513356
if token.type == s:TOKEN_NUMBER
33523357
let node = s:Node(s:NODE_NUMBER)
33533358
let node.pos = token.pos
@@ -3574,12 +3579,13 @@ function! s:ExprParser.parse_identifier()
35743579
let node = s:Node(s:NODE_IDENTIFIER)
35753580
let node.pos = npos
35763581
let node.value = curly_parts[0].value
3582+
return node
35773583
else
35783584
let node = s:Node(s:NODE_CURLYNAME)
35793585
let node.pos = npos
35803586
let node.value = curly_parts
3581-
endif
35823587
return node
3588+
endif
35833589
endfunction
35843590

35853591
function! s:ExprParser.parse_curly_parts()
@@ -3642,6 +3648,7 @@ function! s:LvalueParser.parse_lv8()
36423648
let token = self.tokenizer.get()
36433649
if !s:iswhite(c) && token.type == s:TOKEN_SQOPEN
36443650
let npos = token.pos
3651+
let node = s:Node(-1)
36453652
if self.tokenizer.peek().type == s:TOKEN_COLON
36463653
call self.tokenizer.get()
36473654
let node = s:Node(s:NODE_SLICE)
@@ -3709,6 +3716,7 @@ endfunction
37093716
function! s:LvalueParser.parse_lv9()
37103717
let pos = self.reader.tell()
37113718
let token = self.tokenizer.get()
3719+
let node = s:Node(-1)
37123720
if token.type == s:TOKEN_COPEN
37133721
call self.reader.seek_set(pos)
37143722
let node = self.parse_identifier()
@@ -4232,6 +4240,7 @@ function! s:Compiler.compile_excall(node)
42324240
endfunction
42334241

42344242
function! s:Compiler.compile_let(node)
4243+
let left = ''
42354244
if a:node.left isnot s:NIL
42364245
let left = self.compile(a:node.left)
42374246
else
@@ -4299,6 +4308,7 @@ function! s:Compiler.compile_while(node)
42994308
endfunction
43004309

43014310
function! s:Compiler.compile_for(node)
4311+
let left = ''
43024312
if a:node.left isnot s:NIL
43034313
let left = self.compile(a:node.left)
43044314
else

js/vimlparser.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,11 @@ VimLParser.prototype.parse_command_modifiers = function() {
709709
var modifiers = [];
710710
while (TRUE) {
711711
var pos = this.reader.tell();
712+
var d = "";
712713
if (isdigit(this.reader.peekn(1))) {
713714
var d = this.reader.read_digit();
714715
this.reader.skip_white();
715716
}
716-
else {
717-
var d = "";
718-
}
719717
var k = this.reader.read_alpha();
720718
var c = this.reader.peekn(1);
721719
this.reader.skip_white();
@@ -1168,6 +1166,7 @@ VimLParser.prototype._parse_command = function(parser) {
11681166

11691167
VimLParser.prototype.find_command = function() {
11701168
var c = this.reader.peekn(1);
1169+
var name = "";
11711170
if (c == "k") {
11721171
this.reader.getn(1);
11731172
var name = "k";
@@ -1371,6 +1370,7 @@ VimLParser.prototype.parse_cmd_modifier_range = function() {
13711370

13721371
// TODO:
13731372
VimLParser.prototype.parse_cmd_common = function() {
1373+
var end = this.reader.getpos();
13741374
if (viml_eqregh(this.ea.cmd.flags, "\\<TRLBAR\\>") && !this.ea.usefilter) {
13751375
var end = this.separate_nextcmd();
13761376
}
@@ -1524,6 +1524,7 @@ VimLParser.prototype.parse_cmd_loadkeymap = function() {
15241524
}
15251525

15261526
VimLParser.prototype.parse_cmd_lua = function() {
1527+
var lines = [];
15271528
this.reader.skip_white();
15281529
if (this.reader.peekn(2) == "<<") {
15291530
this.reader.getn(2);
@@ -1640,6 +1641,7 @@ VimLParser.prototype.parse_cmd_function = function() {
16401641
else {
16411642
var named = {};
16421643
while (TRUE) {
1644+
var varnode = Node(NODE_IDENTIFIER);
16431645
var token = tokenizer.get();
16441646
if (token.type == TOKEN_IDENTIFIER) {
16451647
if (!isargname(token.value) || token.value == "firstline" || token.value == "lastline") {
@@ -1649,7 +1651,6 @@ VimLParser.prototype.parse_cmd_function = function() {
16491651
throw Err(viml_printf("E853: Duplicate argument name: %s", token.value), token.pos);
16501652
}
16511653
named[token.value] = 1;
1652-
var varnode = Node(NODE_IDENTIFIER);
16531654
varnode.pos = token.pos;
16541655
varnode.value = token.value;
16551656
viml_add(node.rlist, varnode);
@@ -1673,7 +1674,6 @@ VimLParser.prototype.parse_cmd_function = function() {
16731674
}
16741675
}
16751676
else if (token.type == TOKEN_DOTDOTDOT) {
1676-
var varnode = Node(NODE_IDENTIFIER);
16771677
varnode.pos = token.pos;
16781678
varnode.value = token.value;
16791679
viml_add(node.rlist, varnode);
@@ -2577,6 +2577,7 @@ ExprTokenizer.prototype.get2 = function() {
25772577
return this.token(TOKEN_REG, r.getn(2), pos);
25782578
}
25792579
else if (c == "&") {
2580+
var s = "";
25802581
if ((r.p(1) == "g" || r.p(1) == "l") && r.p(2) == ":") {
25812582
var s = r.getn(3) + r.read_word();
25822583
}
@@ -3110,6 +3111,7 @@ ExprParser.prototype.parse_expr8 = function() {
31103111
if (token.type != TOKEN_SQCLOSE) {
31113112
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
31123113
}
3114+
var left = node;
31133115
}
31143116
else {
31153117
var right = this.parse_expr1();
@@ -3127,6 +3129,7 @@ ExprParser.prototype.parse_expr8 = function() {
31273129
if (token.type != TOKEN_SQCLOSE) {
31283130
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
31293131
}
3132+
var left = node;
31303133
}
31313134
else {
31323135
var node = Node(NODE_SUBSCRIPT);
@@ -3137,9 +3140,9 @@ ExprParser.prototype.parse_expr8 = function() {
31373140
if (token.type != TOKEN_SQCLOSE) {
31383141
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
31393142
}
3143+
var left = node;
31403144
}
31413145
}
3142-
var left = node;
31433146
delete node;
31443147
}
31453148
else if (token.type == TOKEN_POPEN) {
@@ -3210,6 +3213,7 @@ ExprParser.prototype.parse_expr8 = function() {
32103213
ExprParser.prototype.parse_expr9 = function() {
32113214
var pos = this.reader.tell();
32123215
var token = this.tokenizer.get();
3216+
var node = Node(-1);
32133217
if (token.type == TOKEN_NUMBER) {
32143218
var node = Node(NODE_NUMBER);
32153219
node.pos = token.pos;
@@ -3461,13 +3465,14 @@ ExprParser.prototype.parse_identifier = function() {
34613465
var node = Node(NODE_IDENTIFIER);
34623466
node.pos = npos;
34633467
node.value = curly_parts[0].value;
3468+
return node;
34643469
}
34653470
else {
34663471
var node = Node(NODE_CURLYNAME);
34673472
node.pos = npos;
34683473
node.value = curly_parts;
3474+
return node;
34693475
}
3470-
return node;
34713476
}
34723477

34733478
ExprParser.prototype.parse_curly_parts = function() {
@@ -3535,6 +3540,7 @@ LvalueParser.prototype.parse_lv8 = function() {
35353540
var token = this.tokenizer.get();
35363541
if (!iswhite(c) && token.type == TOKEN_SQOPEN) {
35373542
var npos = token.pos;
3543+
var node = Node(-1);
35383544
if (this.tokenizer.peek().type == TOKEN_COLON) {
35393545
this.tokenizer.get();
35403546
var node = Node(NODE_SLICE);
@@ -3606,6 +3612,7 @@ LvalueParser.prototype.parse_lv8 = function() {
36063612
LvalueParser.prototype.parse_lv9 = function() {
36073613
var pos = this.reader.tell();
36083614
var token = this.tokenizer.get();
3615+
var node = Node(-1);
36093616
if (token.type == TOKEN_COPEN) {
36103617
this.reader.seek_set(pos);
36113618
var node = this.parse_identifier();
@@ -4219,6 +4226,7 @@ Compiler.prototype.compile_excall = function(node) {
42194226
}
42204227

42214228
Compiler.prototype.compile_let = function(node) {
4229+
var left = "";
42224230
if (node.left !== NIL) {
42234231
var left = this.compile(node.left);
42244232
}
@@ -4291,6 +4299,7 @@ Compiler.prototype.compile_while = function(node) {
42914299
}
42924300

42934301
Compiler.prototype.compile_for = function(node) {
4302+
var left = "";
42944303
if (node.left !== NIL) {
42954304
var left = this.compile(node.left);
42964305
}

0 commit comments

Comments
 (0)