diff options
author | John Hodge <tpg@mutabah.net> | 2015-03-18 22:13:17 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-03-18 22:13:17 +0800 |
commit | ca09043bcadaacd7256a9b5d60b2358434743da6 (patch) | |
tree | e731961dee9ff3a55a700ed9374681ab29c9c4ba /src | |
parent | 7c774049e8a539ee32923dfbf9ad0c0f36ab4323 (diff) | |
download | mrust-ca09043bcadaacd7256a9b5d60b2358434743da6.tar.gz |
super path in expr, byte literals, while disallow struct, todo struct match
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/common.hpp | 1 | ||||
-rw-r--r-- | src/parse/expr.cpp | 19 | ||||
-rw-r--r-- | src/parse/lex.cpp | 18 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/parse/common.hpp b/src/parse/common.hpp index ee334f01..3ee985c0 100644 --- a/src/parse/common.hpp +++ b/src/parse/common.hpp @@ -27,6 +27,7 @@ enum eParsePathGenericMode extern AST::MetaItem Parse_MetaItem(TokenStream& lex);
extern AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generic_mode);
+extern AST::Path Parse_PathFrom(TokenStream& lex, AST::Path src, eParsePathGenericMode generic_mode);
extern ::std::vector<TypeRef> Parse_Path_GenericList(TokenStream& lex);
extern TypeRef Parse_Type(TokenStream& lex);
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 4960d275..c588d3e8 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -202,6 +202,8 @@ AST::Pattern Parse_PatternReal_Path(TokenStream& lex, AST::Path path) {
case TOK_PAREN_OPEN:
return AST::Pattern(AST::Pattern::TagEnumVariant(), ::std::move(path), Parse_PatternList(lex));
+ case TOK_BRACE_OPEN:
+ throw ParseError::Todo(lex, "struct patterns");
default:
lex.putback(tok);
return AST::Pattern(AST::Pattern::TagValue(), NEWNODE(AST::ExprNode_NamedValue, ::std::move(path)));
@@ -517,7 +519,11 @@ ExprNodeP Parse_WhileStmt(TokenStream& lex, ::std::string lifetime) }
else {
lex.putback(tok);
- ExprNodeP cnd = Parse_Expr1(lex);
+ ExprNodeP cnd;
+ {
+ SET_PARSE_FLAG(lex, disallow_struct_literal);
+ cnd = Parse_Expr1(lex);
+ }
return NEWNODE( AST::ExprNode_Loop, lifetime, ::std::move(cnd), Parse_ExprBlockNode(lex) );
}
}
@@ -776,6 +782,7 @@ bool Parse_IsTokValue(eTokenType tok_type) case TOK_RWORD_TRUE:
case TOK_RWORD_FALSE:
case TOK_RWORD_SELF:
+ case TOK_RWORD_SUPER:
case TOK_RWORD_BOX:
case TOK_PAREN_OPEN:
return true;
@@ -1109,10 +1116,16 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) return rv;
}
+ case TOK_RWORD_SUPER:
+ GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON);
+ path = Parse_PathFrom(lex, AST::Path(AST::Path::TagSuper()), PATH_GENERIC_EXPR);
+ if(0)
case TOK_IDENT:
// Get path
- lex.putback(tok);
- path = Parse_Path(lex, false, PATH_GENERIC_EXPR);
+ {
+ lex.putback(tok);
+ path = Parse_Path(lex, false, PATH_GENERIC_EXPR);
+ }
if(0)
case TOK_DOUBLE_COLON:
path = Parse_Path(lex, true, PATH_GENERIC_EXPR);
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 1e5fb1cf..648792e9 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -393,6 +393,22 @@ Token Lexer::getTokenInt() } else { + if( str == "b" && ch == '\'' ) { + // Byte constant + ch = this->getc(); + if( ch == '\\' ) { + uint32_t val = this->parseEscape('\''); + if( this->getc() != '\'' ) + throw ParseError::Generic(*this, "Multi-byte character literal"); + return Token((uint64_t)val, CORETYPE_U8); + } + else { + if( this->getc() != '\'' ) + throw ParseError::Generic(*this, "Multi-byte character literal"); + return Token((uint64_t)ch, CORETYPE_U8); + } + } + this->ungetc(); for( unsigned int i = 0; i < LEN(RWORDS); i ++ ) { @@ -445,7 +461,7 @@ Token Lexer::getTokenInt() ch = this->getc(); if( ch == '\'' ) { // Character constant - return Token((uint64_t)ch, CORETYPE_CHAR); + return Token((uint64_t)firstchar, CORETYPE_CHAR); } else { // Lifetime name |