summaryrefslogtreecommitdiff
path: root/src/parse/lex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/lex.cpp')
-rw-r--r--src/parse/lex.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp
index a3e8c0d0..0e928bf2 100644
--- a/src/parse/lex.cpp
+++ b/src/parse/lex.cpp
@@ -1205,6 +1205,53 @@ Position TTStream::getPosition() const
return Position("TTStream", 0,0);
}
+
+TTStreamO::TTStreamO(TokenTree input_tt):
+ m_input_tt( mv$(input_tt) )
+{
+ m_stack.push_back( ::std::make_pair(0, nullptr) );
+}
+TTStreamO::~TTStreamO()
+{
+}
+Token TTStreamO::realGetToken()
+{
+ while(m_stack.size() > 0)
+ {
+ // If current index is above TT size, go up
+ unsigned int& idx = m_stack.back().first;
+ const TokenTree& tree = *( m_stack.back().second ? m_stack.back().second : &m_input_tt );
+
+ if(idx == 0 && tree.is_token()) {
+ idx ++;
+ m_last_pos = tree.tok().get_pos();
+ return tree.tok();
+ }
+
+ if(idx < tree.size())
+ {
+ const TokenTree& subtree = tree[idx];
+ idx ++;
+ if( subtree.size() == 0 ) {
+ m_last_pos = subtree.tok().get_pos();
+ return subtree.tok();
+ }
+ else {
+ m_stack.push_back( ::std::make_pair(0, &subtree ) );
+ }
+ }
+ else {
+ m_stack.pop_back();
+ }
+ }
+ return Token(TOK_EOF);
+}
+Position TTStreamO::getPosition() const
+{
+ return m_last_pos;
+}
+
+
TokenStream::TokenStream():
m_cache_valid(false)
{