- fixed some issues with the grammar for parsing states:

* Goto did not support the class scope operator '::'. Like in DECORATE, this cannot be done with a simple '.' because it creates semantic problems with first part of a state label. This requires different syntax so that it can unambiguously distinguish between a scope identifier and the actual label
 * Goto used the incorrect token PLUS for '+' instead of ADD.
 * The state's duration was not stored in the AST.
 * Truncating the sprite name inside the parser is probably not the best idea because it used a simple Printf to report this. Let's do this during processing of the AST where this can be properly handled as an error.
This commit is contained in:
Christoph Oelckers 2016-10-12 00:04:30 +02:00
commit f46b6b5be5
3 changed files with 23 additions and 13 deletions

View file

@ -430,25 +430,31 @@ state_flow_type(X) ::= GOTO(T) dottable_id(A) state_goto_offset(B).
NEW_AST_NODE(StateGoto, flow, T);
flow->Label = A;
flow->Offset = B;
flow->Qualifier = nullptr;
X = flow;
}
state_flow_type(X) ::= GOTO(T) IDENTIFIER(C) SCOPE dottable_id(A) state_goto_offset(B).
{
NEW_AST_NODE(StateGoto, flow, T);
flow->Label = A;
flow->Offset = B;
NEW_AST_NODE(Identifier,id,C);
id->Id = C.Name();
flow->Qualifier =id;
X = flow;
}
state_goto_offset(X) ::= . { X = NULL; }
state_goto_offset(X) ::= PLUS expr(A). { X = A; /*X-overwrites-A*/ } /* Must evaluate to a non-negative integer constant. */
state_goto_offset(X) ::= ADD expr(A). { X = A; /*X-overwrites-A*/ } /* Must evaluate to a non-negative integer constant. */
state_line(X) ::= NWS(A) NWS(B) expr state_opts(C) state_action(D).
state_line(X) ::= NWS(A) NWS(B) expr(E) state_opts(C) state_action(D).
{
NEW_AST_NODE(StateLine, line, A);
const char *sprite = FName(A.Name()).GetChars();
if (strlen(sprite) != 4)
{
Printf("Sprite name '%s' must be four characters", sprite);
}
else
{
memcpy(line->Sprite, sprite, 4);
}
line->Sprite = stat->Strings.Alloc(FName(A.Name()).GetChars());
line->Frames = stat->Strings.Alloc(FName(B.Name()).GetChars());
line->Duration = E;
line->bBright = C.Bright;
line->bFast = C.Fast;
line->bSlow = C.Slow;