Parse the choices
This commit is contained in:
parent
8c729d5218
commit
9d4e426b4f
57
cyoa.leg
57
cyoa.leg
@ -19,20 +19,14 @@ struct statchange_t {
|
||||
int addend;
|
||||
};
|
||||
|
||||
enum ChoiceFlags : int {
|
||||
StatCheck = 0x1,
|
||||
StatChange = 0x2,
|
||||
};
|
||||
|
||||
struct Choice {
|
||||
int flags;
|
||||
int option;
|
||||
char *flavor;
|
||||
statcheck_t statcheck;
|
||||
statcheck_t *statcheck;
|
||||
char *id;
|
||||
statchange_t statchange;
|
||||
statchange_t *statchange;
|
||||
|
||||
Choice(char*, statcheck_t*, statchange_t*);
|
||||
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
|
||||
};
|
||||
|
||||
enum class FooterType {
|
||||
@ -89,10 +83,9 @@ Story = BlankLine* (p:Page { pages.push_back(p.page); })+ EndOfFile;
|
||||
Page = h:Header b:Body { $$.page = b.page; $$.page->id = h.string}
|
||||
BlankLine*;
|
||||
|
||||
Header = < Identifier > { $$.string = strndup(yytext, yyleng); }
|
||||
Newline BlankLine*;
|
||||
Header = < i:Identifier > Newline BlankLine* { $$ = i; }
|
||||
|
||||
Identifier = [A-Z][A-Z0-9_]+;
|
||||
Identifier = < [A-Z][A-Z0-9_]+ > - { $$.string = strndup(yytext, yyleng); };
|
||||
|
||||
Body = Footer | t:TextLine b:Body { $$ = b; append_body(b.page, t.string);};
|
||||
|
||||
@ -103,7 +96,7 @@ Footer = Ending { $$.page = emit_ending(); }
|
||||
| c:ChoiceList { $$.page = emit_choices(c.choices); }
|
||||
;
|
||||
|
||||
Goto = 'GOTO' Spacing < i:Identifier > Newline
|
||||
Goto = 'GOTO' - < i:Identifier > Newline
|
||||
{ $$.string = strndup(yytext, yyleng); }
|
||||
;
|
||||
|
||||
@ -119,39 +112,39 @@ Choice = b:Bullet f:Freetext r:Redirect
|
||||
$$.choice->flavor = f.string;
|
||||
};
|
||||
|
||||
Bullet = < [0-9]+ > ')' Spacing { $$.num = atoi(yytext); };
|
||||
Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); };
|
||||
|
||||
Freetext = < (!Redirect .)+ > { $$.string = strndup(yytext, yyleng); };
|
||||
Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); };
|
||||
|
||||
Redirect = ck:StatCheck? '[' i:Identifier ']' Spacing cg:StatChange? Newline
|
||||
Redirect = ck:StatCheck? '[' i:Identifier ']' - cg:StatChange? Newline
|
||||
{ $$.choice = new Choice(i.string, ck.statcheck, cg.statchange); }
|
||||
|
||||
StatCheck = '<' StatName Spacing [0-9]+ ('+' | '-')? '>' Spacing;
|
||||
StatCheck = '<' n:StatName v:StatVal r:StatRel '>' -
|
||||
{ $$.statcheck = new statcheck_t{n.string, v.num, r.num}; }
|
||||
|
||||
StatChange = '(' ('+' | '-') [0-9]+ Spacing StatName ')';
|
||||
StatChange = '(' ('+' | '-') v:StatVal n:StatName ')'
|
||||
{ $$.statchange = new statchange_t{n.string, v.num}; }
|
||||
|
||||
StatName = [A-Za-z]+;
|
||||
StatName = < [A-Za-z]+ > - { $$.string = strdup(yytext); };
|
||||
|
||||
EndOfFile = !.;
|
||||
StatVal = < [0-9]+ > - { $$.num = atoi(yytext); }
|
||||
|
||||
BlankLine = Spacing Newline;
|
||||
StatRel = < ('+'|'-')? > { $$.num = 0x0 } -
|
||||
|
||||
Spacing = (' ' | '\t')*;
|
||||
EndOfFile = !.
|
||||
|
||||
Newline = '\r\n' | '\r' | '\n';
|
||||
BlankLine = - Newline
|
||||
|
||||
- = (' ' | '\t')*
|
||||
|
||||
Newline = '\r\n' | '\r' | '\n'
|
||||
|
||||
%%
|
||||
|
||||
Choice::Choice(char *id, statcheck_t *ck, statchange_t *cg) {
|
||||
Choice::Choice(char *id, statcheck_t *statcheck, statchange_t *statchange) {
|
||||
this->id = id;
|
||||
if (ck) {
|
||||
statcheck = *ck;
|
||||
flags |= StatCheck;
|
||||
}
|
||||
if (cg) {
|
||||
statchange = *cg;
|
||||
flags |= StatChange;
|
||||
}
|
||||
this->statcheck = statcheck;
|
||||
this->statchange = statchange;
|
||||
}
|
||||
|
||||
Footer::Footer() {
|
||||
|
Loading…
Reference in New Issue
Block a user