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 _SCANNER_H
10#define _SCANNER_H
11
12#include "CharacterClasses.h"
13#include "PPDFile.h"
14
15class Scanner {
16private:
17	PPDFile* fCurrentFile;
18	BString  fLastError;
19	BString  fWarnings;
20
21	BString* Scan(bool (cond)(int ch));
22	bool ScanHexadecimalSubstring(BString* literal);
23	BString* ScanLiteral(bool quotedValue, int separator);
24
25public:
26	Scanner(const char* file);
27	virtual ~Scanner();
28
29	status_t InitCheck();
30
31	// Returns the current character or -1 if on EOF.
32	int GetCurrentChar();
33	// Reads the next character. Use GetChar to read the current
34	void NextChar();
35	// Returns the position of the current character
36	Position GetPosition();
37	// Returns the file name of the current character
38	const char* GetFileName();
39
40	BString* ScanIdent()            { return Scan(IsIdentChar); }
41	BString* ScanOption()           { return Scan(IsOptionChar); }
42	BString* ScanSymbolValue()      { return Scan(IsPrintableWithoutWhitespaces); }
43	BString* ScanInvocationValue()  { return Scan(IsPrintableWithWhitespaces); }
44	BString* ScanStringValue()      { return Scan(IsStringChar); }
45	BString* ScanTranslationValue(int separator = kEof)
46									{ return ScanLiteral(false, separator); }
47	BString* ScanQuotedValue()      { return ScanLiteral(true, kEof); }
48
49	// Include the file at the current position and read the first char.
50	bool Include(const char* file);
51
52	void Warning(const char* message);
53	const char* GetWarningMessage();
54	bool HasWarning();
55
56	void Error(const char* message);
57	const char* GetErrorMessage();
58	bool HasError();
59};
60
61#endif
62