Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TPARSER_INCLUDED
Toshihiro Shimizu 890ddd
#define TPARSER_INCLUDED
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
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
Shinya Kitaoka 120a6e
namespace TSyntax {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct DVAPI SyntaxToken {
Shinya Kitaoka 120a6e
  int m_pos, m_length;
Shinya Kitaoka 120a6e
  TokenType m_type;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI Parser {
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Parser(const Grammar *grammar);
Shinya Kitaoka 120a6e
  ~Parser();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! parse the input string and create the corresponding calculator
Shinya Kitaoka 120a6e
  //! (returns 0 if the text contains mistakes)
Shinya Kitaoka 120a6e
  Calculator *parse(std::string text);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! return true if the last parsed string was correct
Shinya Kitaoka 120a6e
  bool isValid() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! return the last parsed string
Shinya Kitaoka 120a6e
  std::string getText() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! return the last error code (if the last parsed string was correct then
Shinya Kitaoka 120a6e
  //! returns "")
Shinya Kitaoka 120a6e
  std::string getError() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! if getError() != "" returns the position of the last parsed token
Shinya Kitaoka 120a6e
  //! the pair contains the indices of the first and the last characters of the
Shinya Kitaoka 120a6e
  //! token
Shinya Kitaoka 120a6e
  std::pair<int, int=""> getErrorPos() const;</int,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  enum SyntaxStatus { Correct, Incomplete, Error, ExtraIgnored };
Shinya Kitaoka 120a6e
  SyntaxStatus checkSyntax(std::vector<syntaxtoken> &tokens, std::string text);</syntaxtoken>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getSuggestions(Grammar::Suggestions &suggestions, std::string text);
Shinya Kitaoka 120a6e
  std::string getCurrentPatternString(std::string text);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  Parser(const Parser &);
Shinya Kitaoka 120a6e
  Parser &operator=(const Parser &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace TSyntax
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif