viml/parser/expressions: Fix call inside nested parenthesis

It may have incorrectly tried to call everything because of essentially “value” 
nodes being treated as not such.
This commit is contained in:
ZyX
2017-10-01 15:54:46 +03:00
parent f33543377e
commit 3735537a50
2 changed files with 50 additions and 12 deletions

View File

@@ -612,6 +612,7 @@ viml_pexpr_repr_token_end:
#ifdef UNIT_TESTING #ifdef UNIT_TESTING
#include <stdio.h> #include <stdio.h>
REAL_FATTR_UNUSED REAL_FATTR_UNUSED
static inline void viml_pexpr_debug_print_ast_node( static inline void viml_pexpr_debug_print_ast_node(
const ExprASTNode *const *const eastnode_p, const ExprASTNode *const *const eastnode_p,
@@ -626,6 +627,7 @@ static inline void viml_pexpr_debug_print_ast_node(
(*eastnode_p)->start.col, (*eastnode_p)->len); (*eastnode_p)->start.col, (*eastnode_p)->len);
} }
} }
REAL_FATTR_UNUSED REAL_FATTR_UNUSED
static inline void viml_pexpr_debug_print_ast_stack( static inline void viml_pexpr_debug_print_ast_stack(
const ExprASTStack *const ast_stack, const ExprASTStack *const ast_stack,
@@ -640,6 +642,7 @@ static inline void viml_pexpr_debug_print_ast_stack(
} }
} }
REAL_FATTR_UNUSED
static inline void viml_pexpr_debug_print_token( static inline void viml_pexpr_debug_print_token(
const ParserState *const pstate, const LexExprToken token) const ParserState *const pstate, const LexExprToken token)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_ALWAYS_INLINE
@@ -794,6 +797,7 @@ static inline ExprASTNode *viml_pexpr_new_node(const ExprASTNodeType type)
typedef enum { typedef enum {
kEOpLvlInvalid = 0, kEOpLvlInvalid = 0,
kEOpLvlComplexIdentifier,
kEOpLvlParens, kEOpLvlParens,
kEOpLvlArrow, kEOpLvlArrow,
kEOpLvlComma, kEOpLvlComma,
@@ -806,7 +810,6 @@ typedef enum {
kEOpLvlMultiplication, ///< Multiplication, division and modulo. kEOpLvlMultiplication, ///< Multiplication, division and modulo.
kEOpLvlUnary, ///< Unary operations: not, minus, plus. kEOpLvlUnary, ///< Unary operations: not, minus, plus.
kEOpLvlSubscript, ///< Subscripts. kEOpLvlSubscript, ///< Subscripts.
kEOpLvlComplexIdentifier, ///< Plain identifier, curly braces name.
kEOpLvlValue, ///< Values: literals, variables, nested expressions, … kEOpLvlValue, ///< Values: literals, variables, nested expressions, …
} ExprOpLvl; } ExprOpLvl;
@@ -843,10 +846,10 @@ static const ExprOpLvl node_type_to_op_lvl[] = {
[kExprNodeSubscript] = kEOpLvlSubscript, [kExprNodeSubscript] = kEOpLvlSubscript,
[kExprNodeComplexIdentifier] = kEOpLvlComplexIdentifier,
[kExprNodePlainIdentifier] = kEOpLvlComplexIdentifier,
[kExprNodeCurlyBracesIdentifier] = kEOpLvlComplexIdentifier, [kExprNodeCurlyBracesIdentifier] = kEOpLvlComplexIdentifier,
[kExprNodeComplexIdentifier] = kEOpLvlValue,
[kExprNodePlainIdentifier] = kEOpLvlValue,
[kExprNodeRegister] = kEOpLvlValue, [kExprNodeRegister] = kEOpLvlValue,
[kExprNodeListLiteral] = kEOpLvlValue, [kExprNodeListLiteral] = kEOpLvlValue,
}; };
@@ -884,10 +887,10 @@ static const ExprOpAssociativity node_type_to_op_ass[] = {
[kExprNodeSubscript] = kEOpAssLeft, [kExprNodeSubscript] = kEOpAssLeft,
[kExprNodePlainIdentifier] = kEOpAssLeft,
[kExprNodeComplexIdentifier] = kEOpAssLeft,
[kExprNodeCurlyBracesIdentifier] = kEOpAssLeft, [kExprNodeCurlyBracesIdentifier] = kEOpAssLeft,
[kExprNodeComplexIdentifier] = kEOpAssLeft,
[kExprNodePlainIdentifier] = kEOpAssNo,
[kExprNodeRegister] = kEOpAssNo, [kExprNodeRegister] = kEOpAssNo,
[kExprNodeListLiteral] = kEOpAssNo, [kExprNodeListLiteral] = kEOpAssNo,
}; };

View File

@@ -2269,7 +2269,43 @@ describe('Expressions parser', function()
hl('CallingParenthesis', ')'), hl('CallingParenthesis', ')'),
hl('Curly', '}'), hl('Curly', '}'),
}) })
-- FIXME the below should not crash check_parsing('a:{b()}c', 0, {
-- 01234567
ast = {
{
'ComplexIdentifier:0:2:',
children = {
'PlainIdentifier(scope=a,ident=):0:0:a:',
{
'ComplexIdentifier:0:7:',
children = {
{
'CurlyBracesIdentifier(--i):0:2:{',
children = {
{
'Call:0:4:(',
children = {
'PlainIdentifier(scope=0,ident=b):0:3:b',
},
},
},
},
'PlainIdentifier(scope=0,ident=c):0:7:c',
},
},
},
},
},
}, {
hl('IdentifierScope', 'a'),
hl('IdentifierScopeDelimiter', ':'),
hl('Curly', '{'),
hl('Identifier', 'b'),
hl('CallingParenthesis', '('),
hl('CallingParenthesis', ')'),
hl('Curly', '}'),
hl('Identifier', 'c'),
})
check_parsing('a:{{b, c -> @d + @e + ({f -> g})(@h)}(@i)}j', 0, { check_parsing('a:{{b, c -> @d + @e + ({f -> g})(@h)}(@i)}j', 0, {
-- 01234567890123456789012345678901234567890123456 -- 01234567890123456789012345678901234567890123456
-- 0 1 2 3 4 -- 0 1 2 3 4
@@ -2277,9 +2313,9 @@ describe('Expressions parser', function()
{ {
'ComplexIdentifier:0:2:', 'ComplexIdentifier:0:2:',
children = { children = {
'PlainIdentifier(scope=a,ident=):0:0:g:', 'PlainIdentifier(scope=a,ident=):0:0:a:',
{ {
'ComplexIdentifier:0:6:', 'ComplexIdentifier:0:42:',
children = { children = {
{ {
'CurlyBracesIdentifier(--i):0:2:{', 'CurlyBracesIdentifier(--i):0:2:{',
@@ -2314,7 +2350,7 @@ describe('Expressions parser', function()
'Call:0:32:(', 'Call:0:32:(',
children = { children = {
{ {
'NestingParenthesis:0:21: (', 'Nested:0:21: (',
children = { children = {
{ {
'Lambda(\\di):0:23:{', 'Lambda(\\di):0:23:{',
@@ -2342,10 +2378,9 @@ describe('Expressions parser', function()
'Register(name=i):0:38:@i', 'Register(name=i):0:38:@i',
}, },
}, },
'PlainIdentifier(scope=0,ident=j):0:42:j',
}, },
}, },
'PlainIdentifier(scope=0,ident=_test):0:42:_test', 'PlainIdentifier(scope=0,ident=j):0:42:j',
}, },
}, },
}, },
@@ -2364,7 +2399,7 @@ describe('Expressions parser', function()
hl('BinaryPlus', '+', 1), hl('BinaryPlus', '+', 1),
hl('Register', '@e', 1), hl('Register', '@e', 1),
hl('BinaryPlus', '+', 1), hl('BinaryPlus', '+', 1),
hl('NestingParenthesis', '('), hl('NestingParenthesis', '(', 1),
hl('Lambda', '{'), hl('Lambda', '{'),
hl('Identifier', 'f'), hl('Identifier', 'f'),
hl('Arrow', '->', 1), hl('Arrow', '->', 1),