]> git.mxchange.org Git - simgear.git/commitdiff
Fix bad Nasal parse of ‘foo[]’.
authorJames Turner <zakalawe@mac.com>
Tue, 27 May 2014 09:05:17 +0000 (10:05 +0100)
committerJames Turner <zakalawe@mac.com>
Tue, 27 May 2014 09:05:17 +0000 (10:05 +0100)
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

index 8636fbb958e0f90c8fe3132629d429c69d8cbabe..bc36a8179b124d2701e4b9acc8ebdc4aa530f359 100644 (file)
@@ -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);