summaryrefslogtreecommitdiff
path: root/parse/root.cpp
diff options
context:
space:
mode:
authorJohn Hodge (bugs) <tpg@mutabah.net>2014-12-07 09:46:00 +0800
committerJohn Hodge (bugs) <tpg@mutabah.net>2014-12-07 09:46:00 +0800
commitc325b671c1a44c90c8ce570b901219bcc2ae0a38 (patch)
tree5dff25da15192ad0b0635fa96bab5f510df018c6 /parse/root.cpp
parent1ac5429531c195755c7e1690912291e20e9a1717 (diff)
downloadmrust-c325b671c1a44c90c8ce570b901219bcc2ae0a38.tar.gz
Macro evaluation hacked in (... not quite in yet, but framework is there)
Macro definitions not implemented, evil hack to define try! is present
Diffstat (limited to 'parse/root.cpp')
-rw-r--r--parse/root.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/parse/root.cpp b/parse/root.cpp
index c82527a2..2dac321a 100644
--- a/parse/root.cpp
+++ b/parse/root.cpp
@@ -232,6 +232,8 @@ void Parse_TypeConds(TokenStream& lex, AST::TypeParams& params)
/// Parse a function definition (after the 'fn')
AST::Function Parse_FunctionDef(TokenStream& lex)
{
+ TRACE_FUNCTION;
+
Token tok;
// Name
@@ -254,12 +256,45 @@ AST::Function Parse_FunctionDef(TokenStream& lex)
else {
lex.putback(tok);
}
+
+ AST::Function::Class fcn_class = AST::Function::CLASS_UNBOUND;
GET_CHECK_TOK(tok, lex, TOK_PAREN_OPEN);
+ GET_TOK(tok, lex);
+ if( tok.type() == TOK_AMP )
+ {
+ // By-reference method
+ if( GET_TOK(tok, lex) == TOK_LIFETIME )
+ {
+ throw ParseError::Todo("Lifetimes on self in methods");
+ }
+ if( tok.type() == TOK_RWORD_MUT )
+ {
+ GET_CHECK_TOK(tok, lex, TOK_RWORD_SELF);
+ fcn_class = AST::Function::CLASS_MUTMETHOD;
+ }
+ else
+ {
+ CHECK_TOK(tok, TOK_RWORD_SELF);
+ fcn_class = AST::Function::CLASS_REFMETHOD;
+ }
+ GET_TOK(tok, lex);
+ }
+ else if( tok.type() == TOK_RWORD_SELF )
+ {
+ // By-value method
+ fcn_class = AST::Function::CLASS_VALMETHOD;
+ GET_TOK(tok, lex);
+ throw ParseError::Todo("By-value methods");
+ }
+ else
+ {
+ // Unbound method
+ }
::std::vector<AST::StructItem> args;
- if( GET_TOK(tok, lex) != TOK_PAREN_CLOSE )
+ if( tok.type() != TOK_PAREN_CLOSE )
{
- // Argument list
lex.putback(tok);
+ // Argument list
do {
GET_CHECK_TOK(tok, lex, TOK_IDENT);
::std::string name = tok.str();
@@ -287,7 +322,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex)
AST::Expr code = Parse_ExprBlock(lex);
- return AST::Function(name, params, ret_type, args, code);
+ return AST::Function(name, params, fcn_class, ret_type, args, code);
}
AST::Module Parse_ModRoot(bool is_own_file, Preproc& lex)