diff options
-rw-r--r-- | libbuild2/build/script/parser.cxx | 6 | ||||
-rw-r--r-- | libbuild2/parser.cxx | 39 | ||||
-rw-r--r-- | libbuild2/parser.hxx | 1 | ||||
-rw-r--r-- | libbuild2/script/parser.cxx | 12 | ||||
-rw-r--r-- | libbuild2/test/script/parser.cxx | 2 |
5 files changed, 35 insertions, 25 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx index 8b8aa38..372c622 100644 --- a/libbuild2/build/script/parser.cxx +++ b/libbuild2/build/script/parser.cxx @@ -445,7 +445,7 @@ namespace build2 // be printed, thus we parse it in the value lexer mode. // mode (lexer_mode::value); - parse_names (t, tt, pattern_mode::preserve); + parse_names (t, tt, pattern_mode::ignore); return nullopt; } else if (v == "depdb") @@ -567,7 +567,7 @@ namespace build2 // Parse the rest of the line and bail out. // - parse_names (t, tt, pattern_mode::preserve); + parse_names (t, tt, pattern_mode::ignore); return nullopt; } } @@ -627,7 +627,7 @@ namespace build2 pr = parse_names (t, tt, ns, - pattern_mode::preserve, + pattern_mode::ignore, true /* chunk */, "command line", nullptr); diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 244dbfc..f152b17 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1127,6 +1127,9 @@ namespace build2 { attributes_push (t, tt); + // Variable names should not contain patterns so we preserve them here + // and diagnose in parse_variable_name(). + // location nloc (get_location (t)); names ns (parse_names (t, tt, pattern_mode::preserve, "variable name")); @@ -1267,7 +1270,7 @@ namespace build2 fail (t) << "expected c++ recipe version instead of " << t; location nloc (get_location (t)); - names ns (parse_names (t, tt, pattern_mode::preserve)); + names ns (parse_names (t, tt, pattern_mode::ignore)); uint64_t ver; try @@ -2238,7 +2241,7 @@ namespace build2 { args = convert<strings> ( tt != type::newline && tt != type::eos - ? parse_names (t, tt, pattern_mode::preserve, "argument", nullptr) + ? parse_names (t, tt, pattern_mode::expand, "argument", nullptr) : names ()); } catch (const invalid_argument& e) @@ -2602,7 +2605,7 @@ namespace build2 ns = convert<strings> ( tt != type::newline && tt != type::eos ? parse_names (t, tt, - pattern_mode::preserve, + pattern_mode::ignore, "environment variable name", nullptr) : names ()); @@ -2878,7 +2881,7 @@ namespace build2 next (t, tt); const location l (get_location (t)); names ns (tt != type::newline && tt != type::eos - ? parse_names (t, tt, pattern_mode::preserve, "module", nullptr) + ? parse_names (t, tt, pattern_mode::ignore, "module", nullptr) : names ()); for (auto i (ns.begin ()); i != ns.end (); ++i) @@ -3193,7 +3196,7 @@ namespace build2 if (ns.empty () || ns[0].empty ()) fail (l) << "function name expected after ':'"; - if (!ns[0].simple ()) + if (ns[0].pattern || !ns[0].simple ()) fail (l) << "function name expected instead of " << ns[0]; e.func = move (ns[0].value); @@ -3297,7 +3300,7 @@ namespace build2 auto parse_pattern_with_attributes = [this] (token& t, type& tt) { return parse_value_with_attributes ( - t, tt, pattern_mode::preserve, "pattern", nullptr); + t, tt, pattern_mode::ignore, "pattern", nullptr); }; for (size_t i (0);; ++i) @@ -3660,7 +3663,7 @@ namespace build2 // names ns (tt != type::newline && tt != type::eos ? parse_names (t, tt, - pattern_mode::preserve, + pattern_mode::ignore, "description", nullptr) : names ()); @@ -3760,6 +3763,11 @@ namespace build2 name& n (*i++); name o (n.pair ? move (*i++) : name ()); + // @@ TODO + // + if (n.pattern) + fail (l) << "dumping target patterns no yet supported"; + const target* t (enter_target::find_target (*this, n, o, l, trace)); if (t != nullptr) @@ -3787,7 +3795,7 @@ namespace build2 // The list should contain a single, simple name. // - if (ns.size () != 1 || !ns[0].simple () || ns[0].empty ()) + if (ns.size () != 1 || ns[0].pattern || !ns[0].simple () || ns[0].empty ()) fail (l) << "expected variable name instead of " << ns; // Note that the overridability can still be restricted (e.g., by a module @@ -4489,7 +4497,8 @@ namespace build2 if (v.type != nullptr || !v || v.as<names> ().size () != 1) fail (l) << "expected target before ':'"; - if (n.type != nullptr || !n || n.as<names> ().size () != 1) + if (n.type != nullptr || !n || n.as<names> ().size () != 1 || + n.as<names> ()[0].pattern) fail (nl) << "expected variable name after ':'"; names& ns (v.as<names> ()); @@ -4591,7 +4600,7 @@ namespace build2 const location l (get_location (t)); names ns ( - parse_names (t, tt, pattern_mode::preserve, "attribute", nullptr)); + parse_names (t, tt, pattern_mode::ignore, "attribute", nullptr)); string n; value v; @@ -4615,7 +4624,7 @@ namespace build2 next (t, tt); v = (tt != type::comma && tt != type::rsbrace - ? parse_value (t, tt, pattern_mode::preserve, "attribute value") + ? parse_value (t, tt, pattern_mode::ignore, "attribute value") : value (names ())); expire_mode (); @@ -5907,7 +5916,7 @@ namespace build2 }; bool pat (false); - if (pmode != pattern_mode::preserve) + if (pmode == pattern_mode::expand || pmode == pattern_mode::detect) { if (!*pp1 && // Cannot be project-qualified. !quoted && // Cannot be quoted. @@ -5962,7 +5971,7 @@ namespace build2 } } } - else + else if (pmode == pattern_mode::preserve) { // For the preserve mode we treat it as a pattern if it look like // one syntactically. For now we also don't treat leading `+` in the @@ -6282,7 +6291,7 @@ namespace build2 location l (get_location (t)); value v ( tt != type::rsbrace - ? parse_value (t, tt, pattern_mode::preserve, "value subscript") + ? parse_value (t, tt, pattern_mode::ignore, "value subscript") : value (names ())); if (tt != type::rsbrace) @@ -6855,7 +6864,7 @@ namespace build2 // specific (via pre-parse or some such). // params.push_back (tt != type::rparen - ? parse_value (t, tt, pattern_mode::preserve) + ? parse_value (t, tt, pattern_mode::ignore) : value (names ())); } diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx index d6044e9..889d339 100644 --- a/libbuild2/parser.hxx +++ b/libbuild2/parser.hxx @@ -108,6 +108,7 @@ namespace build2 // enum class pattern_mode { + ignore, // Treat as literals. preserve, // Preserve as name pattern. expand, // Expand to non-pattern names. detect // Implementation detail mode (see code for more information). diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx index 4c8a377..ebfd5fc 100644 --- a/libbuild2/script/parser.cxx +++ b/libbuild2/script/parser.cxx @@ -34,7 +34,7 @@ namespace build2 // return tt != type::newline && start_names (tt) ? parse_value (t, tt, - pattern_mode::preserve, + pattern_mode::ignore, "variable value", nullptr) : value (names ()); @@ -101,7 +101,7 @@ namespace build2 { parse_names (t, tt, ns, - pattern_mode::preserve, + pattern_mode::ignore, true /* chunk */, "command line", nullptr); @@ -1073,7 +1073,7 @@ namespace build2 else parse_names (t, tt, ns, - pattern_mode::preserve, + pattern_mode::ignore, true /* chunk */, "command line", nullptr); @@ -1319,7 +1319,7 @@ namespace build2 parse_names (t, tt, ns, - pattern_mode::preserve, + pattern_mode::ignore, true /* chunk */, "env builtin argument", nullptr); @@ -1473,7 +1473,7 @@ namespace build2 next (t, tt); location l (get_location (t)); names ns (parse_names (t, tt, - pattern_mode::preserve, + pattern_mode::ignore, true, "exit status", nullptr)); @@ -1669,7 +1669,7 @@ namespace build2 // names ns (tt != type::newline ? parse_names (t, tt, - pattern_mode::preserve, + pattern_mode::ignore, false, "here-document line", nullptr) diff --git a/libbuild2/test/script/parser.cxx b/libbuild2/test/script/parser.cxx index 0a90f24..9e92f3b 100644 --- a/libbuild2/test/script/parser.cxx +++ b/libbuild2/test/script/parser.cxx @@ -945,7 +945,7 @@ namespace build2 { pre_parse_ = false; args = parse_names (t, tt, - pattern_mode::expand, + pattern_mode::ignore, false, "directive argument", nullptr); |