summaryrefslogtreecommitdiff
path: root/parse/lex.cpp
diff options
context:
space:
mode:
authorJohn Hodge (bugs) <tpg@mutabah.net>2014-12-07 18:53:17 +0800
committerJohn Hodge (bugs) <tpg@mutabah.net>2014-12-07 18:53:17 +0800
commit0bfd3352489411a1e1d6b98397979ad91e2a52b1 (patch)
treec3e41ae23991f4b95ad155e7601f6f5a5c36aa64 /parse/lex.cpp
parent6178198e6a5f0ff2384660253347b6e9b5d686e2 (diff)
downloadmrust-0bfd3352489411a1e1d6b98397979ad91e2a52b1.tar.gz
Macro expansion working, onwards to field parsing
Diffstat (limited to 'parse/lex.cpp')
-rw-r--r--parse/lex.cpp35
1 files changed, 16 insertions, 19 deletions
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)