Example #1
0
bool lex_stream_t::implementation_t::is_string(char c, stream_lex_token_t& result)
{
    if (c != '\'' && c != '\"') return false;
    
    identifier_buffer_m.clear();
    
    while (true)
    {
        char end_char (c);
        
        while (_super::get_char(c) && c != end_char)
        {
            // REVISIT (sparent) : Handle quoted characters here.
            // Also handle invalid characters such as line endings.
            identifier_buffer_m.push_back(c);
        }

        if (c != end_char) throw_parser_exception("Unexpected EOF in string.");
        
        if (!skip_space(c)) break;
        
        if (c != '\'' && c != '\"') 
        {
            _super::putback_char(c);
            break;
        }
    }
    
    identifier_buffer_m.push_back(0);
    result = stream_lex_token_t(string_k, any_regular_t(std::string(&identifier_buffer_m[0])));
    
    return true;
}
Example #2
0
bool lex_stream_t::implementation_t::is_comment(char c, stream_lex_token_t& result)
{
    if (c != '/') return false;
    
    std::istream::int_type peek_c (_super::peek_char());
    
    if (peek_c == EOF || (peek_c != '/' && peek_c != '*')) return false;

    (void)_super::get_char(c);

    identifier_buffer_m.clear();

    if (c == '/')
    {
        while (_super::get_char(c) && !is_line_end(c))
        {
            identifier_buffer_m.push_back(c);
        }

        identifier_buffer_m.push_back(0);
    
        result = stream_lex_token_t(trail_comment_k, any_regular_t(std::string(&identifier_buffer_m[0])));
    }
    else // if (c == '*')
    {
        while (true)
        {
            if (!_super::get_char(c))
                throw_parser_exception("Unexpected EOF in comment.");

            if (c == '*')
            {
                peek_c = _super::peek_char();

                if (peek_c != EOF && peek_c == '/')
                    { _super::ignore_char(); break; }
            }
            else if (is_line_end(c))
                { c = '\n'; }
                
            identifier_buffer_m.push_back(c);
        }
            
        identifier_buffer_m.push_back(0);
    
        result = stream_lex_token_t(lead_comment_k, any_regular_t(std::string(&identifier_buffer_m[0])));
    }
    
    return true;
    
}
Example #3
0
void lex_stream_t::implementation_t::parse_token(char c)
{
    stream_lex_token_t  result;
    
    if (!(  is_number(c, result)
        ||  is_identifier_or_keyword(c, result)
        ||  is_comment(c, result)
        ||  is_string(c,result)
        ||  is_compound(c, result)
        ||  is_simple(c, result)))
        { throw_parser_exception("Syntax Error"); }

    put_token(adobe::move(result));
}
inline void throw_parser_exception(name_t expected, name_t found, const line_position_t& position) {
    throw_parser_exception(expected.c_str(), found.c_str(), position);
}
void expression_parser::throw_exception(const name_t& found, const name_t& expected) {
    throw_parser_exception(found, expected, next_position());
}
void expression_parser::throw_exception(const char* errorString) {
    throw_parser_exception(errorString, next_position());
}