Adapt format.py for attribute conditionals
Allows format.py to format & and | separated conditionals in attribute value fields. Bug: 378692747 Change-Id: I0d9b1eb7b47c3a4052729379c2579b9322997c69 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6020699 Commit-Queue: Alex Gough <ajgo@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1383207}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
8b5c5363bd
commit
44eaeaeb66
mojo/public/tools/mojom/mojom/format
@ -145,6 +145,10 @@ def _format_attribute_list(node, indent, newline=True):
|
||||
lw.write('"')
|
||||
lw.write(attr.value.replace('"', '\\"'))
|
||||
lw.write('"')
|
||||
elif isinstance(attr.value, ast.AttributeValueOrList):
|
||||
lw.write('|'.join(x.name for x in attr.value))
|
||||
elif isinstance(attr.value, ast.AttributeValueAndList):
|
||||
lw.write('&'.join(x.name for x in attr.value))
|
||||
else:
|
||||
raise ValueError(
|
||||
f'Unxpected value type {type(attr.value)} for {attr}')
|
||||
|
@ -9,3 +9,9 @@ struct Struct {
|
||||
// Another field.
|
||||
[ShouldWeEscapeQuotes="did you say\"yes?\""] string c@3; // End comment.
|
||||
};
|
||||
|
||||
[EnableIf=is_one|is_two]
|
||||
struct Struct {
|
||||
[EnableIfNot=is_one&is_blue]
|
||||
string field;
|
||||
};
|
||||
|
@ -11,3 +11,9 @@ struct Struct {
|
||||
[ShouldWeEscapeQuotes="did you say\"yes?\""]
|
||||
string c@3; // End comment.
|
||||
};
|
||||
|
||||
[EnableIf=is_one|is_two]
|
||||
struct Struct {
|
||||
[EnableIfNot=is_one&is_blue]
|
||||
string field;
|
||||
};
|
||||
|
Reference in New Issue
Block a user