aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test/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/test/script/parser.hxx
parent3552356a87402727e663131994fa87f48b3cd4fb (diff)
Initial support for ad hoc recipes (still work in progress)
Diffstat (limited to 'libbuild2/test/script/parser.hxx')
-rw-r--r--libbuild2/test/script/parser.hxx124
1 files changed, 10 insertions, 114 deletions
diff --git a/libbuild2/test/script/parser.hxx b/libbuild2/test/script/parser.hxx
index ed3c926..aa64943 100644
--- a/libbuild2/test/script/parser.hxx
+++ b/libbuild2/test/script/parser.hxx
@@ -8,9 +8,10 @@
#include <libbuild2/forward.hxx>
#include <libbuild2/utility.hxx>
-#include <libbuild2/parser.hxx>
#include <libbuild2/diagnostics.hxx>
+#include <libbuild2/script/parser.hxx>
+
#include <libbuild2/test/script/token.hxx>
#include <libbuild2/test/script/script.hxx>
@@ -20,15 +21,14 @@ namespace build2
{
namespace script
{
- class lexer;
class runner;
- class parser: protected build2::parser
+ class parser: public build2::script::parser
{
// Pre-parse. Issue diagnostics and throw failed in case of an error.
//
public:
- parser (context& c): build2::parser (c) {}
+ parser (context& c): build2::script::parser (c) {}
void
pre_parse (script&);
@@ -36,19 +36,6 @@ namespace build2
void
pre_parse (istream&, script&);
- // Helpers.
- //
- // Parse attribute string and perform attribute-guided assignment.
- // Issue diagnostics and throw failed in case of an error.
- //
- void
- apply_value_attributes (const variable*, // Optional.
- value& lhs,
- value&& rhs,
- const string& attributes,
- token_type assign_kind,
- const path_name&); // For diagnostics.
-
// Recursive descent parser.
//
// Usually (but not always) parse functions receive the token/type
@@ -101,83 +88,14 @@ namespace build2
description
parse_trailing_description (token&, token_type&);
- value
- parse_variable_line (token&, token_type&);
-
command_expr
parse_command_line (token&, token_type&);
- // Ordered sequence of here-document redirects that we can expect to
- // see after the command line.
- //
- struct here_redirect
- {
- size_t expr; // Index in command_expr.
- size_t pipe; // Index in command_pipe.
- int fd; // Redirect fd (0 - in, 1 - out, 2 - err).
- };
-
- struct here_doc
- {
- // Redirects that share here_doc. Most of the time we will have no
- // more than 2 (2 - for the roundtrip test cases). Doesn't refer
- // overridden redirects and thus can be empty.
- //
- small_vector<here_redirect, 2> redirects;
-
- string end;
- bool literal; // Literal (single-quote).
- string modifiers;
-
- // Regex introducer ('\0' if not a regex, so can be used as bool).
- //
- char regex;
-
- // Regex global flags. Meaningful if regex != '\0'.
- //
- string regex_flags;
- };
- using here_docs = vector<here_doc>;
-
- pair<command_expr, here_docs>
- parse_command_expr (token&, token_type&);
-
- command_exit
- parse_command_exit (token&, token_type&);
-
- void
- parse_here_documents (token&, token_type&,
- pair<command_expr, here_docs>&);
-
- struct parsed_doc
- {
- union
- {
- string str; // Here-document literal.
- regex_lines regex; // Here-document regex.
- };
-
- bool re; // True if regex.
- uint64_t end_line; // Here-document end marker location.
- uint64_t end_column;
-
- parsed_doc (string, uint64_t line, uint64_t column);
- parsed_doc (regex_lines&&, uint64_t line, uint64_t column);
- parsed_doc (parsed_doc&&); // Note: move constuctible-only type.
- ~parsed_doc ();
- };
-
- parsed_doc
- parse_here_document (token&, token_type&,
- const string&,
- const string& mode,
- char re_intro); // '\0' if not a regex.
-
// Execute. Issue diagnostics and throw failed in case of an error.
//
public:
void
- execute (script& s, runner& r);
+ execute (script&, runner&);
void
execute (scope&, script&, runner&);
@@ -186,13 +104,11 @@ namespace build2
void
exec_scope_body ();
- // Return false if the execution of the scope should be terminated
- // with the success status (e.g., as a result of encountering the exit
- // builtin). For unsuccessful termination the failed exception should
- // be thrown.
+ // Helpers.
//
- bool
- exec_lines (lines::iterator, lines::iterator, size_t&, command_type);
+ public:
+ static bool
+ special_variable (const string&) noexcept;
// Customization hooks.
//
@@ -200,33 +116,13 @@ namespace build2
virtual lookup
lookup_variable (name&&, string&&, const location&) override;
- // Number of quoted tokens since last reset. Note that this includes
- // the peeked token, if any.
- //
- protected:
- size_t
- quoted () const;
-
- void
- reset_quoted (token& current);
-
- size_t replay_quoted_;
-
// Insert id into the id map checking for duplicates.
//
protected:
const string&
insert_id (string, location);
- // Set lexer pointers for both the current and the base classes.
- //
- protected:
- void
- set_lexer (lexer* l);
-
protected:
- using base_parser = build2::parser;
-
script* script_;
// Pre-parse state.
@@ -238,7 +134,7 @@ namespace build2
id_map* id_map_;
include_set* include_set_; // Testscripts already included in this
// scope. Must be absolute and normalized.
- lexer* lexer_;
+
string id_prefix_; // Auto-derived id prefix.
// Execute state.