static int defArg(struct Parser* p, struct Token* t)
{
- if(t->type == TOK_LPAR) return defArg(p, RIGHT(t));
+ if(t->type == TOK_LPAR) {
+ // http://code.google.com/p/flightgear-bugs/issues/detail?id=737
+ // TOK_LPAR can mean multi-value assignment or function call,
+ // disambigaute by checking the rule of the token
+ if (t->rule == PREC_SUFFIX)
+ naParseError(p, "default arguments cannot be function calls", t->line);
+ return defArg(p, RIGHT(t));
+ }
+
if(t->type == TOK_MINUS && RIGHT(t) &&
RIGHT(t)->type == TOK_LITERAL && !RIGHT(t)->str)
{
{
if(!t || t->type == TOK_EMPTY)
return;
- if(t->type != TOK_COLON)
+ if(t->type != TOK_COLON || !LEFT(t))
naParseError(p, "bad hash/object initializer", t->line);
if(LEFT(t)->type == TOK_SYMBOL) genScalarConstant(p, LEFT(t));
else if(LEFT(t)->type == TOK_LITERAL) genExpr(p, LEFT(t));
static void genBreakContinue(struct Parser* p, struct Token* t)
{
int levels = 1, loop = -1, bp, cp, i;
+ // http://code.google.com/p/flightgear-bugs/issues/detail?id=587
+ // Make sure we are inside of a loop
+ if(p->cg->loopTop <= 0)
+ naParseError(p, "break/continue outside of a valid loop", t->line);
+
if(RIGHT(t)) {
if(RIGHT(t)->type != TOK_SYMBOL)
naParseError(p, "bad break/continue label", t->line);
{
struct Token *lv = LEFT(t), *rv = RIGHT(t);
int len, dummy, var=0;
+ if (!lv)
+ naParseError(p, "bad assignment, missing variable", t->line);
+ else
if(parListLen(lv) || (lv->type == TOK_VAR && parListLen(RIGHT(lv)))) {
if(lv->type == TOK_VAR) { lv = RIGHT(lv); var = 1; }
len = parListLen(lv);
- if(rv->type == TOK_LPAR) {
+ // http://code.google.com/p/flightgear-bugs/issues/detail?id=585
+ // TOK_LPAR can mean multi-value assignment or function call,
+ // disambigaute by checking the rule of the token
+ if(rv->type == TOK_LPAR && rv->rule != PREC_SUFFIX) {
if(len != parListLen(rv))
naParseError(p, "bad assignment count", rv->line);
genCommaList(p, LEFT(rv));
static void genSlice(struct Parser* p, struct Token* t)
{
+ if(!t || t->type==TOK_EMPTY) naParseError(p, "empty slice expression", -1);
if(t->type == TOK_COLON) {
- genExpr(p, LEFT(t));
- genExpr(p, RIGHT(t));
+ if(LEFT(t)) genExpr(p, LEFT(t)); else emit(p, OP_PUSHNIL);
+ if(RIGHT(t)) genExpr(p, RIGHT(t)); else emit(p, OP_PUSHNIL);
emit(p, OP_SLICE2);
} else {
genExpr(p, t);