14420c1ceSMichael Pfeiffer/*
24420c1ceSMichael Pfeiffer * Copyright 2008, Haiku.
34420c1ceSMichael Pfeiffer * Distributed under the terms of the MIT license.
44420c1ceSMichael Pfeiffer *
54420c1ceSMichael Pfeiffer * Authors:
64420c1ceSMichael Pfeiffer *		Michael Pfeiffer <laplace@users.sourceforge.net>
74420c1ceSMichael Pfeiffer */
84420c1ceSMichael Pfeiffer
94420c1ceSMichael Pfeiffer#ifndef _SCANNER_H
104420c1ceSMichael Pfeiffer#define _SCANNER_H
114420c1ceSMichael Pfeiffer
124420c1ceSMichael Pfeiffer#include "CharacterClasses.h"
134420c1ceSMichael Pfeiffer#include "PPDFile.h"
144420c1ceSMichael Pfeiffer
154420c1ceSMichael Pfeifferclass Scanner {
164420c1ceSMichael Pfeifferprivate:
174420c1ceSMichael Pfeiffer	PPDFile* fCurrentFile;
184420c1ceSMichael Pfeiffer	BString  fLastError;
194420c1ceSMichael Pfeiffer	BString  fWarnings;
204420c1ceSMichael Pfeiffer
214420c1ceSMichael Pfeiffer	BString* Scan(bool (cond)(int ch));
224420c1ceSMichael Pfeiffer	bool ScanHexadecimalSubstring(BString* literal);
234420c1ceSMichael Pfeiffer	BString* ScanLiteral(bool quotedValue, int separator);
244420c1ceSMichael Pfeiffer
254420c1ceSMichael Pfeifferpublic:
264420c1ceSMichael Pfeiffer	Scanner(const char* file);
274420c1ceSMichael Pfeiffer	virtual ~Scanner();
284420c1ceSMichael Pfeiffer
294420c1ceSMichael Pfeiffer	status_t InitCheck();
304420c1ceSMichael Pfeiffer
314420c1ceSMichael Pfeiffer	// Returns the current character or -1 if on EOF.
324420c1ceSMichael Pfeiffer	int GetCurrentChar();
334420c1ceSMichael Pfeiffer	// Reads the next character. Use GetChar to read the current
344420c1ceSMichael Pfeiffer	void NextChar();
354420c1ceSMichael Pfeiffer	// Returns the position of the current character
364420c1ceSMichael Pfeiffer	Position GetPosition();
374420c1ceSMichael Pfeiffer	// Returns the file name of the current character
384420c1ceSMichael Pfeiffer	const char* GetFileName();
394420c1ceSMichael Pfeiffer
404420c1ceSMichael Pfeiffer	BString* ScanIdent()            { return Scan(IsIdentChar); }
414420c1ceSMichael Pfeiffer	BString* ScanOption()           { return Scan(IsOptionChar); }
424420c1ceSMichael Pfeiffer	BString* ScanSymbolValue()      { return Scan(IsPrintableWithoutWhitespaces); }
434420c1ceSMichael Pfeiffer	BString* ScanInvocationValue()  { return Scan(IsPrintableWithWhitespaces); }
444420c1ceSMichael Pfeiffer	BString* ScanStringValue()      { return Scan(IsStringChar); }
454420c1ceSMichael Pfeiffer	BString* ScanTranslationValue(int separator = kEof)
464420c1ceSMichael Pfeiffer									{ return ScanLiteral(false, separator); }
474420c1ceSMichael Pfeiffer	BString* ScanQuotedValue()      { return ScanLiteral(true, kEof); }
484420c1ceSMichael Pfeiffer
494420c1ceSMichael Pfeiffer	// Include the file at the current position and read the first char.
504420c1ceSMichael Pfeiffer	bool Include(const char* file);
514420c1ceSMichael Pfeiffer
524420c1ceSMichael Pfeiffer	void Warning(const char* message);
534420c1ceSMichael Pfeiffer	const char* GetWarningMessage();
544420c1ceSMichael Pfeiffer	bool HasWarning();
554420c1ceSMichael Pfeiffer
564420c1ceSMichael Pfeiffer	void Error(const char* message);
574420c1ceSMichael Pfeiffer	const char* GetErrorMessage();
584420c1ceSMichael Pfeiffer	bool HasError();
594420c1ceSMichael Pfeiffer};
604420c1ceSMichael Pfeiffer
614420c1ceSMichael Pfeiffer#endif
62