Subversion Repositories spk

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
/*
2
  defines bod_text_parser - class that can parse bod syntax at general level
3
*/
4
 
5
#ifndef BOD_TEXT_PARSER_INCLUDED
6
#define BOD_TEXT_PARSER_INCLUDED
7
 
8
#include "../common/ext_list.h"
9
 
10
class bod_text_parser
11
{
12
	public:
13
		struct token
14
		{
15
			enum Type{
16
				t_openBracket,
17
				t_closeBracket,
18
				t_semicolon,
19
				t_colon,
20
				t_openInstrBlock,
21
				t_closeInstrBlock,
22
				t_text,
23
				t_hdrinfo,
24
			};
25
 
26
			static const char* specialChars[];
27
			static char tabWidth;
28
 
29
			const char *text;
30
 
31
			int line;
32
			short col;
33
 
34
			Type type;
35
 
36
			token() { text=0; tabWidth=4; }
37
			token(const token& t) { text=t.text; line=t.line; col=t.col; type=t.type; }
38
			virtual ~token() { }
39
 
40
			const char* getText() const;
41
 
42
		};
43
 
44
	private:
45
		//size_t m_lastCharPos;
46
		size_t m_lastPos;
47
		size_t m_newPos;
48
 
49
		const char *m_pszBuffer;
50
		size_t m_buffLen;
51
		int m_lineIdx;
52
		bool m_ignoreRemarks;
53
 
54
		//size_t parseLines(char *buffer, size_t size, char ***array_ptr);
55
		void parseLine(char *line, int idx);
56
 
57
	public:
58
		char * nextLine(); // public because of use in x3objects which is hack anyway
59
 
60
	public:
61
		typedef ext::list<token*> TokenList;
62
		typedef TokenList::iterator iterator;
63
		TokenList tokens;
64
 
65
		bod_text_parser() 
66
		{ 
67
			tabWidth(4);
68
			/*m_lastCharPos=0;*/ 
69
			m_lastPos=0; m_newPos=0;
70
			m_pszBuffer=0;
71
			m_buffLen=0;
72
			m_lineIdx=0;
73
			m_ignoreRemarks=false;
74
		}
75
 
76
		bool eof() const { /*return m_lastCharPos>=m_buffLen;*/ return m_lastPos >= m_buffLen; }
77
 
78
		void tabWidth(int width) { token::tabWidth=width; }
79
		int tabWidth() const { return token::tabWidth; }
80
 
81
		bool ignoreRemarks() const { return m_ignoreRemarks; }
82
		void ignoreRemarks(bool ignore) { m_ignoreRemarks=ignore; }
83
 
84
		void preParseBuffer(char *pszBuffer, size_t size);
85
		size_t parseBuffer(size_t limit=-1);
86
};
87
 
88
#endif // !defined(BOD_TEXT_PARSER_INCLUDED)