Created
November 16, 2012 19:47
-
-
Save Ruzzz/4090288 to your computer and use it in GitHub Desktop.
C++ Simple Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, class CharType>class Parser | |
{ | |
Parser(T &t) :: m_curr(t.begin()) , m_end(t.end()) {} | |
bool next_char(CharType *c) { | |
bool not_eof = m_curr != m_end; | |
if (not_eof) { | |
*c = *m_curr; | |
m_curr++; | |
} | |
return not_eof; | |
} | |
Symbol next_symbol() { | |
CharType c; | |
if (next_char(&c)) { | |
switch (c) { | |
case '<' : | |
return Symbol::LEFT_BRACE; | |
case '>' : | |
return Symbol::RIGHT_BRACE; | |
} | |
} else { | |
return Symbol::EOF; | |
} | |
} | |
void parse() { | |
Symbol s = next_symbol(); | |
while (s != Symbol::EOF) { | |
// TODO | |
s = next_symbol(); | |
} | |
} | |
private: | |
typename T::const_iterator m_curr; | |
typename T::const_iterator m_end; | |
} | |
std::wstring ws; | |
Parser< std::wstring, wchar_t > parser(ws); | |
parser.parse(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment