| 37 | ScriptParser::ScriptParser() {} |
| 38 | |
| 39 | ConcreteNodeListPtr ScriptParser::parse( const ScriptTokenListPtr &tokens, const String &sourceFile ) |
| 40 | { |
| 41 | // MEMCATEGORY_GENERAL because SharedPtr can only free using that category |
| 42 | ConcreteNodeListPtr nodes( OGRE_NEW_T( ConcreteNodeList, MEMCATEGORY_GENERAL )(), |
| 43 | SPFM_DELETE_T ); |
| 44 | |
| 45 | enum |
| 46 | { |
| 47 | READY, |
| 48 | OBJECT |
| 49 | }; |
| 50 | uint32 state = READY; |
| 51 | |
| 52 | ConcreteNode *parent = 0; |
| 53 | ConcreteNodePtr node; |
| 54 | const ScriptToken *token = 0; |
| 55 | ScriptTokenList::iterator i = tokens->begin(), end = tokens->end(); |
| 56 | while( i != end ) |
| 57 | { |
| 58 | token = &*i; |
| 59 | |
| 60 | switch( state ) |
| 61 | { |
| 62 | case READY: |
| 63 | if( token->type == TID_WORD ) |
| 64 | { |
| 65 | if( token->lexemeEquals( "import" ) ) |
| 66 | { |
| 67 | node = ConcreteNodePtr( OGRE_NEW ConcreteNode() ); |
| 68 | node->token = token->lexeme(); |
| 69 | node->file = sourceFile; |
| 70 | node->line = token->line; |
| 71 | node->type = CNT_IMPORT; |
| 72 | |
| 73 | // The next token is the target |
| 74 | ++i; |
| 75 | if( i == end || ( i->type != TID_WORD && i->type != TID_QUOTE ) ) |
| 76 | { |
| 77 | OGRE_EXCEPT( Exception::ERR_INVALID_STATE, |
| 78 | Ogre::String( "expected import target at line " ) + |
| 79 | Ogre::StringConverter::toString( node->line ), |
| 80 | "ScriptParser::parse" ); |
| 81 | } |
| 82 | ConcreteNodePtr temp( OGRE_NEW ConcreteNode() ); |
| 83 | temp->parent = node.get(); |
| 84 | temp->file = sourceFile; |
| 85 | temp->line = i->line; |
| 86 | temp->type = i->type == TID_WORD ? CNT_WORD : CNT_QUOTE; |
| 87 | temp->token = i->lexeme( temp->type == CNT_QUOTE ); |
| 88 | node->children.push_back( temp ); |
| 89 | |
| 90 | // The second-next token is the source |
| 91 | ++i; |
| 92 | ++i; |
| 93 | if( i == end || ( i->type != TID_WORD && i->type != TID_QUOTE ) ) |
| 94 | { |
| 95 | OGRE_EXCEPT( Exception::ERR_INVALID_STATE, |
| 96 | Ogre::String( "expected import source at line " ) + |
no test coverage detected