Fix bad Nasal parse of ‘foo[]’.
When a vector subscript is empty, don’t parse it as ‘[foo]’, instead print a parse error. Fix by Nicholas Scheel & Thomas Geymayer.
This commit is contained in:
parent
9c421d55a9
commit
4bd8fe5855
@ -7,6 +7,7 @@
|
||||
// These are more sensical predicate names in most contexts in this file
|
||||
#define LEFT(tok) ((tok)->children)
|
||||
#define RIGHT(tok) ((tok)->lastChild)
|
||||
#define UNARY(tok) (LEFT(tok) && LEFT(tok) == RIGHT(tok))
|
||||
#define BINARY(tok) (LEFT(tok) && RIGHT(tok) && LEFT(tok)->next == RIGHT(tok))
|
||||
|
||||
// Forward references for recursion
|
||||
@ -634,12 +635,16 @@ static void genExpr(struct Parser* p, struct Token* t)
|
||||
else genExpr(p, LEFT(t));
|
||||
break;
|
||||
case TOK_LBRA:
|
||||
if(BINARY(t)) {
|
||||
genExtract(p, t);
|
||||
} else {
|
||||
if(UNARY(t)) {
|
||||
emit(p, OP_NEWVEC);
|
||||
genList(p, LEFT(t), 1);
|
||||
}
|
||||
else if(BINARY(t)) {
|
||||
genExtract(p, t);
|
||||
} else {
|
||||
// forbid usage as 'vec[]'
|
||||
naParseError(p, "missing index or slice expression(s)", t->line);
|
||||
}
|
||||
break;
|
||||
case TOK_LCURL:
|
||||
emit(p, OP_NEWHASH);
|
||||
|
Loading…
Reference in New Issue
Block a user