| 72 | { } |
| 73 | |
| 74 | void ParseHelper::process( const std::string& str ) |
| 75 | { |
| 76 | std::string top; |
| 77 | commandBuffer.push_back(str); |
| 78 | //std::string top = commandBuffer.back(); |
| 79 | //commandBuffer.pop_back(); |
| 80 | std::shared_ptr<ParseState> blockStatePtr; |
| 81 | while (stateStack.size()) |
| 82 | { |
| 83 | top = commandBuffer.back(); |
| 84 | commandBuffer.pop_back(); |
| 85 | blockStatePtr = stateStack.back(); |
| 86 | if (blockStatePtr->process(top)) |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | if ( ! commandBuffer.size() ) |
| 91 | return; |
| 92 | |
| 93 | // standard state |
| 94 | top = commandBuffer.back(); |
| 95 | if ( !top.size() ) |
| 96 | { |
| 97 | reset( ); |
| 98 | broadcast( std::string() ); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | { // check for unexpected indent |
| 103 | Indent ind; |
| 104 | bool isIndented = PeekIndent( top, &ind ); |
| 105 | if ( isIndented && |
| 106 | ! isInContinuation( ) ) |
| 107 | { |
| 108 | reset( ); |
| 109 | ParseMessage msg( 1, "IndentationError: unexpected indent"); |
| 110 | broadcast( msg ); |
| 111 | return; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // enter indented block state |
| 116 | if ( top[top.size()-1] == ':' ) |
| 117 | { |
| 118 | std::shared_ptr<ParseState> parseState( |
| 119 | new BlockParseState( *this ) ); |
| 120 | stateStack.push_back( parseState ); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if ( top[top.size()-1] == '\\' ) |
| 125 | { |
| 126 | std::shared_ptr<ParseState> parseState( |
| 127 | new ContinuationParseState( *this ) ); |
| 128 | stateStack.push_back( parseState ); |
| 129 | return; |
| 130 | } |
| 131 | |