43 using namespace infact;
46 main(
int argc,
char **argv) {
47 cerr <<
"Testing StreamTokenizer with string arg constructor:" << endl;
48 std::string test_string =
"foo(bar, baz(34), bleh(\"fleh with spaces\"))";
54 cout <<
"token: \"" << st1.
Next() <<
"\""
55 <<
"; type=" << StreamTokenizer::TypeName(type)
56 <<
"; start=" << start
57 <<
"; line=" << line_number
59 cout <<
"chars so far: '" << st1.
str() <<
"'" << endl;
61 cerr <<
"Done." << endl;
63 cerr <<
"\nTesting Putback:" << endl;
69 cout <<
"token: \"" << st1.
Next() <<
"\""
70 <<
"; type=" << StreamTokenizer::TypeName(type)
71 <<
"; start=" << start
72 <<
"; line=" << line_number
74 cout <<
"chars so far: '" << st1.
str() <<
"'" << endl;
77 cerr <<
"\nTesting Rewind(3):" << endl;
83 cout <<
"token: \"" << st1.
Next() <<
"\""
84 <<
"; type=" << StreamTokenizer::TypeName(type)
85 <<
"; start=" << start
86 <<
"; line=" << line_number
88 cout <<
"chars so far: '" << st1.
str() <<
"'" << endl;
91 cerr <<
"Testing Rewind():" << endl;
97 cout <<
"token: \"" << st1.
Next() <<
"\""
98 <<
"; type=" << StreamTokenizer::TypeName(type)
99 <<
"; start=" << start
100 <<
"; line=" << line_number
102 cout <<
"chars so far: '" << st1.
str() <<
"'" << endl;
105 cerr <<
"\nReading from stdin until EOF:" << endl;
110 cout <<
"token: \"" << st2.
Next() <<
"\""
111 <<
"; type=" << StreamTokenizer::TypeName(type) << endl;
string Next()
Returns the next token in the token stream.
int main(int argc, char **argv)
TokenType PeekTokenType() const
Returns the type of the next token, or EOF_TYPE if there is no next token.
void Putback()
A synonym for Rewind(1).
string str()
Returns the entire sequence of characters read so far by this stream tokenizer as a newly constructed...
A simple class for tokenizing a stream of tokens for the formally specified language used to construc...
bool HasNext() const
Returns whether there is another token in the token stream.
Provides the StreamTokenizer class.
size_t PeekTokenStart() const
Returns the next token’s start position, or the byte position of the underlying byte stream if there ...
size_t PeekTokenLineNumber() const
Returns the line number of the first byte of the next token, or the current line number of the underl...
TokenType
The set of types of tokens read by this stream tokenizer.
void Rewind()
Rewinds this token stream to the beginning.