diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-12 11:30:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-12 11:30:04 +0200 |
commit | 257ad3c2c5e633d2fd3f2228021ac3ae8d6d07cb (patch) | |
tree | ecfa5df6e8abca5bd483d5498bf84412ae58930e /build/parser | |
parent | 0dcf07989b4b942f6ff872023b2886b7f698d711 (diff) |
Initial buildfile parser implementation
g++-4.9 -std=c++14 -g -I../../.. -o driver driver.cxx ../../../build/lexer.cxx ../../../build/parser.cxx && ./driver
Diffstat (limited to 'build/parser')
-rw-r--r-- | build/parser | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/build/parser b/build/parser new file mode 100644 index 0000000..04ef00d --- /dev/null +++ b/build/parser @@ -0,0 +1,55 @@ +// 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 <string> +#include <iosfwd> +#include <exception> + +#include <build/path> + +namespace build +{ + class token; + enum class token_type; + class lexer; + + // The handler must assume the diagnostics has already been issued. + // + struct parser_error: std::exception {}; + + class parser + { + public: + parser (std::ostream& diag): diag_ (diag) {} + + void + parse (std::istream&, const path&); + + // Recursive descent parser. + // + private: + void + names (token&, token_type&); + + // Utilities. + // + private: + void + next (token&, token_type&); + + std::ostream& + error (const token&); + + private: + std::ostream& diag_; + + lexer* lexer_; + const path* path_; + }; +} + +#endif // BUILD_PARSER |