From e150ee5e1ce33b0a4913d53e5df4658ea508eb6e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 30 Jan 2012 08:55:14 -0700 Subject: Syntax updated to support options & commands. --- demo.stage | 6 ++++-- src/parser.l | 2 ++ src/parser.y | 22 +++++++++++++++++++++- support/vim/syntax/stage.vim | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/demo.stage b/demo.stage index 852deee..5a3fe2e 100644 --- a/demo.stage +++ b/demo.stage @@ -118,9 +118,10 @@ situation <> } enter { - display('''You're standing on a narrow stretch of beach.[break] The ocean + display('''You're standing on a narrow stretch of beach. The ocean sparkles to the north, there's a cliff face just to the south. The - beach extends [green>westwardwestward> } enter { + } } diff --git a/src/parser.l b/src/parser.l index 7957c53..7ceee0a 100644 --- a/src/parser.l +++ b/src/parser.l @@ -42,6 +42,7 @@ if { return tokIf; } then { return tokThen; } else { return tokElse; } command { return tokCommand; } +option { return tokOption; } goto { return tokGoto; } not { return tokNot; } setup { return tokSetup; } @@ -49,6 +50,7 @@ enter { return tokEnter; } and { return tokAnd; } or { return tokOr; } return { return tokReturn; } +ignore { return tokIgnore; } true { yylval->bValue = true; return tokBool; } false { yylval->bValue = false; return tokBool; } diff --git a/src/parser.y b/src/parser.y index 2aff29c..e127627 100644 --- a/src/parser.y +++ b/src/parser.y @@ -58,11 +58,13 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, GameBuilder &, const char *err %token tokElse %token tokNot %token tokCommand +%token tokOption %token tokPlayer %token tokLtEq %token tokGtEq %token tokCmp %token tokReturn +%token tokIgnore %token tokPlusAssign %token tokMinusAssign %token tokTimesAssign @@ -108,6 +110,7 @@ globalExprList: cmpltGlobalExpr: globalExpr ';' | commandDecl + | ignoreDecl ; globalExpr: tokIdent '=' expr @@ -118,12 +121,19 @@ bodyDecl: | bodyDecl function ; -situation: tokSituation tokSituationName { bld.beginSituation( *($2) ); } '{' situationMembers '}' { bld.endSituation(); } +situationMode: tokSituation tokSituationName { bld.beginSituation( *($2) ); } + | tokCommand tokSituation tokSituationName { bld.beginSituation( *($2) ); } + | tokOption tokSituation tokSituationName { bld.beginSituation( *($2) ); } + ; + +situation: situationMode '{' situationMembers '}' { bld.endSituation(); } ; situationMembers: | situationMembers situationModeFunc | situationMembers commandDecl + | situationMembers optionDecl + | situationMembers ignoreDecl ; situationModeFunc: situationMode '{' cmpltExprList '}' { @@ -274,6 +284,9 @@ dictValues: expr ':' expr { bld.addNode( AstNode::tInsert ); } | dictValues ',' expr ':' expr { bld.addNode( AstNode::tInsert ); } ; +optionDecl: tokOption ':' tokString '{' cmpltExprList '}' + ; + commandDecl: tokCommand ':' tokString { bld.beginCommand( *$3 ); } commandParamList '{' { bld.endCommandParams(); } cmpltExprList '}' { bld.closeCommand(); } ; @@ -282,6 +295,13 @@ commandParamList: | commandParamList tokString { bld.addCommandLiteral( *$2 ); } | commandParamList tokIdent { bld.addCommandParam( *$2 ); } ; + +ignoreDecl: tokIgnore ':' tokString ignoreList ';' + ; + +ignoreList: + | ignoreList tokString + ; %% /* void yylex_init( yyscan_t * ); diff --git a/support/vim/syntax/stage.vim b/support/vim/syntax/stage.vim index 45e1346..13d86b4 100644 --- a/support/vim/syntax/stage.vim +++ b/support/vim/syntax/stage.vim @@ -19,7 +19,7 @@ syn keyword Statement setup enter syn keyword Todo TODO FIXME XXX syn keyword Type function command situation game global player syn keyword Constant null true false -syn keyword Builtins display goto exists delete exit return random integer float +syn keyword Builtins display goto exists delete exit return random integer float string debugString keys join syn cluster CommentGroup contains=Todo -- cgit v1.2.3