diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-05-14 14:18:50 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-05-17 17:48:37 +0300 |
commit | 96908ec43ed27d9f34da27b6a94a6db357465056 (patch) | |
tree | 7d61f1ccb6c4cef366b652f4446eee7e38eb6736 /libbuild2/build/script/parser.hxx | |
parent | e5827facbfbfe90eae1b71c355a08bf61e2f6e1a (diff) |
Add build script
Diffstat (limited to 'libbuild2/build/script/parser.hxx')
-rw-r--r-- | libbuild2/build/script/parser.hxx | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx new file mode 100644 index 0000000..a8ffb25 --- /dev/null +++ b/libbuild2/build/script/parser.hxx @@ -0,0 +1,92 @@ +// file : libbuild2/build/script/parser.hxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBUILD2_BUILD_SCRIPT_PARSER_HXX +#define LIBBUILD2_BUILD_SCRIPT_PARSER_HXX + +#include <libbuild2/types.hxx> +#include <libbuild2/forward.hxx> +#include <libbuild2/utility.hxx> + +#include <libbuild2/diagnostics.hxx> + +#include <libbuild2/script/parser.hxx> + +#include <libbuild2/build/script/token.hxx> +#include <libbuild2/build/script/script.hxx> + +namespace build2 +{ + namespace build + { + namespace script + { + class runner; + + class parser: public build2::script::parser + { + // Pre-parse. Issue diagnostics and throw failed in case of an error. + // + public: + parser (context& c): build2::script::parser (c) {} + + void + pre_parse (istream&, const path_name&, uint64_t line, script&); + + // Recursive descent parser. + // + // Usually (but not always) parse functions receive the token/type + // from which it should start consuming and in return the token/type + // should contain the first token that has not been consumed. + // + // Functions that are called parse_*() rather than pre_parse_*() are + // used for both stages. + // + protected: + token + pre_parse_script (); + + void + pre_parse_line (token&, token_type&, bool if_line = false); + + void + pre_parse_if_else (token&, token_type&); + + command_expr + parse_command_line (token&, token_type&); + + // Workaround for GCC 4.9 that fails to compile the base class + // protected member function call from a lambda defined in the derived + // class. + // + using build2::parser::apply_value_attributes; + + // Execute. Issue diagnostics and throw failed in case of an error. + // + public: + void + execute (environment&, runner&); + + protected: + void + exec_script (); + + // Customization hooks. + // + protected: + virtual lookup + lookup_variable (name&&, string&&, const location&) override; + + protected: + script* script_; + + // Execute state. + // + runner* runner_; + environment* environment_; + }; + } + } +} + +#endif // LIBBUILD2_BUILD_SCRIPT_PARSER_HXX |