33 #ifndef WALLAROO_DETAIL_TOKENSOURCE_H_
34 #define WALLAROO_DETAIL_TOKENSOURCE_H_
66 Token(
Type t,
const std::string& l = std::string() ) : type( t ), lexem( l ) {}
72 case load:
return "@load";
break;
73 case create:
return "new";
break;
74 case open:
return "(";
break;
75 case close:
return ")";
break;
76 case stmtsep:
return ";";
break;
77 case attrsep:
return ",";
break;
78 case assign:
return "=";
break;
79 case collsep:
return ".";
break;
80 case id:
return "<id>";
break;
81 case value:
return "<value>";
break;
82 case done:
return "<EOF>";
break;
94 explicit TokenSource( std::istream& in ) : input( in ), lineno( 1 ), column( 1 ) {}
100 char c = input.peek();
103 case ' ':
case '\t': Consume();
break;
104 case '\n': NewLine(); Consume();
break;
117 if ( input.peek() ==
'\'' ) Consume();
118 else throw LexicalError(
"Missing terminating char closing", lineno, column );
127 while ( c !=
'"' && !input.eof() && c !=
'\n' )
133 if ( c ==
'"' ) Consume();
134 else throw LexicalError(
"Missing terminating string closing", lineno, column );
140 while ( c !=
'\n' && !input.eof() )
155 if ( isalpha( c ) || c ==
'_' )
158 while ( isalnum( c ) || c ==
'_' || c ==
':' || c ==
'<' || c ==
'>' )
171 while (isalnum(c) || c ==
'@')
178 throw LexicalError(
"Invalid keyword:" +
id, lineno, column);
180 else if ( input.eof() )
182 else if ( isdigit( c ) || c ==
'-' || c ==
'+' )
185 std::size_t sepcount = 0;
191 while ( isdigit( c ) || c ==
'.' )
194 if ( ++sepcount > 1 )
195 throw LexicalError(
"Floating point invalid (too many '.')", lineno, column );
203 throw LexicalError(
"Unrecognized character", lineno, column );
209 std::size_t
Line()
const {
return lineno; }
210 std::size_t
Col()
const {
return column; }
231 #endif // WALLAROO_DETAIL_TOKENSOURCE_H_
Definition: tokensource.h:57
std::size_t Line() const
Definition: tokensource.h:209
Definition: tokensource.h:48
Type type
Definition: tokensource.h:64
std::string lexem
Definition: tokensource.h:65
static std::string Description(Type t)
Definition: tokensource.h:68
Definition: tokensource.h:52
Definition: tokensource.h:62
Definition: exceptions.h:217
Definition: tokensource.h:55
Token(Type t, const std::string &l=std::string())
Definition: tokensource.h:66
TokenSource(std::istream &in)
Definition: tokensource.h:94
Definition: tokensource.h:59
Definition: tokensource.h:56
Definition: tokensource.h:91
Definition: attribute.h:45
Definition: tokensource.h:54
Definition: tokensource.h:61
std::size_t Col() const
Definition: tokensource.h:210
Token Next()
Definition: tokensource.h:96
Definition: tokensource.h:58
Definition: tokensource.h:60
Type
Definition: tokensource.h:51
Definition: tokensource.h:53