aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script/parser.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-04-28 08:48:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-05-27 15:47:28 +0200
commitb808c255b6a9ddba085bf5646e7d20ec344f2e2d (patch)
tree32730291f7e6de8ef0a227905520dd66fb4ec0f3 /libbuild2/build/script/parser.hxx
parent3552356a87402727e663131994fa87f48b3cd4fb (diff)
Initial support for ad hoc recipes (still work in progress)
Diffstat (limited to 'libbuild2/build/script/parser.hxx')
-rw-r--r--libbuild2/build/script/parser.hxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx
new file mode 100644
index 0000000..27e7f49
--- /dev/null
+++ b/libbuild2/build/script/parser.hxx
@@ -0,0 +1,96 @@
+// 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) {}
+
+ // Note that the returned script object references the passed path
+ // name.
+ //
+ script
+ pre_parse (istream&, const path_name&, uint64_t line);
+
+ // 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&);
+
+ // Execute. Issue diagnostics and throw failed in case of an error.
+ //
+ public:
+ void
+ execute (const scope& root, const scope& base,
+ environment&, const script&, runner&);
+
+ protected:
+ void
+ exec_script ();
+
+ // Helpers.
+ //
+ public:
+ static bool
+ special_variable (const string&) noexcept;
+
+ // 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