xref: /haiku/src/tests/add-ons/print/ppd/parser/Parser.h (revision 96490327ca254c5b2e989fb3fc20c4d36c2c6f93)
1 /*
2  * Copyright 2008, Haiku.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Michael Pfeiffer <laplace@users.sourceforge.net>
7  */
8 
9 #ifndef _PARSER_H
10 #define _PARSER_H
11 
12 #include "Scanner.h"
13 #include "Statement.h"
14 
15 // PPD statement parser
16 class Parser
17 {
18 private:
19 	Scanner fScanner;
20 
21 	int GetCurrentChar() { return fScanner.GetCurrentChar(); }
22 	void NextChar()      { fScanner.NextChar(); }
23 
24 	void SkipWhitespaces();
25 	void SkipComment();
26 	void SkipWhitespaceSeparator();
27 	bool ParseKeyword(Statement* statement);
28 	bool ParseTranslation(Value* value, int separator = -1);
29 	bool ParseOption(Statement* statement);
30 	bool ParseValue(Statement* statement);
31 	void UpdateStatementType(Statement* statement);
32 	Statement* ParseStatement();
33 
34 protected:
35 	void Warning(const char* message) { fScanner.Warning(message); }
36 	void Error(const char* message) { fScanner.Error(message); }
37 
38 public:
39 	// Initializes the parser with the file
40 	Parser(const char* file);
41 	// Returns B_OK if the constructor could open the file
42 	// successfully
43 	status_t InitCheck();
44 
45 	// Includes the file for parsing
46 	bool Include(const char* file) { return fScanner.Include(file); }
47 
48 	// Returns the statement or null on eof or on error
49 	Statement* Parse();
50 	// Returns true if there was a parsing error
51 	bool HasError()               { return fScanner.HasError(); }
52 	// The error message of the parsing error
53 	const char* GetErrorMessage() { return fScanner.GetErrorMessage(); }
54 	// Returns true if there are any warnings
55 	bool HasWarning()             { return fScanner.HasWarning(); }
56 	// Returns the waring message
57 	const char* GetWarningMessage() { return fScanner.GetWarningMessage(); }
58 };
59 
60 #endif
61