diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2022-10-20 19:39:57 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2022-10-21 11:50:52 +0300 |
commit | 4881a227779a78db1de2a7723e2a86f2b61453b3 (patch) | |
tree | c85ca613cc1a9dc4952d0cc7b0c55603f2b4edfa /libbuild2/test/script | |
parent | e5efed8e25180b9d009edf2a06e5151db107e883 (diff) |
Change attribute syntax in script to come after variable in set and for (set x [...], for x [...])
Diffstat (limited to 'libbuild2/test/script')
-rw-r--r-- | libbuild2/test/script/parser+for.test.testscript | 20 | ||||
-rw-r--r-- | libbuild2/test/script/parser.cxx | 35 |
2 files changed, 32 insertions, 23 deletions
diff --git a/libbuild2/test/script/parser+for.test.testscript b/libbuild2/test/script/parser+for.test.testscript index 5350f28..985f9c9 100644 --- a/libbuild2/test/script/parser+for.test.testscript +++ b/libbuild2/test/script/parser+for.test.testscript @@ -69,10 +69,10 @@ %cmd (b/|'b\\')% EOO - : typed-var-value + : typed-elem : $* <<EOI >>~%EOO% - for [dir_path] x: a b + for x [dir_path]: a b cmd $x end EOI @@ -80,10 +80,10 @@ %cmd (b/|'b\\')% EOO - : typed-values-var-value + : typed-elem-value : $* <<EOI >>~%EOO% - for [dir_path] x: [strings] a b + for x [dir_path]: [strings] a b cmd $x end EOI @@ -472,14 +472,14 @@ echo a b | for x EOO - : typed-var-value + : typed-elem : $* <<EOI >>EOO - echo 'a b' | for -w [dir_path] x + echo 'a b' | for -w x [dir_path] cmd $x end EOI - echo 'a b' | for -w [dir_path] x + echo 'a b' | for -w x [dir_path] EOO } @@ -837,14 +837,14 @@ for x b <a EOO - : typed-var-value + : typed-elem : $* <<EOI >>EOO - for -w [dir_path] x <'a b' + for -w x [dir_path] <'a b' cmd $x end EOI - for -w [dir_path] x <'a b' + for -w x [dir_path] <'a b' EOO } diff --git a/libbuild2/test/script/parser.cxx b/libbuild2/test/script/parser.cxx index a30f666..60656a1 100644 --- a/libbuild2/test/script/parser.cxx +++ b/libbuild2/test/script/parser.cxx @@ -497,27 +497,36 @@ namespace build2 assert (pt.type == type::word && pt.value == "for"); mode (lexer_mode::for_loop); - next_with_attributes (t, tt); + next (t, tt); string& n (t.value); - if (tt == type::lsbrace || // Attributes. - (tt == type::word && // Variable name. - t.qtype == quote_type::unquoted && - (n[0] == '_' || - alpha (n[0]) || - n == "*" || - n == "~" || - n == "@"))) + if (tt == type::word && t.qtype == quote_type::unquoted && + (n[0] == '_' || alpha (n[0]) || // Variable. + n == "*" || n == "~" || n == "@")) // Special variable. { - attributes_push (t, tt); - - if (tt != type::word || t.qtype != quote_type::unquoted) - fail (t) << "expected variable name instead of " << t; + // Detect patterns analogous to parse_variable_name() (so we + // diagnose `for x[string]: ...`). + // + if (n.find_first_of ("[*?") != string::npos) + fail (t) << "expected variable name instead of " << n; if (special_variable (n)) fail (t) << "attempt to set '" << n << "' variable directly"; + if (lexer_->peek_char ().first == '[') + { + token vt (move (t)); + next_with_attributes (t, tt); + + attributes_push (t, tt, + true /* standalone */, + false /* next_token */); + + t = move (vt); + tt = t.type; + } + if (lexer_->peek_char ().first == ':') lt = line_type::cmd_for_args; } |