From 4bd8fe585518ef33d1280918e774748a87a61c88 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 27 May 2014 10:05:17 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20bad=20Nasal=20parse=20of=20=E2=80=98foo[]?= =?UTF-8?q?=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a vector subscript is empty, don’t parse it as ‘[foo]’, instead print a parse error. Fix by Nicholas Scheel & Thomas Geymayer. --- simgear/nasal/codegen.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/simgear/nasal/codegen.c b/simgear/nasal/codegen.c index 8636fbb9..bc36a817 100644 --- a/simgear/nasal/codegen.c +++ b/simgear/nasal/codegen.c @@ -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);