示例#1
0
void
TokenStream::consumeSymbol(Value* output, int match)
{
    Value next;
    getNextStr(&next);
    set_symbol_from_string(output, &next);
    consume(match);
}
示例#2
0
std::string
TokenStream::consumeStr(int match)
{
    Value next;
    getNextStr(&next);
    std::string out = as_cstring(&next);
    consume(match);
    return out;
}
示例#3
0
bool TokenStream::nextEqualsString(const char* str, int lookahead)
{
    if ((this->_position + lookahead) >= tokens.size())
        return false;

    Value next;
    getNextStr(&next, lookahead);
    return string_equals(&next, str);
}
示例#4
0
void
TokenStream::consumeStr(Value* output, int match)
{
    if (!is_string(output))
        set_string(output, "");

    Value next;
    getNextStr(&next);
    string_append(output, &next);
    consume(match);
}
示例#5
0
void TokenStream::dump()
{
    int lookbehind = 5;
    int lookahead = 15;
    for (int i=-lookbehind; i < lookahead; i++) {
        int index = position() + i;
        if (index < 0) continue;
        if (index >= length()) continue;

        Value nextStr;
        getNextStr(&nextStr, i);
        printf("[%d] %s '%s'\n", i, get_token_text(next(i).match), as_cstring(&nextStr));
    }
}
示例#6
0
void
TokenStream::consume(int match)
{
    if (finished())
        internal_error(std::string("Unexpected EOF while looking for ")
                + get_token_text(match));

    if ((match != -1) && next().match != match) {
        std::stringstream msg;
        Value nextStr;
        getNextStr(&nextStr);
        msg << "Unexpected token (expected " << get_token_text(match)
            << ", found " << get_token_text(next().match)
            << " '" << as_cstring(&nextStr) << "')";
        internal_error(msg.str());
    }

    _position++;
}
示例#7
0
void
TokenStream::consumeStr(caValue* output, int match)
{
    getNextStr(output, 0);
    consume(match);
}