aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/parser.cxx
AgeCommit message (Collapse)AuthorFilesLines
2024-09-25Use type-aware iteration in script for-loop (GH issue #436)Boris Kolpackov1-2/+5
2024-08-27Handle invalid scope paths specified in buildfile (GH issue #396)Boris Kolpackov1-14/+28
2024-08-06Rename certain target_set::insert() versions to insert_implied() for clarityBoris Kolpackov1-1/+1
Also clarify the target_decl documentation.
2024-03-19Use new next_word() to observe blank lines for accurate line countBoris Kolpackov1-2/+4
2024-03-01Use original variable name in config reportBoris Kolpackov1-24/+50
2024-02-21Improve diagnosticsBoris Kolpackov1-1/+12
2024-02-20Add json_map and json_set buildfile value typesBoris Kolpackov1-33/+54
These expose the std::map<json_value,json_value> and std::set<json_value> types to buildfiles. New functions: $size(<json-set>) $size(<json-map>) $keys(<json-map>) Note that the $keys() function returns the list of map key as a json array. For example: m = [json_map] 2@([json] a@1 b@2) 1@([json] 1 2) s = [json_set] ([json] x@1 y@2) ([json] a@1 b@2) print ($m[2][b]) # 2 print ($s[([json] y@2 x@1)]) # true
2024-02-20Add string_set buildfile value typeBoris Kolpackov1-0/+1
This exposes the std::set<std::string> type to buildfiles. New functions: $size(<string-set>) Subscript returns true if the value is present and false otherwise (so it is mapped to std::set::contains()). For example: set = [string_set] a b c if ($set[b]) ... Note that append (+=) and prepend (=+) have the same semantics (std::set::insert()). For example: set = [string_set] a b set += c b # a b c set =+ d b # a b c d Example of iteration: set = [string_set] a b c for k: $set ...
2024-02-19Add string_map buildfile value typeBoris Kolpackov1-3/+7
This exposes the std::map<std::string,std::string> type to buildfiles. New functions: $size(<string-map>) $keys(<string-map>) Subscript can be used to lookup a value by key. The result is [null] if there is no value associated with the specified key. For example: map = [string_map] a@1 b@2 c@3 b = ($map[b]) # 2 if ($map[z] == [null]) ... Note that append (+=) is overriding (like std::map::insert_or_assign()) while prepend (=+) is not (like std::map::insert()). In a sense, whatever appears last (from left to right) is kept, which is consistent with what we expect to happen when specifying the same key repeatedly in a literal representation. For example: map = [string_map] a@0 b@2 a@1 # a@1 b@2 map += b@0 c@3 # a@1 b@0 c@3 map =+ b@1 d@4 # a@1 b@0 c@3 d@4 Example of iteration: map = [string_map] a@1 b@2 c@3 for p: $map { k = $first($p) v = $second($p) } While the subscript is mapped to key lookup only, index-based access can be implemented (with a bit of overhead) using the $keys() function: map = [string_map] a@1 b@2 c@3 keys = $keys($m) for i: $integer_sequence(0, $size($keys)) { k = ($keys[$i]) v = ($map[$k]) } Also, this commit changes the naming of other template-based value types (not exposed as buildfile value types) to use C++ template id-like names (e.g., map<string,optional<bool>>).
2024-02-12Add ability to specify recipes in separate filesBoris Kolpackov1-145/+418
This can now be achieved with the new `recipe` directive: recipe <language> <file> Note that similar to the use of if-else and switch directives with recipes, this directive requires explicit % recipe header. For example, instead of: file{foo.output}: {{ echo 'hello' >$path($>) }} We can now write: file{foo.output}: % recipe buildscript hello.buildscript With hello.buildscript containing: echo 'hello' >$path($>) Similarly, for C++ recipes (this time for a pattern), instead of: [rule_name=hello] file{~'/(.+)\.output/'}: % update clean {{ c++ 1 -- -- ... }} We can now write: [rule_name=hello] file{~'/(.+)\.output/'}: % update clean recipe c++ hello.cxx With hello.cxx containing: // c++ 1 -- -- ... Relative <file> paths are resolved using the buildfile directory that contains the `recipe` directive as a base. Note also that this mechanism can be used in exported buildfiles with recipe files placed into build/export/ together with buildfiles.
2024-02-07Add support for nested subscript, use for json accessBoris Kolpackov1-89/+95
2024-02-07Add experimental support for JSON value typesBoris Kolpackov1-24/+100
New types: json json_array json_object New functions: $json.value_type(<json>) $json.value_size(<json>) $json.member_{name,value}(<json-member>) $json.object_names(<json-object>) $json.array_size(<json-array>) $json.array_find(<json-array>, <json>) $json.array_find_index(<json-array>, <json>) $json.load(<path>) $json.parse(<text>) $json.serialize(<json>[, <indentation>]) For example, to load a JSON value from a file: j = $json.load($src_base/board.json) Or to construct it in a buildfile: j = [json] one@1 two@([json] 2 3 4) three@([json] x@1 y@-1) This can also be done incrementally with append/prepend: j = [json_object] j += one@1 j += two@([json] 2 3 4) j += three@([json] x@1 y@-1) Instead of using this JSON-like syntax, one can also specify valid JSON input text: j = [json] '{"one":1, "two":[2, 3, 4], "three":{"x":1, "y":-1}' Besides the above set of functions, other handy ways to access components in a JSON value are iteration and subscript. For example: for m: $j print $member_name($m) $member_value($m) print ($j[three]) A subscript can be nested: print ($j[two][1]) print ($j[three][x]) While a JSON value can be printed directly like any other value, the representation will not be pretty-printed. As a result, for complex JSON values, printing a serialized representation might be a more readable option: info $serialize($j)
2024-02-06Add support for value type-specific subscript and iterationBoris Kolpackov1-89/+128
2024-02-06Fix bunch of maybe used uninitialized warningsBoris Kolpackov1-1/+1
2024-01-16Don't enter exported buildfile as real targets (GH issue #357)Boris Kolpackov1-2/+4
In particular, this used to prevent file_rule from match such targets for clean.
2024-01-15Add no_default_target attribute for source, buildfile import directivesBoris Kolpackov1-12/+56
This attribute can be used to disable the default target semantics for the sources/imported buildfile.
2024-01-15Disable default target semantics when loading {bootstrap,root}.buildBoris Kolpackov1-2/+6
2024-01-15Automatically alias unknown target types of imported targetsBoris Kolpackov1-7/+26
2024-01-15Fail with unable to import rather than unknown target typeBoris Kolpackov1-3/+18
2024-01-11Add ability to alias target type from another projectBoris Kolpackov1-34/+104
The syntax is: define <type> = <scope>/<type>
2024-01-09Allow imported buildfiles to using config.* variables from own projectBoris Kolpackov1-28/+161
2023-12-04Improve parser diagnosticsBoris Kolpackov1-1/+5
2023-11-02Minor diagnostics improvementBoris Kolpackov1-1/+1
2023-11-01Add notion of match optionsBoris Kolpackov1-1/+2
Now, when matching a rule, the caller may request a subset of the full functionality of performing an operation on a target. This is achieved with match options.
2023-10-26Minor diagnostics improvementBoris Kolpackov1-4/+12
2023-08-02Diagnose declarations of targets/prerequisites with abstract target typesBoris Kolpackov1-0/+25
2023-06-26Omit dangling symlink warning for backlinked executablesBoris Kolpackov1-13/+44
2023-06-09Diagnose multiple values in typed concatenation (GH issue #263)Boris Kolpackov1-26/+41
2023-06-08Add support for buildfile importationBoris Kolpackov1-105/+377
2023-05-31Provide implied configure_* and dist_* action registration for ad hoc recipesBoris Kolpackov1-2/+11
This makes it consistent with the existing ad hoc rules semantics.
2023-05-29Explicit group: pattern membersBoris Kolpackov1-12/+18
2023-05-29Explicit group: dynamic membersBoris Kolpackov1-2/+2
2023-05-29Explicit group: static membersBoris Kolpackov1-0/+3
2023-05-29Explicit group: syntax parsingBoris Kolpackov1-121/+403
2023-05-16Enter export stub targets with correct outBoris Kolpackov1-12/+36
2023-05-09Add support for dumping build system state in JSON format (GH issue #182)Boris Kolpackov1-2/+6
Specifically: 1. New --dump-format option. Valid values are `buildfile` and `json-v0.1`. 2. The --dump option now recognizes two additional values: `match-pre` and `match-post` to dump the state of pre/post-operations. The `match` value now only triggers dumping of the main operation.
2023-05-03Add --dump-scope and --dump-target options to limit --dump outputBoris Kolpackov1-2/+2
2023-01-31Minor improvement to diagnosticsBoris Kolpackov1-2/+6
2022-12-19Disable `)` escaping in buildspec, command line variable overridesBoris Kolpackov1-6/+5
Similar to line continuations, that would make directory paths on Windows unusable, for example: b info(C:\myproj\) Note that while this is less of a problem in command line variable overrides, we disable it there for consistency.
2022-12-19Disable line continuation in buildspec, command line variable overridesBoris Kolpackov1-4/+6
Line continuations would make directory paths on Windows unusable, for example: b C:\myproj\
2022-12-19Restore newline escaping (line continuations) in double-quoted stringsBoris Kolpackov1-3/+4
Also make effective escaping in buildspec and command line variable overrides consistent with double-quoted strings.
2022-12-15Add noexcept to move constructors and move assignment operatorsKaren Arutyunov1-6/+6
2022-12-15Improve escape sequence supportBoris Kolpackov1-125/+167
Specifically: 1. In the double-quoted strings we now only do effective escaping of the special `$("\` characters plus `)` for symmetry. 2. There is now support for "escape sequence expansion" in the form $\X where \X can be any of the C/C++ simple escape sequences (\n, \t, etc) plus \0 (which in C/C++ is an octal escape sequence). For example: info "foo$\n$\tbar$\n$\tbaz" Will print: buildfile:1:1: info: foo bar baz
2022-12-14Improve empty simple value to empty list of names reduction heuristicsBoris Kolpackov1-17/+45
Specifically, do not reduce typed RHS empty simple values for prepend/append and additionally for assignment provided LHS is typed and is a container.
2022-12-14Handle NULL values in $string() and $concat() functionsBoris Kolpackov1-1/+2
This is relied upon by the parser to provide conversion/concatenation semantics consistent with untyped values. Note that we handle NULL values only for types that have empty representation.
2022-12-12Adapt to dir_iterator API changeKaren Arutyunov1-1/+14
2022-12-02Fail if scope or target qualification in variable expansion is unknownBoris Kolpackov1-29/+69
There are three options here: we can "fall through" to an outer scope (there is always the global scope backstop; this is the old semantics, sort of), we can return NULL straight away, or we can fail. It feels like in most cases unknown scope or target is a mistake and doing anything other than failing is just making things harder to debug.
2022-11-29Move buildfiles to root_extra, use vector instead of unordered_setBoris Kolpackov1-1/+3
2022-11-29Improve diagnostics for value subscript out of evaluation contextBoris Kolpackov1-2/+21
2022-11-23Rework diag_buffer interface to facilitate correct destruction orderBoris Kolpackov1-1/+1