I have a class "Parser" that convert a text file to a bunch of lines made of tokens :
Code:
// A parser that can convert a "C-Like" file to an structured list of Lines and Tokens
// Cf. "Parser::SetSeparators()" : Default Line Separators = { '\n', '\r' }
// and Default Token Separators = { ' ', '\t', '(', ')', '=', ':', ';', ',' }
class Parser
{
public:
struct Line // A "line" made of tokens and inner lines (both are optionnal)
{
vector<ParserString> Token; // Line's Elements
vector<Line> Inner; // Inner Block's Lines (delimited by '{' and '}')
};
// Parse the Stream and put its lines and tokens in the Line list (can also put separators)
virtual int LoadBlock(ParserStream& S, vector<Line>& L, const bool KeepSeparators);
virtual bool IsLineSep(char c); // Tells if 'c' is a Line Separator
virtual bool IsTokenSep(char c); // Tells if 'c' is a Token Separator
virtual bool IsEmpty(Line& L); // Tells if this Line is Empty
// NOTE : Send 'NULL' and '0' to default them.
virtual void SetSeparators( const char* Separators_Line, const char NumSepLine,
const char* Separators_Token, const char NumSepToken );
// For DEBUG : Recursively print blocks (lines and tokens)
virtual void PrintBlock(vector<Line>& B, ParserString strIndent);
Parser() // Default Ctor
{
SetSeparators(NULL, 0, NULL, 0);
}
protected:
char m_Separators_Line[256]; // Line Separators
char m_Separators_Token[256]; // Token Separators
unsigned char m_NumSepLine, m_NumSepToken; // Numbers of Separators
};
With this class, I can easily parse any text file (eg : ".def", "xkScene.txt")
I will release the source code in one week so, you can wait it
