From 3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 30 Dec 2011 23:15:31 -0700 Subject: All variants of for each loop are tested and work --- src/gamestate.cpp | 18 ++++++++++++++---- src/variable.cpp | 5 +++++ src/variable.h | 1 + support/vim/syntax/stage.vim | 2 -- test.stage | 7 +++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 4af49aa..dcae848 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -428,8 +428,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) Variable y = popDeref(); Variable x = pop(); deref( x ) += y; -// VariableRef r = x.getVariableRef(); -// setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid ); } break; @@ -438,8 +436,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) Variable y = popDeref(); Variable x = pop(); deref( x ) -= y; -// VariableRef r = x.getVariableRef(); -// setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid ); } break; @@ -618,6 +614,20 @@ void GameState::parse( const AstBranch::NodeList &lCode ) parse( rDo ); } } + else if( vIn.getType() == Variable::tList ) + { + if( bUseKey ) + { + throw Bu::ExceptionBase("You cannot use key:value pairs as iterators in a for each loop iterating over a list."); + } + const Variable::VariableList &rList = vIn.getList(); + for( Variable::VariableList::const_iterator i = + rList.begin(); i; i++ ) + { + setVariable( vrValue.sName, *i, vrValue.sid ); + parse( rDo ); + } + } } break; diff --git a/src/variable.cpp b/src/variable.cpp index 0ce9793..5296848 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -113,6 +113,11 @@ Variable *Variable::getVariablePtr() const return pValue; } +const Variable::VariableList &Variable::getList() const +{ + return *lValue; +} + const Variable::VariableHash &Variable::getHash() const { return *hValue; diff --git a/src/variable.h b/src/variable.h index 22a1b26..8741b28 100644 --- a/src/variable.h +++ b/src/variable.h @@ -61,6 +61,7 @@ public: Bu::String getString() const; VariableRef getVariableRef() const; Variable *getVariablePtr() const; + const VariableList &getList() const; const VariableHash &getHash() const; Variable to( Type e ) const; diff --git a/support/vim/syntax/stage.vim b/support/vim/syntax/stage.vim index b18ec0d..34da126 100644 --- a/support/vim/syntax/stage.vim +++ b/support/vim/syntax/stage.vim @@ -21,8 +21,6 @@ syn keyword Type function command situation game global player syn keyword Constant null true false syn keyword Builtins display goto exists delete exit return -syn match TargetProcess /[a-zA-Z_][a-zA-Z0-9_]*:/he=e-1 - syn cluster CommentGroup contains=Todo syn match Special display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)" diff --git a/test.stage b/test.stage index 9e5c00a..deef755 100644 --- a/test.stage +++ b/test.stage @@ -28,6 +28,13 @@ situation <> display( lst ); lst -= 55; display( lst ); + lst += "hi"; + lst += "Things"; + display("---For each test---"); + for each x : y in dict do + { + display( x ); + } exit(); } -- cgit v1.2.3