mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
viml/parser/expressions: Make commas actually work when calling
This commit is contained in:
@@ -681,24 +681,22 @@ static void viml_pexpr_handle_bop(ExprASTStack *const ast_stack,
|
||||
ExprOpLvl top_node_lvl;
|
||||
ExprOpAssociativity top_node_ass;
|
||||
assert(kv_size(*ast_stack));
|
||||
#define NODE_LVL(typ) \
|
||||
(bop_node->type == kExprNodeCall && typ == kExprNodeCall \
|
||||
? kEOpLvlSubscript \
|
||||
: node_type_to_op_lvl[typ])
|
||||
#define NODE_ASS(typ) \
|
||||
(bop_node->type == kExprNodeCall && typ == kExprNodeCall \
|
||||
? kEOpAssLeft \
|
||||
: node_type_to_op_ass[typ])
|
||||
const ExprOpLvl bop_node_lvl = NODE_LVL(bop_node->type);
|
||||
const ExprOpLvl bop_node_lvl = (bop_node->type == kExprNodeCall
|
||||
? kEOpLvlSubscript
|
||||
: node_type_to_op_lvl[bop_node->type]);
|
||||
#ifndef NDEBUG
|
||||
const ExprOpAssociativity bop_node_ass = NODE_ASS(bop_node->type);
|
||||
const ExprOpAssociativity bop_node_ass = (
|
||||
bop_node->type == kExprNodeCall
|
||||
? kEOpAssLeft
|
||||
: node_type_to_op_ass[bop_node->type]);
|
||||
#endif
|
||||
do {
|
||||
ExprASTNode **new_top_node_p = kv_last(*ast_stack);
|
||||
ExprASTNode *new_top_node = *new_top_node_p;
|
||||
assert(new_top_node != NULL);
|
||||
const ExprOpLvl new_top_node_lvl = NODE_LVL(new_top_node->type);
|
||||
const ExprOpAssociativity new_top_node_ass = NODE_ASS(new_top_node->type);
|
||||
const ExprOpLvl new_top_node_lvl = node_type_to_op_lvl[new_top_node->type];
|
||||
const ExprOpAssociativity new_top_node_ass = (
|
||||
node_type_to_op_ass[new_top_node->type]);
|
||||
assert(bop_node_lvl != new_top_node_lvl
|
||||
|| bop_node_ass == new_top_node_ass);
|
||||
if (top_node_p != NULL
|
||||
@@ -751,8 +749,6 @@ static void viml_pexpr_handle_bop(ExprASTStack *const ast_stack,
|
||||
*want_node_p = (*want_node_p == kENodeArgumentSeparator
|
||||
? kENodeArgument
|
||||
: kENodeValue);
|
||||
#undef NODE_ASS
|
||||
#undef NODE_LVL
|
||||
}
|
||||
|
||||
/// ParserPosition literal based on ParserPosition pos with columns shifted
|
||||
|
@@ -943,6 +943,121 @@ describe('Expressions parser', function()
|
||||
hl('Register', '@e', 1),
|
||||
hl('CallingParenthesis', ')'),
|
||||
})
|
||||
check_parsing('@a(@b(@c))', 0, {
|
||||
-- 01234567890123456789012345678901234567
|
||||
-- 0 1 2 3
|
||||
ast = {
|
||||
{
|
||||
'Call:0:2:(',
|
||||
children = {
|
||||
'Register(name=a):0:0:@a',
|
||||
{
|
||||
'Call:0:5:(',
|
||||
children = {
|
||||
'Register(name=b):0:3:@b',
|
||||
'Register(name=c):0:6:@c',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
hl('Register', '@a'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@b'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@c'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
})
|
||||
check_parsing('@a(@b(@c(@d(@e), @f(@g(@h), @i(@j)))))', 0, {
|
||||
-- 01234567890123456789012345678901234567
|
||||
-- 0 1 2 3
|
||||
ast = {
|
||||
{
|
||||
'Call:0:2:(',
|
||||
children = {
|
||||
'Register(name=a):0:0:@a',
|
||||
{
|
||||
'Call:0:5:(',
|
||||
children = {
|
||||
'Register(name=b):0:3:@b',
|
||||
{
|
||||
'Call:0:8:(',
|
||||
children = {
|
||||
'Register(name=c):0:6:@c',
|
||||
{
|
||||
'Comma:0:15:,',
|
||||
children = {
|
||||
{
|
||||
'Call:0:11:(',
|
||||
children = {
|
||||
'Register(name=d):0:9:@d',
|
||||
'Register(name=e):0:12:@e',
|
||||
},
|
||||
},
|
||||
{
|
||||
'Call:0:19:(',
|
||||
children = {
|
||||
'Register(name=f):0:16: @f',
|
||||
{
|
||||
'Comma:0:26:,',
|
||||
children = {
|
||||
{
|
||||
'Call:0:22:(',
|
||||
children = {
|
||||
'Register(name=g):0:20:@g',
|
||||
'Register(name=h):0:23:@h',
|
||||
},
|
||||
},
|
||||
{
|
||||
'Call:0:30:(',
|
||||
children = {
|
||||
'Register(name=i):0:27: @i',
|
||||
'Register(name=j):0:31:@j',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
hl('Register', '@a'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@b'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@c'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@d'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@e'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('Comma', ','),
|
||||
hl('Register', '@f', 1),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@g'),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@h'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('Comma', ','),
|
||||
hl('Register', '@i', 1),
|
||||
hl('CallingParenthesis', '('),
|
||||
hl('Register', '@j'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
hl('CallingParenthesis', ')'),
|
||||
})
|
||||
end)
|
||||
itp('works with identifiers', function()
|
||||
check_parsing('var', 0, {
|
||||
|
Reference in New Issue
Block a user