Execute semantic actions for optionals only if the optional exists
This commit is contained in:
parent
c3b7cc58f0
commit
bf55252b9a
@ -25,7 +25,7 @@ struct Choice {
|
||||
char *id;
|
||||
statchange_t *statchange;
|
||||
|
||||
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
|
||||
Choice(int);
|
||||
};
|
||||
|
||||
typedef std::map<int, Choice*> ChoiceList;
|
||||
|
@ -60,20 +60,18 @@ Ending = 'THE END' Newline
|
||||
ChoiceList = c:Choice l:ChoiceList { $$ = l; (*$$.choices)[c.choice->option] = c.choice; }
|
||||
| c:Choice { $$.choices = new ChoiceList(); (*$$.choices)[c.choice->option] = c.choice; }
|
||||
|
||||
Choice = b:Bullet f:Freetext r:Redirect
|
||||
{
|
||||
$$ = r;
|
||||
$$.choice->option = b.num;
|
||||
$$.choice->flavor = f.string;
|
||||
}
|
||||
Choice = b:Bullet
|
||||
f:Freetext { b.choice->flavor = f.string; }
|
||||
(ck:StatCheck { b.choice->statcheck = ck.statcheck; })?
|
||||
'[' i:Identifier ']' { b.choice->id = i.string; } -
|
||||
(cg:StatChange { b.choice->statchange = cg.statchange; })?
|
||||
Newline { $$ = b; }
|
||||
;
|
||||
|
||||
Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); }
|
||||
Bullet = < [0-9]+ > ')' - { $$.choice = new Choice(atoi(yytext)); }
|
||||
|
||||
Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); }
|
||||
|
||||
Redirect = ck:StatCheck? '[' i:Identifier ']' - cg:StatChange? Newline
|
||||
{ $$.choice = new Choice(i.string, ck.statcheck, cg.statchange); }
|
||||
|
||||
StatCheck = '<' n:StatName v:StatVal r:StatRel '>' -
|
||||
{ $$.statcheck = new statcheck_t{n.string, v.num, r.num}; }
|
||||
|
||||
@ -96,10 +94,10 @@ Newline = '\r\n' | '\r' | '\n'
|
||||
|
||||
%%
|
||||
|
||||
Choice::Choice(char *id, statcheck_t *statcheck, statchange_t *statchange) {
|
||||
this->id = id;
|
||||
this->statcheck = statcheck;
|
||||
this->statchange = statchange;
|
||||
Choice::Choice(int option) {
|
||||
this->option = option;
|
||||
this->statcheck = NULL;
|
||||
this->statchange = NULL;
|
||||
}
|
||||
|
||||
Footer::Footer() {
|
||||
|
Loading…
Reference in New Issue
Block a user