Commit graph

14 commits

Author SHA1 Message Date
Sasha Smundak
29fdcad56c Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
  my_list: [
    { name: "foo", value: 42, something: true, },
    { name: "bar", value: 34, something: false, },
  ],
}

Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-03-02 17:26:20 -08:00
Logan Chien
3deba3df45 Emit errors on mixed property syntax
This commit refines `compat` condition in `parseProperty()` so that a
module definition would either use the new syntax or the old syntax,
but not something in the between, such as

    cc_library {
        name: "bad_example",
        srcs= ["bad.c"],
    }

Test: lunch aosp_arm64-userdebug; make  # runs unit test
Change-Id: If2d3e5d55edccc28d314d99b83b0f54e5c53ac35
2018-06-26 12:20:08 +08:00
Dan Willemsen
d2c8162ca9 Improve indentation for multi-line expressions
When someone used a multiline string:

    cmd: "..." +
         "...",

bpfmt used to print this out as:

    cmd: "..." +
    "...",

This change doesn't do the quote alignment like I see in some of our
user-created instances of this, but it does indent a single level:

    cmd: "..." +
        "...",

Test: unit tests
Test: Compared bpfmt results before and after across AOSP
Change-Id: I61bf790be9d08a187857b2725facf71e8b38e372
2018-05-07 16:15:33 -07:00
Nan Zhang
f586544ab7 Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.

int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.

Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-02 22:10:47 -07:00
Colin Cross
6b6735d3be printer: support multiple skipped comments
There may be multiple skipped comments in a row, convert
p.skippedComments to a list and add a test.

Change-Id: I30dcff269bee56fd51ef9513dab7c7885c44b7d7
2016-07-12 16:12:09 -07:00
Colin Cross
1e73794d42 Add CommentGroups
Determining which comments are contiguous is difficult once they have
been parsed into an out-of-band comment list, as any intervening nodes
are in a separate structure.  Group the comments into CommentGroups
during the parsing stage instead.

Change-Id: I9444c58e75333b7521b58dbfbd36ff29d139b6e3
2016-06-14 15:26:49 -07:00
Colin Cross
e32cc80f20 Refactor blueprint parser nodes to an interface
Refactor the blueprint parser Value object, which contained a Type enum
and members to hold every possible type, into an interface (now called
Expression).  Rename the existing Expression object that represented a binary
operator Operator.

Also adds and fixes some new printer test cases with mulitline expressions.

Change-Id: Icf4a20f92c8c2a27f18df8ca515a9d7f282ff133
2016-06-08 14:48:53 -07:00
Jamie Gennis
6cafc2cddc Update import paths to include github 2015-03-21 01:03:36 -04:00
Colin Cross
85398a916a Simplify printer whitespace and newline handling
Trying to handle all the whitespace and newline printing inside
printToken got overly complicated, and resulted in a few bugs in
the layout around comments and indentation that were hard to fix.
Rewrite the whitespace and newline handling to be handled directly
by the object printers, using requestSpace() to ensure whitespace
is inserted and requestNewline() to ensure a newline is inserted.

Also fixes unnecessarily left aligning all comments that contain
indentation, and fixes accidentally unindenting comments that are
the last token in their indented block.

Change-Id: I18707802726107cf0b6ec7de9b542d0ec1d2c0dd
2015-03-20 16:55:32 -07:00
Colin Cross
cb7b9ad6ca Go back to the old Blueprints file format
Switch back to:
moduleType {
    name: value,
    arch: {
        x86: {
            name: value,
        },
    },
}

This provides better consistency between properties defined at the
top level of a module and properties defined inside a map.

The parser will continue to support the other format for now, but the
printer will only produce the original format.
2015-03-04 14:00:06 -08:00
Colin Cross
b274e6c8e5 Support += assignments
Support += assignments to variables.  Variables are now mutable
up until they are referenced, then they become immutable.  This
will allow variables to be modified in a conditional, or allow
better commenting on why parts of a variable are set.

Change-Id: Iad964da7206b493365fe3686eedd7954e6eaf9a2
2015-03-04 14:00:06 -08:00
Colin Cross
9a103c0ed4 Modify printer to be stricter about extra newlines
The printer was allowing extra newlines in odd places, for example
between a property name and the '=' in a module definition.  Make
newline location stricter by explicitly allowing newlines or
line comments.
2015-03-04 13:57:21 -08:00
Colin Cross
8e0c51192a Add license headers and LICENSE file
Change-Id: I6f7c7374093c0745ee4aa677480376a06648b358
2015-01-23 14:23:27 -08:00
Colin Cross
3e8e74f276 Move blueprint/* up a directory
Make integrating with go tools easier by putting the blueprint package
files in the top level directory of the git project instead of in a
subdirectory called blueprint.

Change-Id: I35c144c5fe7ddf34e478d0c47c50b2f6c92c2a03
2015-01-23 14:23:27 -08:00
Renamed from blueprint/parser/printer_test.go (Browse further)