Skip to content

Commit

Permalink
Merge pull request #55 from haya14busa/add-scope-hack-for-compiler
Browse files Browse the repository at this point in the history
Add scope hack for compiler
  • Loading branch information
mattn committed Jul 19, 2017
2 parents a48032a + a76da1c commit 55f97af
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
22 changes: 16 additions & 6 deletions autoload/vimlparser.vim
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,10 @@ function! s:VimLParser.parse_command_modifiers()
let modifiers = []
while s:TRUE
let pos = self.reader.tell()
let d = ''
if s:isdigit(self.reader.peekn(1))
let d = self.reader.read_digit()
call self.reader.skip_white()
else
let d = ''
endif
let k = self.reader.read_alpha()
let c = self.reader.peekn(1)
Expand Down Expand Up @@ -900,6 +899,7 @@ endfunction

function! s:VimLParser.find_command()
let c = self.reader.peekn(1)
let name = ''

if c ==# 'k'
call self.reader.getn(1)
Expand Down Expand Up @@ -1087,6 +1087,7 @@ endfunction

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

function! s:VimLParser.parse_cmd_lua()
let lines = []
call self.reader.skip_white()
if self.reader.peekn(2) ==# '<<'
call self.reader.getn(2)
Expand Down Expand Up @@ -1352,6 +1354,7 @@ function! s:VimLParser.parse_cmd_function()
else
let named = {}
while s:TRUE
let varnode = s:Node(s:NODE_IDENTIFIER)
let token = tokenizer.get()
if token.type == s:TOKEN_IDENTIFIER
if !s:isargname(token.value) || token.value ==# 'firstline' || token.value ==# 'lastline'
Expand All @@ -1360,7 +1363,6 @@ function! s:VimLParser.parse_cmd_function()
throw s:Err(printf('E853: Duplicate argument name: %s', token.value), token.pos)
endif
let named[token.value] = 1
let varnode = s:Node(s:NODE_IDENTIFIER)
let varnode.pos = token.pos
let varnode.value = token.value
call add(node.rlist, varnode)
Expand All @@ -1381,7 +1383,6 @@ function! s:VimLParser.parse_cmd_function()
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
endif
elseif token.type == s:TOKEN_DOTDOTDOT
let varnode = s:Node(s:NODE_IDENTIFIER)
let varnode.pos = token.pos
let varnode.value = token.value
call add(node.rlist, varnode)
Expand Down Expand Up @@ -2770,6 +2771,7 @@ function! s:ExprTokenizer.get2()
" @<EOL> is treated as @"
return self.token(s:TOKEN_REG, r.getn(2), pos)
elseif c ==# '&'
let s = ''
if (r.p(1) ==# 'g' || r.p(1) ==# 'l') && r.p(2) ==# ':'
let s = r.getn(3) . r.read_word()
else
Expand Down Expand Up @@ -3256,6 +3258,7 @@ function! s:ExprParser.parse_expr8()
if token.type != s:TOKEN_SQCLOSE
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
endif
let left = node
else
let right = self.parse_expr1()
if self.tokenizer.peek().type == s:TOKEN_COLON
Expand All @@ -3272,6 +3275,7 @@ function! s:ExprParser.parse_expr8()
if token.type != s:TOKEN_SQCLOSE
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
endif
let left = node
else
let node = s:Node(s:NODE_SUBSCRIPT)
let node.pos = npos
Expand All @@ -3281,9 +3285,9 @@ function! s:ExprParser.parse_expr8()
if token.type != s:TOKEN_SQCLOSE
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
endif
let left = node
endif
endif
let left = node
unlet node
elseif token.type == s:TOKEN_POPEN
let node = s:Node(s:NODE_CALL)
Expand Down Expand Up @@ -3348,6 +3352,7 @@ endfunction
function! s:ExprParser.parse_expr9()
let pos = self.reader.tell()
let token = self.tokenizer.get()
let node = s:Node(-1)
if token.type == s:TOKEN_NUMBER
let node = s:Node(s:NODE_NUMBER)
let node.pos = token.pos
Expand Down Expand Up @@ -3574,12 +3579,13 @@ function! s:ExprParser.parse_identifier()
let node = s:Node(s:NODE_IDENTIFIER)
let node.pos = npos
let node.value = curly_parts[0].value
return node
else
let node = s:Node(s:NODE_CURLYNAME)
let node.pos = npos
let node.value = curly_parts
endif
return node
endif
endfunction

function! s:ExprParser.parse_curly_parts()
Expand Down Expand Up @@ -3642,6 +3648,7 @@ function! s:LvalueParser.parse_lv8()
let token = self.tokenizer.get()
if !s:iswhite(c) && token.type == s:TOKEN_SQOPEN
let npos = token.pos
let node = s:Node(-1)
if self.tokenizer.peek().type == s:TOKEN_COLON
call self.tokenizer.get()
let node = s:Node(s:NODE_SLICE)
Expand Down Expand Up @@ -3709,6 +3716,7 @@ endfunction
function! s:LvalueParser.parse_lv9()
let pos = self.reader.tell()
let token = self.tokenizer.get()
let node = s:Node(-1)
if token.type == s:TOKEN_COPEN
call self.reader.seek_set(pos)
let node = self.parse_identifier()
Expand Down Expand Up @@ -4232,6 +4240,7 @@ function! s:Compiler.compile_excall(node)
endfunction

function! s:Compiler.compile_let(node)
let left = ''
if a:node.left isnot s:NIL
let left = self.compile(a:node.left)
else
Expand Down Expand Up @@ -4299,6 +4308,7 @@ function! s:Compiler.compile_while(node)
endfunction

function! s:Compiler.compile_for(node)
let left = ''
if a:node.left isnot s:NIL
let left = self.compile(a:node.left)
else
Expand Down
23 changes: 16 additions & 7 deletions js/vimlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,11 @@ VimLParser.prototype.parse_command_modifiers = function() {
var modifiers = [];
while (TRUE) {
var pos = this.reader.tell();
var d = "";
if (isdigit(this.reader.peekn(1))) {
var d = this.reader.read_digit();
this.reader.skip_white();
}
else {
var d = "";
}
var k = this.reader.read_alpha();
var c = this.reader.peekn(1);
this.reader.skip_white();
Expand Down Expand Up @@ -1168,6 +1166,7 @@ VimLParser.prototype._parse_command = function(parser) {

VimLParser.prototype.find_command = function() {
var c = this.reader.peekn(1);
var name = "";
if (c == "k") {
this.reader.getn(1);
var name = "k";
Expand Down Expand Up @@ -1371,6 +1370,7 @@ VimLParser.prototype.parse_cmd_modifier_range = function() {

// TODO:
VimLParser.prototype.parse_cmd_common = function() {
var end = this.reader.getpos();
if (viml_eqregh(this.ea.cmd.flags, "\\<TRLBAR\\>") && !this.ea.usefilter) {
var end = this.separate_nextcmd();
}
Expand Down Expand Up @@ -1524,6 +1524,7 @@ VimLParser.prototype.parse_cmd_loadkeymap = function() {
}

VimLParser.prototype.parse_cmd_lua = function() {
var lines = [];
this.reader.skip_white();
if (this.reader.peekn(2) == "<<") {
this.reader.getn(2);
Expand Down Expand Up @@ -1640,6 +1641,7 @@ VimLParser.prototype.parse_cmd_function = function() {
else {
var named = {};
while (TRUE) {
var varnode = Node(NODE_IDENTIFIER);
var token = tokenizer.get();
if (token.type == TOKEN_IDENTIFIER) {
if (!isargname(token.value) || token.value == "firstline" || token.value == "lastline") {
Expand All @@ -1649,7 +1651,6 @@ VimLParser.prototype.parse_cmd_function = function() {
throw Err(viml_printf("E853: Duplicate argument name: %s", token.value), token.pos);
}
named[token.value] = 1;
var varnode = Node(NODE_IDENTIFIER);
varnode.pos = token.pos;
varnode.value = token.value;
viml_add(node.rlist, varnode);
Expand All @@ -1673,7 +1674,6 @@ VimLParser.prototype.parse_cmd_function = function() {
}
}
else if (token.type == TOKEN_DOTDOTDOT) {
var varnode = Node(NODE_IDENTIFIER);
varnode.pos = token.pos;
varnode.value = token.value;
viml_add(node.rlist, varnode);
Expand Down Expand Up @@ -2577,6 +2577,7 @@ ExprTokenizer.prototype.get2 = function() {
return this.token(TOKEN_REG, r.getn(2), pos);
}
else if (c == "&") {
var s = "";
if ((r.p(1) == "g" || r.p(1) == "l") && r.p(2) == ":") {
var s = r.getn(3) + r.read_word();
}
Expand Down Expand Up @@ -3110,6 +3111,7 @@ ExprParser.prototype.parse_expr8 = function() {
if (token.type != TOKEN_SQCLOSE) {
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
}
var left = node;
}
else {
var right = this.parse_expr1();
Expand All @@ -3127,6 +3129,7 @@ ExprParser.prototype.parse_expr8 = function() {
if (token.type != TOKEN_SQCLOSE) {
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
}
var left = node;
}
else {
var node = Node(NODE_SUBSCRIPT);
Expand All @@ -3137,9 +3140,9 @@ ExprParser.prototype.parse_expr8 = function() {
if (token.type != TOKEN_SQCLOSE) {
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
}
var left = node;
}
}
var left = node;
delete node;
}
else if (token.type == TOKEN_POPEN) {
Expand Down Expand Up @@ -3210,6 +3213,7 @@ ExprParser.prototype.parse_expr8 = function() {
ExprParser.prototype.parse_expr9 = function() {
var pos = this.reader.tell();
var token = this.tokenizer.get();
var node = Node(-1);
if (token.type == TOKEN_NUMBER) {
var node = Node(NODE_NUMBER);
node.pos = token.pos;
Expand Down Expand Up @@ -3461,13 +3465,14 @@ ExprParser.prototype.parse_identifier = function() {
var node = Node(NODE_IDENTIFIER);
node.pos = npos;
node.value = curly_parts[0].value;
return node;
}
else {
var node = Node(NODE_CURLYNAME);
node.pos = npos;
node.value = curly_parts;
return node;
}
return node;
}

ExprParser.prototype.parse_curly_parts = function() {
Expand Down Expand Up @@ -3535,6 +3540,7 @@ LvalueParser.prototype.parse_lv8 = function() {
var token = this.tokenizer.get();
if (!iswhite(c) && token.type == TOKEN_SQOPEN) {
var npos = token.pos;
var node = Node(-1);
if (this.tokenizer.peek().type == TOKEN_COLON) {
this.tokenizer.get();
var node = Node(NODE_SLICE);
Expand Down Expand Up @@ -3606,6 +3612,7 @@ LvalueParser.prototype.parse_lv8 = function() {
LvalueParser.prototype.parse_lv9 = function() {
var pos = this.reader.tell();
var token = this.tokenizer.get();
var node = Node(-1);
if (token.type == TOKEN_COPEN) {
this.reader.seek_set(pos);
var node = this.parse_identifier();
Expand Down Expand Up @@ -4219,6 +4226,7 @@ Compiler.prototype.compile_excall = function(node) {
}

Compiler.prototype.compile_let = function(node) {
var left = "";
if (node.left !== NIL) {
var left = this.compile(node.left);
}
Expand Down Expand Up @@ -4291,6 +4299,7 @@ Compiler.prototype.compile_while = function(node) {
}

Compiler.prototype.compile_for = function(node) {
var left = "";
if (node.left !== NIL) {
var left = this.compile(node.left);
}
Expand Down
Loading

0 comments on commit 55f97af

Please sign in to comment.