Subversion Repositories spk

Rev

Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 114
Line 8... Line 8...
8
#include "../common/ext_list.h"
8
#include "../common/ext_list.h"
9
 
9
 
10
class bod_text_parser
10
class bod_text_parser
11
{
11
{
12
	public:
12
	public:
-
 
13
		enum ParseFlags
-
 
14
		{
-
 
15
			none=0,
-
 
16
			parseIgnoreSlash=1,
-
 
17
			parseEqual=2,
-
 
18
			parseStdBrackets=4,
-
 
19
			parseQuotedStrings=8,
-
 
20
			parseBODComments=16,
-
 
21
			parseCComments=32,
-
 
22
			parseOperators=64
-
 
23
		};
-
 
24
		
-
 
25
		class Error
-
 
26
		{
-
 
27
			private:
-
 
28
				static const char *m_messages[];
-
 
29
			public:
-
 
30
				enum Code {
-
 
31
					errNone,
-
 
32
					errNewLineInConstant
-
 
33
				};
-
 
34
				Code code;
-
 
35
				int col, line;
-
 
36
				
-
 
37
				Error() { col=line=-1; code=errNone; } 
-
 
38
				
-
 
39
				const char* message() const { return m_messages[code]; }
-
 
40
		};
-
 
41
		
-
 
42
		/*enum Error
-
 
43
		{
-
 
44
			errNone,
-
 
45
			errNewLineInConstant
-
 
46
		};*/
-
 
47
		
13
		struct token
48
		struct token
14
		{
49
		{
-
 
50
			/* 
-
 
51
				before messing with the order of the enums, 
-
 
52
				make sure it will not break X3_TOKEN* declarations in x3objects.h 
-
 
53
			*/
15
			enum Type{
54
			enum Type{
16
				t_openBracket,
55
				t_openCrBracket,
17
				t_closeBracket,
56
				t_closeCrBracket,
18
				t_semicolon,
57
				t_semicolon,
19
				t_colon,
58
				t_colon,
-
 
59
				t_equal,
20
				t_openInstrBlock,
60
				t_openInstrBlock,
21
				t_closeInstrBlock,
61
				t_closeInstrBlock,
-
 
62
				t_hdrinfo,
-
 
63
				t_openStdBracket,
-
 
64
				t_closeStdBracket,
-
 
65
				t_slash,
-
 
66
				t_dot,
-
 
67
				t_plus,
22
				t_text,
68
				t_text,
23
				t_hdrinfo,
69
				t_quotedString
24
			};
70
			};
25
			
71
			
26
			static const char* specialChars[];
72
			static const char* specialChars[];
27
			static char tabWidth;
73
			static char tabWidth;
28
			
74
			
29
			const char *text;
75
			const char *text;
30
 
76
 
31
			int line;
77
			int line;
32
			short col;
78
			short col;
33
			
79
			
34
			Type type;
80
			Type type;
35
			
81
			
36
			token() { text=0; tabWidth=4; }
82
			token() { text=0; tabWidth=4; }
37
			token(const token& t) { text=t.text; line=t.line; col=t.col; type=t.type; }
83
			token(const token& t) { text=t.text; line=t.line; col=t.col; type=t.type; }
38
			virtual ~token() { }
84
			virtual ~token() { }
39
			
85
			
40
			const char* getText() const;
86
			const char* getText() const;
41
			
87
			
42
		};
88
		};
43
		
89
		
44
	private:
90
	private:
45
		//size_t m_lastCharPos;
-
 
46
		size_t m_lastPos;
91
		size_t m_lastPos;
47
		size_t m_newPos;
92
		size_t m_newPos;
48
		
93
		
49
		const char *m_pszBuffer;
94
		const char *m_pszBuffer;
50
		size_t m_buffLen;
95
		size_t m_buffLen;
51
		int m_lineIdx;
96
		int m_lineIdx;
52
		bool m_ignoreRemarks;
-
 
53
		
97
		
-
 
98
		Error m_error;
-
 
99
		ParseFlags m_parseFlags;
-
 
100
		
54
		//size_t parseLines(char *buffer, size_t size, char ***array_ptr);
101
		bool testFlag(ParseFlags f) const { return (parseFlags() & f) > 0; }
-
 
102
		
55
		void parseLine(char *line, int idx);
103
		bool parseLine(char *line, int idx);
-
 
104
	
-
 
105
		void error(int line, int col, Error::Code code) 
-
 
106
		{ 
-
 
107
			m_error.code=code; 
-
 
108
			m_error.col=col; m_error.line=line;
-
 
109
			// set the last pos to end so eof() will return true
-
 
110
			if(code!=Error::errNone)
-
 
111
				m_lastPos=m_buffLen; 
-
 
112
		}
56
	
113
	
57
	public:
114
	public:
58
		char * nextLine(); // public because of use in x3objects which is hack anyway
115
		char * nextLine(); // public because of use in x3objects which is hack anyway
59
		
116
		
60
	public:
117
	public:
61
		typedef ext::list<token*> TokenList;
118
		typedef ext::list<token*> TokenList;
62
		typedef TokenList::iterator iterator;
119
		typedef TokenList::iterator iterator;
63
		TokenList tokens;
120
		TokenList tokens;
64
		
121
		
65
		bod_text_parser() 
122
		bod_text_parser() 
66
		{ 
123
		{ 
67
			tabWidth(4);
124
			tabWidth(4);
68
			/*m_lastCharPos=0;*/ 
-
 
69
			m_lastPos=0; m_newPos=0;
125
			m_lastPos=0; m_newPos=0;
70
			m_pszBuffer=0;
126
			m_pszBuffer=0;
71
			m_buffLen=0;
127
			m_buffLen=0;
72
			m_lineIdx=0;
128
			m_lineIdx=0;
73
			m_ignoreRemarks=false;
129
			parseFlags(none);
74
		}
130
		}
75
		
131
		
-
 
132
		~bod_text_parser()
-
 
133
		{
-
 
134
			for(iterator &it=tokens.begin(); it!=tokens.end(); ++it){
-
 
135
				delete *it;
-
 
136
			}
-
 
137
		}
-
 
138
		
-
 
139
		Error error() const { return m_error; }
-
 
140
		
76
		bool eof() const { /*return m_lastCharPos>=m_buffLen;*/ return m_lastPos >= m_buffLen; }
141
		bool eof() const { return m_lastPos >= m_buffLen; }
77
		
142
		
78
		void tabWidth(int width) { token::tabWidth=width; }
143
		void tabWidth(int width) { token::tabWidth=width; }
79
		int tabWidth() const { return token::tabWidth; }
144
		int tabWidth() const { return token::tabWidth; }
80
		
145
		
81
		bool ignoreRemarks() const { return m_ignoreRemarks; }
146
		void parseFlags(ParseFlags newf) { m_parseFlags=newf; }
82
		void ignoreRemarks(bool ignore) { m_ignoreRemarks=ignore; }
147
		ParseFlags parseFlags() const { return m_parseFlags; }
83
		
148
		
84
		void preParseBuffer(char *pszBuffer, size_t size);
149
		void preParseBuffer(char *pszBuffer, size_t size);
85
		size_t parseBuffer(size_t limit=-1);
150
		size_t parseBuffer(size_t limit=-1);
86
};
151
};
87
 
152