Subversion Repositories spk

Rev

Rev 114 | Go to most recent revision | Details | 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:
56
		typedef ext::list<Error*> ErrorList;
57
		typedef bod_text_parser::token token;
58
 
59
		void error(const bod_text_parser::token *t, ErrorSeverity severity, const char *format, ...);
60
 
61
	public:
62
		typedef ErrorList::iterator iterator;
63
 
64
		ErrorList errors;
65
 
66
		virtual ~bod_parser_base() { clearErrors(); }
67
 
68
		void clearErrors()
69
		{
70
			for(iterator &it=errors.begin(); it!=errors.end(); ++it){
71
				delete *it;
72
			}
73
		}
74
 
75
	protected:
76
		token* loadValue(token_stream& is, const char *context="");
77
		bool loadIntValue(token_stream& is, int *i, const char *context="");
78
		bool loadDoubleValue(token_stream& is, double *d, const char *context="");
79
		char * loadString(token_stream& is, const char *context="");
80
		static bool ungetValue(token_stream& s);
81
};
82
 
83
#endif // !defined(BOD_PARSER_BASE_INCLUDED)