| 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 | |
| 18 | #ifndef HEADER_SEXP_PARSER_HPP |
| 19 | #define |
| 20 | |
| 21 | #include <memory> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <sexp/lexer.hpp> |
| 25 | #include <sexp/value.hpp> |
| 26 | |
| 27 | namespace sexp { |
| 28 | |
| 29 | class Lexer; |
| 30 | |
| 31 | class Parser |
| 32 | { |
| 33 | public: |
| 34 | enum { USE_ARRAYS = true }; |
| 35 | |
| 36 | static Value from_string(std::string const& str, bool use_arrays = false); |
| 37 | static Value from_stream(std::istream& stream, bool use_arrays = false); |
| 38 | |
| 39 | static std::vector<Value> from_string_many(std::string const& str, bool use_arrays = false); |
| 40 | static std::vector<Value> from_stream_many(std::istream& stream, bool use_arrays = false); |
| 41 | |
| 42 | public: |
| 43 | Parser(Lexer& lexer); |
| 44 | ~Parser(); |
| 45 | |
| 46 | private: |
| 47 | [[noreturn]] |
| 48 | void parse_error(const char* msg) const; |
| 49 | std::vector<Value> read_many(); |
| 50 | Value read(); |
| 51 | |
| 52 | private: |
| 53 | Lexer& m_lexer; |
| 54 | Lexer::TokenType m_token; |
| 55 | |
| 56 | private: |
| 57 | Parser(const Parser&); |
| 58 | Parser & operator=(const Parser&); |
| 59 | }; |
| 60 | |
| 61 | } // namespace sexp |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | /* EOF */ |
| 66 | |