From 0c2d1d043d71450ea5087937c97af4c12c6d33fc Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 17 Mar 2015 14:11:00 +0800 Subject: Hack in hex character literals --- src/parse/lex.cpp | 14 ++++++++++++-- src/parse/root.cpp | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') 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 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; -- cgit v1.2.3