Example #1
0
    result_type operator() (argument_type line)
    {
        if( !m_parsing )
        {
            std::string::size_type start = line.find("$(IF ", 0);
            std::string::size_type end = line.find(')', start);

            std::string symbol = line.substr(start + 5, end - start - 5);

            // if the symbol exists in the map, parse normally until we hit $(END)
            // if it doesn't exist, skip until we hit $(END)
            m_output = symbols.find(symbol) != symbols.end();
            m_parsing = true;
        }
        else
        {
            // look for $(END)
            if( line.find("$(END)") != std::string::npos )
            {
                // stop parsing
                m_parsing = false;
                parsers.erase(parsers.end()-1);
                return true;
            }
            
            symbol_parser::m_should_output = m_output;
            return false;
        }

        return true;
    }
Example #2
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;
    }