Exemplo n.º 1
0
    result_type operator() (argument_type line)
    {
        // parse for our symbols
        for( std::string::size_type pos = 0; (pos = line.find('$', pos)) != std::string::npos; pos++ )
        {
            std::string::size_type end = line.find(')', pos);

            std::string::iterator it_begin = line.begin() + pos;
            std::string::iterator it_end = line.begin() + end;

            std::string statement = line.substr(pos + 2, end - pos - 2);

            // check for commands
            std::string::size_type space_pos;
            if( (space_pos = statement.find_first_of(" )", 0)) != std::string::npos )
            {
                // space must come first
                if( statement[space_pos] == ' ' )
                {
                    // push the parser for this command
                    std::string command = statement.substr(0, space_pos);
                    parsers.push_back(parser_factory(command, symbols, parsers, input, output));
                    parsers.back()->operator()(line);

                    return true;
                }
            }

            symbol_map::const_iterator sym = symbols.find(statement);
            if( sym == symbols.end() )
                throw std::runtime_error(std::string("Unknown symbol encountered: ") + statement);

            line.replace(pos, end - pos + 1, sym->second);

            pos++;
        }

        if( m_should_output )
            output << line << "\n";

        return true;
    }