| #pragma once |
| |
| #ifndef TPARSER_INCLUDED |
| #define TPARSER_INCLUDED |
| |
| #include <memory> |
| |
| #include "tcommon.h" |
| #include "tgrammar.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TNZBASE_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| namespace TSyntax { |
| |
| struct DVAPI SyntaxToken { |
| int m_pos, m_length; |
| TokenType m_type; |
| }; |
| |
| class DVAPI Parser { |
| class Imp; |
| std::unique_ptr<Imp> m_imp; |
| |
| public: |
| Parser(const Grammar *grammar); |
| ~Parser(); |
| |
| |
| |
| Calculator *parse(std::string text); |
| |
| |
| bool isValid() const; |
| |
| |
| std::string getText() const; |
| |
| |
| |
| std::string getError() const; |
| |
| |
| |
| |
| std::pair<int, int> getErrorPos() const; |
| |
| enum SyntaxStatus { Correct, Incomplete, Error, ExtraIgnored }; |
| SyntaxStatus checkSyntax(std::vector<SyntaxToken> &tokens, std::string text); |
| |
| void getSuggestions(Grammar::Suggestions &suggestions, std::string text); |
| std::string getCurrentPatternString(std::string text); |
| |
| private: |
| |
| Parser(const Parser &); |
| Parser &operator=(const Parser &); |
| }; |
| |
| } |
| |
| #endif |