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;
|
char *id;
|
||||||
statchange_t *statchange;
|
statchange_t *statchange;
|
||||||
|
|
||||||
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
|
Choice(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<int, Choice*> ChoiceList;
|
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; }
|
ChoiceList = c:Choice l:ChoiceList { $$ = l; (*$$.choices)[c.choice->option] = c.choice; }
|
||||||
| c:Choice { $$.choices = new ChoiceList(); (*$$.choices)[c.choice->option] = c.choice; }
|
| c:Choice { $$.choices = new ChoiceList(); (*$$.choices)[c.choice->option] = c.choice; }
|
||||||
|
|
||||||
Choice = b:Bullet f:Freetext r:Redirect
|
Choice = b:Bullet
|
||||||
{
|
f:Freetext { b.choice->flavor = f.string; }
|
||||||
$$ = r;
|
(ck:StatCheck { b.choice->statcheck = ck.statcheck; })?
|
||||||
$$.choice->option = b.num;
|
'[' i:Identifier ']' { b.choice->id = i.string; } -
|
||||||
$$.choice->flavor = f.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); }
|
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 = '<' n:StatName v:StatVal r:StatRel '>' -
|
||||||
{ $$.statcheck = new statcheck_t{n.string, v.num, r.num}; }
|
{ $$.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) {
|
Choice::Choice(int option) {
|
||||||
this->id = id;
|
this->option = option;
|
||||||
this->statcheck = statcheck;
|
this->statcheck = NULL;
|
||||||
this->statchange = statchange;
|
this->statchange = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Footer::Footer() {
|
Footer::Footer() {
|
||||||
|
Loading…
Reference in New Issue
Block a user