void parse_string_as_argument_list(caValue* str, List* output) { // Read the tokens as a space-seperated list of strings. // TODO is to be more smart about word boundaries: spaces inside // quotes or parentheses shouldn't break apart items. TokenStream tokens; tokens.reset(as_cstring(str)); Value itemInProgress; set_string(&itemInProgress, ""); while (!tokens.finished()) { if (tokens.nextIs(tok_Whitespace)) { if (!equals_string(&itemInProgress, "")) { copy(&itemInProgress, list_append(output)); set_string(&itemInProgress, ""); } } else { string_append(&itemInProgress, tokens.nextStr().c_str()); } tokens.consume(); } if (!equals_string(&itemInProgress, "")) { copy(&itemInProgress, list_append(output)); set_string(&itemInProgress, ""); } }
void print_remaining_tokens(std::ostream& out, TokenStream& tokens) { for (int i=0; i < tokens.remaining(); i++) { if (i != 0) out << " "; out << get_token_text(tokens.next(i).match); out << "(" << tokens.nextStr(i) << ")"; } }