summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
Diffstat (limited to 'parse')
-rw-r--r--parse/expr.cpp24
-rw-r--r--parse/lex.cpp35
-rw-r--r--parse/lex.hpp28
3 files changed, 61 insertions, 26 deletions
diff --git a/parse/expr.cpp b/parse/expr.cpp
index b3c00247..22f774bb 100644
--- a/parse/expr.cpp
+++ b/parse/expr.cpp
@@ -406,6 +406,11 @@ AST::ExprNode Parse_ExprVal(TokenStream& lex)
return ExprNode(ExprNode::TagInteger(), tok.intval(), tok.datatype());
case TOK_FLOAT:
throw ParseError::Todo("Float");
+ case TOK_RWORD_SELF: {
+ AST::Path path;
+ path.append( AST::PathNode("self", ::std::vector<TypeRef>()) );
+ return ExprNode(ExprNode::TagNamedValue(), path);
+ }
case TOK_MACRO: {
// Need to create a token tree, pass to the macro, then pass the result of that to Parse_Expr0
MacroExpander expanded_macro = Macro_Invoke(tok.str().c_str(), Parse_TT(lex));
@@ -477,6 +482,8 @@ TokenTree Parse_TT_Val(TokenStream& lex)
return inner;
}
break; }
+ case TOK_RWORD_SELF:
+ return TokenTree(tok);
case TOK_RWORD_MATCH:
ret.push_back(TokenTree(tok));
ret.push_back(Parse_TT(lex));
@@ -516,6 +523,23 @@ TokenTree Parse_TT_Expr(TokenStream& lex)
ret.push_back(tok);
ret.push_back(Parse_TT_Val(lex));
break;
+ case TOK_DOT:
+ ret.push_back(tok);
+ GET_CHECK_TOK(tok, lex, TOK_IDENT);
+ ret.push_back(tok);
+ switch(GET_TOK(tok, lex))
+ {
+ case TOK_DOUBLE_COLON:
+ throw ParseError::Todo("Generic type params in TT expr");
+ case TOK_PAREN_OPEN:
+ lex.putback(tok);
+ ret.push_back(Parse_TT(lex));
+ break;
+ default:
+ lex.putback(tok);
+ break;
+ }
+ break;
default:
lex.putback(tok);
cont = false;
diff --git a/parse/lex.cpp b/parse/lex.cpp
index e48cb9bb..4c1103a1 100644
--- a/parse/lex.cpp
+++ b/parse/lex.cpp
@@ -10,6 +10,7 @@
#include <cassert>
#include <iostream>
#include <cstdlib> // strtol
+#include <typeinfo>
Lexer::Lexer(::std::string filename):
m_istream(filename.c_str()),
@@ -225,7 +226,6 @@ Token Lexer::getToken()
str.push_back(ch);
ch = this->getc();
}
- this->putback();
if( ch == '!' )
{
@@ -233,6 +233,7 @@ Token Lexer::getToken()
}
else
{
+ this->putback();
for( unsigned int i = 0; i < LEN(RWORDS); i ++ )
{
if( str < RWORDS[i].chars ) break;
@@ -541,19 +542,6 @@ const char* Token::typestr(enum eTokenType type)
return os;
}
-TokenTree::TokenTree()
-{
-
-}
-TokenTree::TokenTree(Token tok)
-{
-
-}
-TokenTree::TokenTree(::std::vector<TokenTree> subtrees)
-{
-
-}
-
TTStream::TTStream(const TokenTree& input_tt):
m_input_tt(input_tt)
{
@@ -569,14 +557,21 @@ Token TTStream::realGetToken()
// If current index is above TT size, go up
unsigned int& idx = m_stack.back().first;
const TokenTree& tree = *m_stack.back().second;
+
+ if(idx == 0 && tree.size() == 0) {
+ idx ++;
+ return tree.tok();
+ }
+
if(idx < tree.size())
{
- if( tree[idx].size() == 0 ) {
- idx ++;
- return tree[idx-1].tok();
+ const TokenTree& subtree = tree[idx];
+ idx ++;
+ if( subtree.size() == 0 ) {
+ return subtree.tok();
}
else {
- m_stack.push_back( ::std::make_pair(0, &tree[idx] ) );
+ m_stack.push_back( ::std::make_pair(0, &subtree ) );
}
}
else {
@@ -603,7 +598,9 @@ Token TokenStream::getToken()
}
else
{
- return this->realGetToken();
+ Token ret = this->realGetToken();
+ ::std::cout << "getToken[" << typeid(*this).name() << "] - " << ret << ::std::endl;
+ return ret;
}
}
void TokenStream::putback(Token tok)
diff --git a/parse/lex.hpp b/parse/lex.hpp
index e01a1cbf..dbf365a0 100644
--- a/parse/lex.hpp
+++ b/parse/lex.hpp
@@ -199,14 +199,28 @@ private:
class TokenTree
{
+ Token m_tok;
+ ::std::vector<TokenTree> m_subtrees;
public:
- TokenTree();
- TokenTree(Token tok);
- TokenTree(::std::vector<TokenTree> subtrees);
-
- const unsigned int size() const;
- const TokenTree& operator[](unsigned int) const;
- const Token& tok() const;
+ TokenTree() {}
+ TokenTree(Token tok):
+ m_tok(tok)
+ {
+ }
+ TokenTree(::std::vector<TokenTree> subtrees):
+ m_subtrees(subtrees)
+ {
+ }
+
+ const unsigned int size() const {
+ return m_subtrees.size();
+ }
+ const TokenTree& operator[](unsigned int idx) const {
+ return m_subtrees[idx];
+ }
+ const Token& tok() const {
+ return m_tok;
+ }
};
class TTStream: