parser.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SExp - A S-Expression Parser for C++
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // 2015 Ingo Ruhnke <grumbel@gmail.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef HEADER_SEXP_PARSER_HPP
  18. #define HEADER_SEXP_PARSER_HPP
  19. #include <memory>
  20. #include <vector>
  21. #include <sexp/lexer.hpp>
  22. #include <sexp/value.hpp>
  23. namespace sexp {
  24. class Lexer;
  25. class Parser
  26. {
  27. public:
  28. enum { USE_ARRAYS = true };
  29. static Value from_string(std::string const& str, bool use_arrays = false);
  30. static Value from_stream(std::istream& stream, bool use_arrays = false);
  31. static std::vector<Value> from_string_many(std::string const& str, bool use_arrays = false);
  32. static std::vector<Value> from_stream_many(std::istream& stream, bool use_arrays = false);
  33. public:
  34. Parser(Lexer& lexer);
  35. ~Parser();
  36. private:
  37. [[noreturn]]
  38. void parse_error(const char* msg) const;
  39. std::vector<Value> read_many();
  40. Value read();
  41. private:
  42. Lexer& m_lexer;
  43. Lexer::TokenType m_token;
  44. private:
  45. Parser(const Parser&);
  46. Parser & operator=(const Parser&);
  47. };
  48. } // namespace sexp
  49. #endif
  50. /* EOF */