// file : build/parser -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file #ifndef BUILD_PARSER #define BUILD_PARSER #include #include #include #include // std::move #include #include #include #include namespace build { class scope; class lexer; class parser { public: parser (): fail (&path_) {} // Issues diagnostics and throws failed in case of an error. // void parse (std::istream&, const path&, scope&); // Recursive descent parser. // private: struct name_type { name_type (std::string t, path d, std::string n) : type (std::move (t)), dir (std::move (d)), name (std::move (n)) {} std::string type; // Empty if untyped. path dir; std::string name; }; typedef std::vector names_type; void clause (token&, token_type&); void print (token&, token_type&); void source (token&, token_type&); void include (token&, token_type&); names_type names (token& t, token_type& tt) { names_type ns; names (t, tt, ns, nullptr, nullptr); return ns; } void names (token&, token_type&, names_type&, const path* dir, const std::string* type); // Utilities. // private: token_type next (token&, token_type&); token_type peek (); // Diagnostics. // private: const fail_mark fail; private: const std::string* path_; // Path processed by diagnostic_string(). lexer* lexer_; scope* scope_; token peek_ {token_type::eos, 0, 0}; bool peeked_ {false}; std::unordered_set include_; }; } #endif // BUILD_PARSER