43 if (outputstream) fprintf(outputstream,
"\\\n");
45 else {ungetc(c,inputstream); c=
'\\';}
53 while ((c=fgetc(inputstream)) !=
']' || lc!=
']') lc=c;
57 {ungetc(c,inputstream); c=
'[';}
63 if (outputstream &&!feof(inputstream))
64 fputc(c,outputstream);
69 string token, lasttoken, tokenBeforeLast;
70 tokeninput(FILE* in, FILE* out=NULL)
71 {inputstream=in; outputstream=out; getnextc(); lineno=1;}
73 int line()
const {
return lineno;}
79 friend class tokeninput::mark_t ;
84 token.swap(lasttoken);
85 token.swap(tokenBeforeLast);
89 if (feof(inputstream))
throw eof();
92 while (isspace(c)) getnextc();
95 while (c!=
'\n' && !feof(inputstream))
97 if (c!=
'\r') token+=c;
98 if (c==
'/' && getnextc()==
'*')
99 for (
char l=getnextc(); l!=
'*' || c!=
'/'; l=c, getnextc());
102 if (token.find(
"#pragma")==0)
106 while (isspace(c)) getnextc();
108 if (feof(inputstream))
throw eof();
110 if (c==
'"' || c==
'\'')
117 escape=c==
'\\' && !escape;
120 while (c!=terminal || escape);
124 else if (strchr(
"#\\!@$~(){}[]:;,.?%*|-+=<>^&/",c))
132 if (c==
'=' && !strchr(
"#\\!@$~(){}[]:;,.?",lc))
140 case '<':
case '>':
case '|':
case '&':
141 case '+':
case '-':
case ':':
146 if ((lc==
'<' || lc==
'>') && c==
'=')
152 else if (lc==
'-' && c==
'>')
200 while (lc!=
'*' || c!=
'/')
210 while (c!=
'\n') getnextc();
216 else if (!isalnum(c) && c!=
'_')
223 while (isalnum(c) || c==
'_')
235 friend void tokeninput::operator=(mark_t& x);
236 friend int tokeninput::operator>(mark_t& x);
241 mark_t(tokeninput& x): tokinp(x)
245 fgetpos(x.inputstream,&fp);
247 offset=ftell(x.inputstream);
251void tokeninput::operator=(
mark_t& x)
255 if (fseek(inputstream,x.offset,SEEK_SET))
throw eof();
257 if (fsetpos(inputstream,&(x.fp)))
throw eof();
261int tokeninput::operator>(mark_t& x)
262{
return ftell(inputstream) > x.offset;}
266inline int isalpha(
char x)
267{
return x==
'_' || (x>=
'a' && x<=
'z') || (x>=
'A' && x<=
'Z');}
271template <
class K,
class T>
class hash_map:
public map<K,T> {};
272template <
class K>
class hash_set:
public set<K> {};
275string gobble_delimited(
tokeninput& input,
const char *left,
277{
string argList = input.lasttoken;
278 argList +=
" " + input.token +
" ";
280 string tmp=(string)left+right;
281 if (input.token==tmp)
return argList;
282 for (input.nexttok(); input.token!=right || delim_count>0;
285 argList += input.token +
" ";
286 if (input.token==left) delim_count++;
287 if (input.token==right) delim_count--;
288 if (input.token==
">>" &&
string(left)==
"<")
291 if (delim_count<=0)
break;
301 size_t angle_count=0;
305 if (input.token[0]==
'=')
306 while (!strchr(
">,",input.token[0]))
308 if (input.token[0]==
'<') gobble_delimited(input,
"<",
">");
311 targs += input.token;
312 if (input.token!=
".") targs+=
" ";
313 if (input.token[0]==
'<') angle_count+=input.token.length();
314 else if (input.token[0]==
'>')
315 angle_count-=input.token.length();
318 while (angle_count>0);
Definition tokeninput.h:271
Definition tokeninput.h:272