Esempio n. 1
0
std::string GG::WriteExpression(const adobe::array_t& expression)
{
    std::string retval;
    adobe::array_t::const_reverse_iterator it = expression.rbegin();
    adobe::array_t::const_reverse_iterator end_it = expression.rend();
    WriteExpressionImpl(it, end_it, retval);
    return retval;
}
Esempio n. 2
0
std::string GG::WriteStatement(const adobe::array_t& statement, unsigned int indent/* = 0*/)
{
    std::string retval;
    adobe::array_t::const_reverse_iterator it = statement.rbegin();
    adobe::array_t::const_reverse_iterator end_it = statement.rend();
    WriteStatementImpl(it, end_it, retval, indent);
    return retval;
}
Esempio n. 3
0
    bool TestExpression(const lexer& lexer_,
                        const expression_parser_rules& parser_rules,
                        adobe::array_t& new_parsed_expression,
                        AdobeParserType adobe_parse,
                        const std::string& expression)
    {
        std::cout << "expression: \"" << expression << "\"\n";
        adobe::array_t original_parsed_expression;
        bool original_parse_failed = false;
        try {
            original_parsed_expression = adobe_parse(expression);
        } catch (const adobe::stream_error_t&) {
            original_parse_failed = true;
        }
        std::cout << "original: <parse " << (original_parse_failed ? "failure" : "success") << ">\n";
        using boost::spirit::qi::phrase_parse;
        text_iterator it(expression.begin());
        detail::s_text_it = &it;
        detail::s_begin = it;
        detail::s_end = text_iterator(expression.end());
        detail::s_filename = "test_expression";
        token_iterator iter = lexer_.begin(it, detail::s_end);
        token_iterator end = lexer_.end();
        bool new_parse_failed =
            !phrase_parse(iter,
                          end,
                          parser_rules.expression(boost::phoenix::ref(new_parsed_expression)),
                          boost::spirit::qi::in_state("WS")[lexer_.self]);
        std::cout << "new:      <parse " << (new_parse_failed ? "failure" : "success") << ">\n";
        bool pass =
            original_parse_failed && new_parse_failed ||
            new_parsed_expression == original_parsed_expression;

        if (pass) {
            std::string rewritten_expression = GG::WriteExpression(new_parsed_expression);
            std::cout << "Rewrite:    " << rewritten_expression << '\n';
            try {
                adobe::array_t round_trip_parsed_expression = adobe_parse(rewritten_expression);
                pass &= round_trip_parsed_expression == new_parsed_expression;
            } catch (const adobe::stream_error_t&) {
                pass = new_parsed_expression.empty();
            }
        }

        std::cout << "Round-trip parse: " << (pass ? "PASS" : "FAIL") << '\n';

        std::cout << "\n";
        new_parsed_expression.clear();

        return pass;
    }
Esempio n. 4
0
    bool TestExpression(const lexer& lexer_,
                        const expression_parser_rules& parser_rules,
                        adobe::array_t& new_parsed_expression,
                        AdobeParserType adobe_parse,
                        const std::string& expression)
    {
        std::cout << "expression: \"" << expression << "\"\n";
        adobe::array_t original_parsed_expression;
        bool original_parse_failed = false;
        try {
            original_parsed_expression = adobe_parse(expression);
        } catch (const adobe::stream_error_t&) {
            original_parse_failed = true;
        }
        if (original_parse_failed)
            std::cout << "original: <parse failure>\n";
        else
            std::cout << "original: " << original_parsed_expression << "\n";
        using boost::spirit::qi::phrase_parse;
        text_iterator it(expression.begin());
        detail::s_text_it = &it;
        detail::s_begin = it;
        detail::s_end = text_iterator(expression.end());
        detail::s_filename = "test_expression";
        token_iterator iter = lexer_.begin(it, detail::s_end);
        token_iterator end = lexer_.end();
        bool new_parse_failed =
            !phrase_parse(iter,
                          end,
                          parser_rules.expression(boost::phoenix::ref(new_parsed_expression)),
                          boost::spirit::qi::in_state("WS")[lexer_.self]);
        if (new_parse_failed)
            std::cout << "new:      <parse failure>\n";
        else
            std::cout << "new:      " << new_parsed_expression << "\n";
        bool pass =
            original_parse_failed && new_parse_failed ||
            new_parsed_expression == original_parsed_expression;
        std::cout << (pass ? "PASS" : "FAIL") << "\n";

        if (!pass) {
            std::cout << "original (verbose):\n";
            verbose_dump(original_parsed_expression);
            std::cout << "new (verbose):\n";
            verbose_dump(new_parsed_expression);
        }

        std::cout << "\n";
        new_parsed_expression.clear();

        return pass;
    }