diff options
author | John Hodge <tpg@mutabah.net> | 2015-08-28 16:14:00 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-08-28 16:14:00 +0800 |
commit | 261f2aea278e1185f69b06e65501c1ca718df47c (patch) | |
tree | 8a8e54c4fd85f238ebdddb01f33693eadc194934 /src/parse | |
parent | aaa9780a3b5a1c78b6f5e0eb1c46405ee044b750 (diff) | |
download | mrust-261f2aea278e1185f69b06e65501c1ca718df47c.tar.gz |
Tagged union for Path
Diffstat (limited to 'src/parse')
-rw-r--r-- | src/parse/expr.cpp | 2 | ||||
-rw-r--r-- | src/parse/paths.cpp | 20 | ||||
-rw-r--r-- | src/parse/root.cpp | 16 |
3 files changed, 23 insertions, 15 deletions
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 15e983f7..eb53ac98 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -1001,7 +1001,7 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) case TOK_RWORD_SELF:
{
if( LOOK_AHEAD(lex) != TOK_DOUBLE_COLON ) {
- return NEWNODE( AST::ExprNode_NamedValue, AST::Path(AST::Path::TagVariable(), "self") );
+ return NEWNODE( AST::ExprNode_NamedValue, AST::Path(AST::Path::TagLocal(), "self") );
}
else
{
diff --git a/src/parse/paths.cpp b/src/parse/paths.cpp index e3b290d0..43346172 100644 --- a/src/parse/paths.cpp +++ b/src/parse/paths.cpp @@ -41,9 +41,9 @@ AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode) } AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generic_mode) { + Token tok; if( is_abs ) { - Token tok; if( GET_TOK(tok, lex) == TOK_STRING ) { ::std::string cratename = tok.str(); GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON); @@ -54,8 +54,16 @@ AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generi return Parse_PathFrom(lex, AST::Path(AST::Path::TagAbsolute()), generic_mode); } } - else - return Parse_PathFrom(lex, AST::Path(AST::Path::TagRelative()), generic_mode); + else { + //assert( GET_TOK(tok, lex) == TOK_IDENT ); + //if( lex.lookahead(0) != TOK_DOUBLE_COLON ) { + // return AST::Path( tok.str() ); + //} + //else { + // lex.putback(tok); + return Parse_PathFrom(lex, AST::Path(AST::Path::TagRelative()), generic_mode); + //} + } } AST::Path Parse_PathFrom(TokenStream& lex, AST::Path path, eParsePathGenericMode generic_mode) @@ -145,9 +153,9 @@ AST::Path Parse_PathFrom(TokenStream& lex, AST::Path path, eParsePathGenericMode path.append( AST::PathNode(component, params) ); } lex.putback(tok); - if( path.is_trivial() ) { - path = AST::Path(path[0].name()); - } + //if( path.is_trivial() ) { + // path = AST::Path(path[0].name()); + //} DEBUG("path = " << path); return path; } diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 1fd62741..369cc95a 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -725,7 +725,7 @@ void Parse_Impl(TokenStream& lex, AST::Module& mod, bool is_unsafe/*=false*/) {
if( !impl_type.is_path() )
throw ParseError::Generic(lex, "Trait was not a path");
- trait_path = impl_type.path();
+ trait_path = mv$(impl_type.path());
// Implementing a trait for another type, get the target type
if( GET_TOK(tok, lex) == TOK_DOUBLE_DOT )
{
@@ -885,9 +885,9 @@ void Parse_ExternBlock(TokenStream& lex, AST::Module& mod, ::std::string abi) }
}
-void Parse_Use_Wildcard(const AST::Path& base_path, ::std::function<void(AST::Path, ::std::string)> fcn)
+void Parse_Use_Wildcard(AST::Path base_path, ::std::function<void(AST::Path, ::std::string)> fcn)
{
- fcn(base_path, ""); // HACK! Empty path indicates wilcard import
+ fcn( mv$(base_path), ""); // HACK! Empty path indicates wilcard import
}
void Parse_Use_Set(TokenStream& lex, const AST::Path& base_path, ::std::function<void(AST::Path, ::std::string)> fcn)
{
@@ -911,7 +911,8 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::Path, ::std::string)> TRACE_FUNCTION;
Token tok;
- AST::Path path = AST::Path( AST::Path::TagAbsolute() );
+ AST::Path path = AST::Path(AST::Path::TagAbsolute());
+ ::std::vector<AST::PathNode> nodes;
switch( GET_TOK(tok, lex) )
{
@@ -945,7 +946,6 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::Path, ::std::string)> default:
throw ParseError::Unexpected(lex, tok);
}
- // TODO: Use from crate root
while( GET_TOK(tok, lex) == TOK_DOUBLE_COLON )
{
if( GET_TOK(tok, lex) == TOK_IDENT )
@@ -961,7 +961,7 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::Path, ::std::string)> GET_CHECK_TOK(tok, lex, TOK_BRACE_CLOSE);
break ;
case TOK_STAR:
- Parse_Use_Wildcard(path, fcn);
+ Parse_Use_Wildcard( mv$(path), fcn );
break ;
default:
throw ParseError::Unexpected(lex, tok);
@@ -1309,7 +1309,7 @@ void Parse_ModRoot_Items(TokenStream& lex, AST::Crate& crate, AST::Module& mod, case TOK_RWORD_USE:
Parse_Use(lex, [&mod,is_public,&path](AST::Path p, std::string s) {
DEBUG(path << " - use " << p << " as '" << s << "'");
- mod.add_alias(is_public, p, s);
+ mod.add_alias(is_public, mv$(p), s);
});
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
break;
@@ -1614,7 +1614,7 @@ void Parse_ModRoot(TokenStream& lex, AST::Crate& crate, AST::Module& mod, LList< {
// Import the prelude
AST::Path prelude_path = AST::Path( "std", { AST::PathNode("prelude", {}), AST::PathNode("v1", {}) } );
- Parse_Use_Wildcard(prelude_path,
+ Parse_Use_Wildcard( mv$(prelude_path),
[&mod](AST::Path p, std::string s) {
mod.add_alias(false, p, s);
}
|