Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TPARSER_INCLUDED
Toshihiro Shimizu 890ddd
#define TPARSER_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "tgrammar.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZBASE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace TSyntax
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct DVAPI SyntaxToken {
Toshihiro Shimizu 890ddd
	int m_pos, m_length;
Toshihiro Shimizu 890ddd
	TokenType m_type;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI Parser
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	class Imp;
Toshihiro Shimizu 890ddd
	Imp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Parser(const Grammar *grammar);
Toshihiro Shimizu 890ddd
	~Parser();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! parse the input string and create the corresponding calculator
Toshihiro Shimizu 890ddd
	//! (returns 0 if the text contains mistakes)
Toshihiro Shimizu 890ddd
	Calculator *parse(string text);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! return true if the last parsed string was correct
Toshihiro Shimizu 890ddd
	bool isValid() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! return the last parsed string
Toshihiro Shimizu 890ddd
	string getText() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! return the last error code (if the last parsed string was correct then returns "")
Toshihiro Shimizu 890ddd
	string getError() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! if getError() != "" returns the position of the last parsed token
Toshihiro Shimizu 890ddd
	//! the pair contains the indices of the first and the last characters of the token
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> getErrorPos() const;</int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	enum SyntaxStatus {
Toshihiro Shimizu 890ddd
		Correct,
Toshihiro Shimizu 890ddd
		Incomplete,
Toshihiro Shimizu 890ddd
		Error,
Toshihiro Shimizu 890ddd
		ExtraIgnored
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	SyntaxStatus checkSyntax(std::vector<syntaxtoken> &tokens, string text);</syntaxtoken>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getSuggestions(Grammar::Suggestions &suggestions, string text);
Toshihiro Shimizu 890ddd
	string getCurrentPatternString(string text);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// not implemented
Toshihiro Shimizu 890ddd
	Parser(const Parser &);
Toshihiro Shimizu 890ddd
	Parser &operator=(const Parser &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace TSyntax
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif