Subversion Repositories spk

Rev

Rev 1 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#ifndef BOD_PARSER_BASE_INCLUDED
2
#define BOD_PARSER_BASE_INCLUDED
3
 
4
#include "../common/ext_list.h"
5
#include "bod_text_parser.h"
6
#include "token_stream.h"
7
 
8
// I must get rid of COM S_OK definition to be able to use it later in enum
9
#ifdef S_OK 
10
#undef S_OK
11
#endif
12
 
13
class bod_parser_base
14
{
15
	public:
16
		enum ErrorSeverity
17
		{
18
			S_OK = 0,
19
			S_Error,
20
			S_Warning
21
		};
22
 
23
		enum ErrorCode
24
		{
25
			E_Error
26
		};
27
 
28
		enum ErrorFacility
29
		{
30
			F_Compiler
31
		};
32
 
33
		struct Error
34
		{
35
			int	code;
36
			char text[255];
37
			int line, col;
38
 
39
			void makeCode(ErrorFacility f, ErrorSeverity s, ErrorCode e)
40
			{
41
				code=s << 24;
42
				code|=f << 16;
43
				code|=e;
44
			}
45
 
46
			ErrorSeverity severity() const { return (ErrorSeverity)(code >> 24); }
47
			ErrorFacility facility() const { return (ErrorFacility)((code >> 16) & 0xff); }
48
			bool failed() const { return (severity() & S_Error) > 0; }
49
			bool warning() const { return (severity() & S_Warning) > 0; }
50
			bool succeeded() const { return (severity() & S_OK) == 0; }
51
 
52
			ErrorCode getCode() const { return (ErrorCode)(code & 0xFFFF); }
53
		};
54
 
55
	protected:
114 cycrow 56
		typedef bod_text_parser::token token;
1 cycrow 57
		typedef ext::list<Error*> ErrorList;
58
 
59
		void error(const bod_text_parser::token *t, ErrorSeverity severity, const char *format, ...);
60
 
61
	public:
62
		typedef ErrorList::iterator iterator;
114 cycrow 63
		typedef token_stream<bod_text_parser> token_stream;
1 cycrow 64
 
65
		ErrorList errors;
66
 
67
		virtual ~bod_parser_base() { clearErrors(); }
68
 
69
		void clearErrors()
70
		{
71
			for(iterator &it=errors.begin(); it!=errors.end(); ++it){
72
				delete *it;
73
			}
74
		}
75
 
76
	protected:
77
		token* loadValue(token_stream& is, const char *context="");
78
		bool loadIntValue(token_stream& is, int *i, const char *context="");
79
		bool loadDoubleValue(token_stream& is, double *d, const char *context="");
80
		char * loadString(token_stream& is, const char *context="");
81
		static bool ungetValue(token_stream& s);
82
};
83
 
84
#endif // !defined(BOD_PARSER_BASE_INCLUDED)