Skip to content

Commit 4e3fb77

Browse files
committed
transpile js,py
1 parent 18e1afb commit 4e3fb77

File tree

2 files changed

+80
-57
lines changed

2 files changed

+80
-57
lines changed

js/vimlparser.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,14 @@ function ExArg() {
578578
// PLUS .left
579579
// SUBSCRIPT .left .right
580580
// SLICE .left .rlist
581-
// METHOD .left .right .lambda_rlist
581+
// METHOD .left .right
582582
// CALL .left .rlist
583583
// DOT .left .right
584584
// NUMBER .value
585585
// STRING .value
586586
// LIST .value
587587
// DICT .value
588+
// BLOB .value
588589
// NESTING .left
589590
// OPTION .value
590591
// IDENTIFIER .value
@@ -3397,48 +3398,27 @@ ExprParser.prototype.parse_expr8 = function() {
33973398
delete node;
33983399
}
33993400
else if (token.type == TOKEN_ARROW) {
3401+
var funcname_or_lambda = this.parse_expr9();
3402+
var token = this.tokenizer.get();
3403+
if (token.type != TOKEN_POPEN) {
3404+
throw Err("E107: Missing parentheses: lambda", token.pos);
3405+
}
3406+
var right = Node(NODE_CALL);
3407+
right.pos = token.pos;
3408+
right.left = funcname_or_lambda;
3409+
right.rlist = this.parse_rlist();
34003410
var node = Node(NODE_METHOD);
34013411
node.pos = token.pos;
34023412
node.left = left;
3403-
node.right = this.parse_expr8();
3404-
node.lambda_rlist = NIL;
3405-
if (node.right.type != NODE_CALL) {
3406-
throw Err("Rhs of method operator must be an function call", node.right.pos);
3407-
}
3413+
node.right = right;
34083414
var left = node;
34093415
delete node;
34103416
}
34113417
else if (token.type == TOKEN_POPEN) {
34123418
var node = Node(NODE_CALL);
34133419
node.pos = token.pos;
34143420
node.left = left;
3415-
node.rlist = [];
3416-
if (this.tokenizer.peek().type == TOKEN_PCLOSE) {
3417-
this.tokenizer.get();
3418-
}
3419-
else {
3420-
while (TRUE) {
3421-
viml_add(node.rlist, this.parse_expr1());
3422-
var token = this.tokenizer.get();
3423-
if (token.type == TOKEN_COMMA) {
3424-
// XXX: Vim allows foo(a, b, ). Lint should warn it.
3425-
if (this.tokenizer.peek().type == TOKEN_PCLOSE) {
3426-
this.tokenizer.get();
3427-
break;
3428-
}
3429-
}
3430-
else if (token.type == TOKEN_PCLOSE) {
3431-
break;
3432-
}
3433-
else {
3434-
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
3435-
}
3436-
}
3437-
}
3438-
if (viml_len(node.rlist) > MAX_FUNC_ARGS) {
3439-
// TODO: funcname E740: Too many arguments for function: %s
3440-
throw Err("E740: Too many arguments for function", node.pos);
3441-
}
3421+
node.rlist = this.parse_rlist();
34423422
var left = node;
34433423
delete node;
34443424
}
@@ -3460,6 +3440,38 @@ ExprParser.prototype.parse_expr8 = function() {
34603440
return left;
34613441
}
34623442

3443+
ExprParser.prototype.parse_rlist = function() {
3444+
var rlist = [];
3445+
var token = this.tokenizer.peek();
3446+
if (this.tokenizer.peek().type == TOKEN_PCLOSE) {
3447+
this.tokenizer.get();
3448+
}
3449+
else {
3450+
while (TRUE) {
3451+
viml_add(rlist, this.parse_expr1());
3452+
var token = this.tokenizer.get();
3453+
if (token.type == TOKEN_COMMA) {
3454+
// XXX: Vim allows foo(a, b, ). Lint should warn it.
3455+
if (this.tokenizer.peek().type == TOKEN_PCLOSE) {
3456+
this.tokenizer.get();
3457+
break;
3458+
}
3459+
}
3460+
else if (token.type == TOKEN_PCLOSE) {
3461+
break;
3462+
}
3463+
else {
3464+
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
3465+
}
3466+
}
3467+
}
3468+
if (viml_len(rlist) > MAX_FUNC_ARGS) {
3469+
// TODO: funcname E740: Too many arguments for function: %s
3470+
throw Err("E740: Too many arguments for function", token.pos);
3471+
}
3472+
return rlist;
3473+
}
3474+
34633475
// expr9: number
34643476
// "string"
34653477
// 'string'

py/vimlparser.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,14 @@ def ExArg():
567567
# PLUS .left
568568
# SUBSCRIPT .left .right
569569
# SLICE .left .rlist
570-
# METHOD .left .right .lambda_rlist
570+
# METHOD .left .right
571571
# CALL .left .rlist
572572
# DOT .left .right
573573
# NUMBER .value
574574
# STRING .value
575575
# LIST .value
576576
# DICT .value
577+
# BLOB .value
577578
# NESTING .left
578579
# OPTION .value
579580
# IDENTIFIER .value
@@ -2769,38 +2770,25 @@ def parse_expr8(self):
27692770
left = node
27702771
del node
27712772
elif token.type == TOKEN_ARROW:
2773+
funcname_or_lambda = self.parse_expr9()
2774+
token = self.tokenizer.get()
2775+
if token.type != TOKEN_POPEN:
2776+
raise VimLParserException(Err("E107: Missing parentheses: lambda", token.pos))
2777+
right = Node(NODE_CALL)
2778+
right.pos = token.pos
2779+
right.left = funcname_or_lambda
2780+
right.rlist = self.parse_rlist()
27722781
node = Node(NODE_METHOD)
27732782
node.pos = token.pos
27742783
node.left = left
2775-
node.right = self.parse_expr8()
2776-
node.lambda_rlist = NIL
2777-
if node.right.type != NODE_CALL:
2778-
raise VimLParserException(Err("Rhs of method operator must be an function call", node.right.pos))
2784+
node.right = right
27792785
left = node
27802786
del node
27812787
elif token.type == TOKEN_POPEN:
27822788
node = Node(NODE_CALL)
27832789
node.pos = token.pos
27842790
node.left = left
2785-
node.rlist = []
2786-
if self.tokenizer.peek().type == TOKEN_PCLOSE:
2787-
self.tokenizer.get()
2788-
else:
2789-
while TRUE:
2790-
viml_add(node.rlist, self.parse_expr1())
2791-
token = self.tokenizer.get()
2792-
if token.type == TOKEN_COMMA:
2793-
# XXX: Vim allows foo(a, b, ). Lint should warn it.
2794-
if self.tokenizer.peek().type == TOKEN_PCLOSE:
2795-
self.tokenizer.get()
2796-
break
2797-
elif token.type == TOKEN_PCLOSE:
2798-
break
2799-
else:
2800-
raise VimLParserException(Err(viml_printf("unexpected token: %s", token.value), token.pos))
2801-
if viml_len(node.rlist) > MAX_FUNC_ARGS:
2802-
# TODO: funcname E740: Too many arguments for function: %s
2803-
raise VimLParserException(Err("E740: Too many arguments for function", node.pos))
2791+
node.rlist = self.parse_rlist()
28042792
left = node
28052793
del node
28062794
elif not iswhite(c) and token.type == TOKEN_DOT:
@@ -2816,6 +2804,29 @@ def parse_expr8(self):
28162804
break
28172805
return left
28182806

2807+
def parse_rlist(self):
2808+
rlist = []
2809+
token = self.tokenizer.peek()
2810+
if self.tokenizer.peek().type == TOKEN_PCLOSE:
2811+
self.tokenizer.get()
2812+
else:
2813+
while TRUE:
2814+
viml_add(rlist, self.parse_expr1())
2815+
token = self.tokenizer.get()
2816+
if token.type == TOKEN_COMMA:
2817+
# XXX: Vim allows foo(a, b, ). Lint should warn it.
2818+
if self.tokenizer.peek().type == TOKEN_PCLOSE:
2819+
self.tokenizer.get()
2820+
break
2821+
elif token.type == TOKEN_PCLOSE:
2822+
break
2823+
else:
2824+
raise VimLParserException(Err(viml_printf("unexpected token: %s", token.value), token.pos))
2825+
if viml_len(rlist) > MAX_FUNC_ARGS:
2826+
# TODO: funcname E740: Too many arguments for function: %s
2827+
raise VimLParserException(Err("E740: Too many arguments for function", token.pos))
2828+
return rlist
2829+
28192830
# expr9: number
28202831
# "string"
28212832
# 'string'

0 commit comments

Comments
 (0)