2012-08-26
Don't try to read expressions as statements. That yields nothing useful and inevidently bombs out anyway.
commands.cxx | file | annotate | diff | comparison | revisions | |
parser.cxx | file | annotate | diff | comparison | revisions | |
scriptreader.h | file | annotate | diff | comparison | revisions |
--- a/commands.cxx Sun Aug 26 23:28:09 2012 +0300 +++ b/commands.cxx Sun Aug 26 23:54:58 2012 +0300 @@ -163,11 +163,24 @@ !t.compare ("float") ? TYPE_FLOAT : !t.compare ("str") ? TYPE_STRING : !t.compare ("void") ? TYPE_VOID : - !t.compare ("bool") ? TYPE_INT : -1; + !t.compare ("bool") ? TYPE_BOOL : -1; } // ============================================================================ // Inverse operation - type name by value +str GetTypeName (int r) { + switch (r) { + case TYPE_INT: return "int"; break; + case TYPE_STRING: return "str"; break; + case TYPE_VOID: return "void"; break; + case TYPE_FLOAT: return "float"; break; + case TYPE_BOOL: return "bool"; break; + } + + return ""; +} + +// ============================================================================ str GetReturnTypeName (int r) { switch (r) { case RETURNVAL_INT: return "int"; break; @@ -195,7 +208,7 @@ // Returns the prototype of the command str GetCommandPrototype (CommandDef* comm) { str text; - text += GetReturnTypeName (comm->returnvalue); + text += GetTypeName (comm->returnvalue); text += ' '; text += comm->name; text += '('; @@ -210,7 +223,7 @@ if (i) text += ", "; - text += GetReturnTypeName (comm->argtypes[i]); + text += GetTypeName (comm->argtypes[i]); text += ' '; text += comm->argnames[i];
--- a/parser.cxx Sun Aug 26 23:28:09 2012 +0300 +++ b/parser.cxx Sun Aug 26 23:54:58 2012 +0300 @@ -97,7 +97,7 @@ // State name must be a word. if (token.first (" ") != token.len()) - ParserError ("state name must be a single word! got `%s`", token.chars()); + ParserError ("state name must be a single word, got `%s`", token.chars()); str statename = token; // stateSpawn is special - it *must* be defined. If we @@ -133,7 +133,7 @@ EventDef* e = FindEventByName (token); if (!e) - ParserError ("bad event! got `%s`\n", token.chars()); + ParserError ("bad event, got `%s`\n", token.chars()); MustNext ("{"); @@ -679,13 +679,15 @@ while (1) { if (!token.compare (")")) { if (curarg < comm->numargs) - ParserError ("too few arguments passed to %s\n", comm->name.chars()); + ParserError ("too few arguments passed to %s\n\tprototype: %s", + comm->name.chars(), GetCommandPrototype (comm).chars()); break; curarg++; } if (curarg >= comm->maxargs) - ParserError ("too many arguments passed to %s\n", comm->name.chars()); + ParserError ("too many arguments passed to %s\n\tprototype: %s", + comm->name.chars(), GetCommandPrototype (comm).chars()); r->Merge (ParseExpression (comm->argtypes[curarg])); MustNext (); @@ -797,13 +799,13 @@ int oper; while ((oper = ParseOperator (true)) != -1) { // We peeked the operator, move forward now - MustNext(); + Next (); // Can't be an assignement operator, those belong in assignments. if (IsAssignmentOperator (oper)) ParserError ("assignment operator inside expression"); - // Parse the right operand, + // Parse the right operand. MustNext (); DataBuffer* rb = ParseExprValue (reqtype); @@ -943,6 +945,7 @@ case TYPE_VOID: ParserError ("unknown identifier `%s` (expected keyword, function or variable)", token.chars()); break; + case TYPE_BOOL: case TYPE_INT: { MustNumber (true); @@ -1069,9 +1072,8 @@ return b; } - // If it's not a keyword, parse it as an expression. - DataBuffer* b = ParseExpression (TYPE_VOID); - return b; + ParserError ("bad statement"); + return NULL; } void ScriptReader::AddSwitchCase (ObjWriter* w, DataBuffer* b) {