- }
- else if(finish)
- {
- if(token.str!=";")
- throw ParseError(get_location()+": Syntax error at token '"+token.str+"' (Expected a ';')", src, in.get_line_number());
- break;
- }
- else if(token.str=="{")
- sub=true;
- else if(token.str==";")
- break;
- else if(token.type==Token::INTEGER)
- result.args.push_back(Value(Value::INTEGER, token.str));
- else if(token.type==Token::FLOAT)
- result.args.push_back(Value(Value::FLOAT, token.str));
- else if(token.type==Token::STRING)
- result.args.push_back(Value(Value::STRING, token.str));
- else if(token.type==Token::IDENTIFIER)
- {
- if(token.str=="true")
- result.args.push_back(Value(Value::BOOLEAN, "1"));
- else if(token.str=="false")
- result.args.push_back(Value(Value::BOOLEAN, "0"));
- else
- result.args.push_back(Value(Value::ENUM, token.str));
- //result.args.push_back(resolve_identifiertoken.str);
- }
- else if(token.str=="")
- throw ParseError(src+": Unexcepted EOF", src, in.get_line_number());
- else
- throw ParseError(get_location()+": Syntax error", src, in.get_line_number());
- }
-
- return result;
-}
-
-Token Parser::parse_token()
-{
- int c=0;
- unsigned comment=0;
-
- // Skip over comments and whitespace
- while(in)
- {
- c=in.get();
- int next=in.peek();
-
- if(c=='/' && next=='/')
- comment=1;
- else if(c=='/' && next=='*')
- comment=2;
- else if(c=='\n' && comment==1)
- comment=0;
- else if(c=='*' && next=='/' && comment==2)
- comment=3;
- else if(comment==3) // Skip the second character of block comment end
- comment=0;
- else if(!isspace(c) && !comment)
- break;
- }
-
- if(comment) // Didn't hit any non-whitespace
- throw ParseError(src+": Unfinished comment", src, in.get_line_number());
-
- enum ParseState
- {
- INIT,
- SIGN,
- FLOATEXPINIT,
- FLOATEXPSIGN,
- STRING,
- ACCEPT,
- ZERO,
- DECIMAL,
- HEXADECIMAL,
- OCTAL,
- FLOAT,
- FLOATEXP,
- IDENTIFIER
- };
-
- static Token::Type token_type[]=
- {
- Token::SPECIAL,
- Token::SPECIAL,
- Token::SPECIAL,
- Token::SPECIAL,
- Token::STRING,
- Token::SPECIAL,
- Token::INTEGER,
- Token::INTEGER,
- Token::INTEGER,
- Token::INTEGER,
- Token::FLOAT,
- Token::FLOAT,
- Token::IDENTIFIER
- };
-
- ParseState state=INIT;
- string buf;
- bool escape=false;
-
- while(in)
- {
- if(state!=INIT)
- c=in.get();
- int next=in.peek();
-
- buf+=c;
-
- switch(state)
- {
- case INIT:
- if(c=='0')
- state=ZERO;
- else if(c=='-' || c=='+')
- state=SIGN;
- else if(c=='.')
- state=FLOAT;
- else if(c=='"')
- state=STRING;
- else if(c=='{' || c=='}' || c==';')
- return Token(Token::SPECIAL, string(1, c));
- else if(isdigit(c))
- state=DECIMAL;
- else if(isalpha(c))
- state=IDENTIFIER;