summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/common.hpp12
-rw-r--r--src/parse/expr.cpp13
-rw-r--r--src/parse/root.cpp10
3 files changed, 29 insertions, 6 deletions
diff --git a/src/parse/common.hpp b/src/parse/common.hpp
index 38ef3c96..ff72920c 100644
--- a/src/parse/common.hpp
+++ b/src/parse/common.hpp
@@ -4,12 +4,16 @@
#define GET_TOK(tok, lex) ((tok = lex.getToken()).type())
#define GET_CHECK_TOK(tok, lex, exp) do {\
- if((tok = lex.getToken()).type() != exp) \
- throw ParseError::Unexpected(lex, tok, Token(exp));\
+ if((tok = lex.getToken()).type() != exp) { \
+ DEBUG("GET_CHECK_TOK " << __FILE__ << ":" << __LINE__); \
+ throw ParseError::Unexpected(lex, tok, Token(exp));\
+ }\
} while(0)
#define CHECK_TOK(tok, exp) do {\
- if(tok.type() != exp) \
- throw ParseError::Unexpected(lex, tok, Token(exp));\
+ if(tok.type() != exp) { \
+ DEBUG("CHECK_TOK " << __FILE__ << ":" << __LINE__); \
+ throw ParseError::Unexpected(lex, tok, Token(exp));\
+ } \
} while(0)
enum eParsePathGenericMode
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp
index 1a9b494c..0bebbc64 100644
--- a/src/parse/expr.cpp
+++ b/src/parse/expr.cpp
@@ -229,8 +229,18 @@ ExprNodeP Parse_Stmt(TokenStream& lex, bool& opt_semicolon)
lex.putback(tok);
opt_semicolon = true;
return Parse_ExprBlockNode(lex);
+ case TOK_RWORD_CONST: {
+ opt_semicolon = false;
+ GET_CHECK_TOK(tok, lex, TOK_IDENT);
+ ::std::string name = tok.str();
+ GET_CHECK_TOK(tok, lex, TOK_COLON);
+ TypeRef type = Parse_Type(lex);
+ GET_CHECK_TOK(tok, lex, TOK_EQUAL);
+ auto val = Parse_Expr1(lex);
+ return NEWNODE( AST::ExprNode_Const, ::std::move(name), ::std::move(type), ::std::move(val) );
+ }
case TOK_RWORD_LET: {
- //ret.append();
+ opt_semicolon = false;
AST::Pattern pat = Parse_Pattern(lex);
TypeRef type;
if( GET_TOK(tok, lex) == TOK_COLON ) {
@@ -241,7 +251,6 @@ ExprNodeP Parse_Stmt(TokenStream& lex, bool& opt_semicolon)
CHECK_TOK(tok, TOK_EQUAL);
}
ExprNodeP val = Parse_ExprBlocks(lex);
- opt_semicolon = false;
return NEWNODE( AST::ExprNode_LetBinding, ::std::move(pat), ::std::move(type), ::std::move(val) );
}
case TOK_RWORD_RETURN:
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index 8f5bc737..b6b7af15 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -658,6 +658,7 @@ AST::Enum Parse_EnumDef(TokenStream& lex, const AST::MetaItems meta_items)
/// Parse a meta-item declaration (either #![ or #[)
AST::MetaItem Parse_MetaItem(TokenStream& lex)
{
+ TRACE_FUNCTION;
Token tok;
GET_CHECK_TOK(tok, lex, TOK_IDENT);
::std::string name = tok.str();
@@ -681,6 +682,7 @@ AST::MetaItem Parse_MetaItem(TokenStream& lex)
AST::Impl Parse_Impl(TokenStream& lex)
{
+ TRACE_FUNCTION;
Token tok;
AST::TypeParams params;
@@ -719,8 +721,16 @@ AST::Impl Parse_Impl(TokenStream& lex)
AST::Impl impl( ::std::move(params), ::std::move(impl_type), ::std::move(trait_type) );
// A sequence of method implementations
+ AST::MetaItems item_attrs;
while( GET_TOK(tok, lex) != TOK_BRACE_CLOSE )
{
+ 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_public = false;
if(tok.type() == TOK_RWORD_PUB) {
is_public = true;