diff options
author | John Hodge <tpg@mutabah.net> | 2015-03-17 14:11:00 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-03-17 14:11:00 +0800 |
commit | 0c2d1d043d71450ea5087937c97af4c12c6d33fc (patch) | |
tree | 650ea831a04f7ea3e2cf2d866ff39e174be5496e | |
parent | 80e44173b4abef7238304fbaf1182862144b62b1 (diff) | |
download | mrust-0c2d1d043d71450ea5087937c97af4c12c6d33fc.tar.gz |
Hack in hex character literals
-rw-r--r-- | src/parse/lex.cpp | 14 | ||||
-rw-r--r-- | src/parse/root.cpp | 8 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 17eb4f30..4237b48f 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -240,7 +240,7 @@ Token Lexer::getToken() ch = this->getc(); if( ch == 'x' ) { num_mode = HEX; - while( isxdigit(ch = this->getc()) ) + while( isxdigit(ch = this->getc_num()) ) { val *= 16; if(ch <= '9') @@ -253,7 +253,16 @@ Token Lexer::getToken() } else if( ch == 'b' ) { num_mode = BIN; - throw ParseError::Todo("Lex binary numbers"); + while( isdigit(ch = this->getc_num()) ) + { + val *= 2; + if(ch == '0') + val += 0; + else if( ch == '1' ) + val += 1; + else + throw ParseError::Generic("Invalid digit in binary literal"); + } } else if( isdigit(ch) ) { num_mode = OCT; @@ -487,6 +496,7 @@ uint32_t Lexer::parseEscape(char enclosing) char ch = this->getc(); switch(ch) { + case 'x': case 'u': { // Unicode (up to six hex digits) uint32_t val = 0; diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 55f6f21c..b67f620c 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -651,6 +651,14 @@ void Parse_Struct(AST::Module& mod, TokenStream& lex, const bool is_public, cons ::std::vector<AST::StructItem> items;
while( GET_TOK(tok, lex) != TOK_BRACE_CLOSE )
{
+ AST::MetaItems item_attrs;
+ while( tok.type() == TOK_ATTR_OPEN )
+ {
+ item_attrs.push_back( Parse_MetaItem(lex) );
+ GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE);
+ GET_TOK(tok, lex);
+ }
+
bool is_pub = false;
if(tok.type() == TOK_RWORD_PUB) {
is_pub = true;
|