summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-04-04 16:32:21 +0800
committerJohn Hodge <tpg@mutabah.net>2015-04-04 16:32:21 +0800
commit1e02026fb0edb878361c1b7f59d30dae02f4abc9 (patch)
tree3ab5580ee9601fd5dd82ff2c3b60afbf25b0dd14
parentc744ebf392209f1dc7dda8900d1e0b16823b55bd (diff)
downloadmrust-1e02026fb0edb878361c1b7f59d30dae02f4abc9.tar.gz
Lexer - Handle integer suffixes
-rw-r--r--src/parse/lex.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp
index c81c3149..c246bbc0 100644
--- a/src/parse/lex.cpp
+++ b/src/parse/lex.cpp
@@ -307,7 +307,7 @@ Token Lexer::getTokenInt()
}
else if( isdigit(ch) ) {
num_mode = OCT;
- throw ParseError::Todo("Lex octal numbers");
+ throw ParseError::Todo(*this, "Lex octal numbers");
}
else {
num_mode = DEC;
@@ -318,13 +318,34 @@ Token Lexer::getTokenInt()
while( isdigit(ch) ) {
val *= 10;
val += ch - '0';
- ch = this->getc();
+ ch = this->getc_num();
}
}
if(ch == 'u' || ch == 'i') {
// Unsigned
- throw ParseError::Todo("Lex number suffixes");
+ ::std::string suffix;
+ while( issym(ch) )
+ {
+ suffix.push_back(ch);
+ ch = this->getc();
+ }
+ this->ungetc();
+
+ if(0) ;
+ else if(suffix == "i8") num_type = CORETYPE_I8;
+ else if(suffix == "i16") num_type = CORETYPE_I16;
+ else if(suffix == "i32") num_type = CORETYPE_I32;
+ else if(suffix == "i64") num_type = CORETYPE_I64;
+ else if(suffix == "isize") num_type = CORETYPE_INT;
+ else if(suffix == "u8") num_type = CORETYPE_U8;
+ else if(suffix == "u16") num_type = CORETYPE_U16;
+ else if(suffix == "u32") num_type = CORETYPE_U32;
+ else if(suffix == "u64") num_type = CORETYPE_U64;
+ else if(suffix == "usize") num_type = CORETYPE_UINT;
+ else
+ throw ParseError::Generic(*this, FMT("Unknown integer suffix '" << suffix << "'"));
+ return Token(val, num_type);
}
else if( ch == '.' ) {
if( num_mode != DEC )
@@ -361,15 +382,12 @@ Token Lexer::getTokenInt()
ch = this->getc();
}
this->ungetc();
- if( suffix == "f32" ) {
- num_type = CORETYPE_F32;
- }
- else if( suffix == "f64" ) {
- num_type = CORETYPE_F64;
- }
- else {
+
+ if(0) ;
+ else if(suffix == "f32") num_type = CORETYPE_F32;
+ else if(suffix == "f64") num_type = CORETYPE_F64;
+ else
throw ParseError::Generic( FMT("Unknown number suffix " << suffix) );
- }
}
else
{