// This file is part of Cait . // Copyright (C) 2022-2022 Fuwn // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only #ifndef PARSER_HH #define PARSER_HH #include #include #include "lexer.hh" #include "node.hh" namespace cait { using node_tree = std::vector; class parser_exception : public std::runtime_error { public: explicit parser_exception(const std::string &); virtual auto x() -> void; }; struct token_bundle { private: using token_t = token; public: std::size_t &j; token_t &token; std::vector &parsed_token_line; std::vector &token_line; token_bundle(std::size_t &, token_t &, std::vector &, std::vector &); }; // https://stackoverflow.com/a/25652548/14452787 template struct range_t { private: T _begin, _end; public: range_t(T, T); T begin(); T end(); }; // https://stackoverflow.com/a/25652548/14452787 template range_t range(T, T); class parser { private: token_tree _tree; node_tree _nodes; auto fix_tree(token_tree &) -> void; auto prune_empty_token_lines() -> void; static auto token_parse_build_declaration(token_bundle) -> void; static auto token_parse_rule_variable(token_bundle) -> void; static auto token_parse_include_subninja_declaration(token_bundle) -> void; static auto token_parse_default_declaration(token_bundle) -> void; static auto token_parse_rule_pool_declaration(token_bundle) -> void; static auto token_parse_assignment_operator(token_bundle) -> void; public: explicit parser(token_tree &); [[nodiscard]] auto tree() const noexcept -> const token_tree &; [[nodiscard]] auto nodes() const noexcept -> const node_tree &; auto generate_nodes(const std::string &, const std::vector &) noexcept(false) -> void; }; } // namespace cait #endif // PARSER_HH