dts: dtlib: Fix parsing of character literals
This was allowed due to a misunderstanding:
foo = 'x';
In reality, 'x' works like an integer literal, and is used like this:
foo = < 'x' >;
Fix character literal parsing to match the C tools.
Also fix backslash escape parsing to match the C tools exactly
(get_escape_char() in util.c): \<char> should be turned into <char> if
<char> isn't recognized as a special escape character, instead of being
left alone. This fixes parsing of e.g. '\'' (a character literal with a
single quote in it).
Piggyback some more tests for weird property/node names.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
diff --git a/scripts/dts/testdtlib.py b/scripts/dts/testdtlib.py
index 365f810..6ce282d 100755
--- a/scripts/dts/testdtlib.py
+++ b/scripts/dts/testdtlib.py
@@ -88,6 +88,7 @@
i = /bits/ 16 < 0x10 0x20 (-1) >;
j = /bits/ 32 < 0x10 0x20 (-1) >;
k = /bits/ 64 < 0x10 0x20 (-1) >;
+ l = < 'a' 'b' 'c' >;
};
""",
"""
@@ -105,6 +106,7 @@
i = /bits/ 16 < 0x10 0x20 0xffff >;
j = < 0x10 0x20 0xffffffff >;
k = /bits/ 64 < 0x10 0x20 0xffffffffffffffff >;
+ l = < 0x61 0x62 0x63 >;
};
""")
@@ -200,6 +202,55 @@
".tmp.dts:4 (column 6): parse error: octal escape out of range (> 255)")
#
+ # Test character literal parsing
+ #
+
+ verify_parse(r"""
+/dts-v1/;
+
+/ {
+ a = < '\'' >;
+ b = < '\x12' >;
+};
+""",
+"""
+/dts-v1/;
+
+/ {
+ a = < 0x27 >;
+ b = < 0x12 >;
+};
+""")
+
+ verify_error("""
+/dts-v1/;
+
+/ {
+ // Character literals are not allowed at the top level
+ a = 'x';
+};
+""",
+".tmp.dts:5 (column 6): parse error: malformed value")
+
+ verify_error("""
+/dts-v1/;
+
+/ {
+ a = < '' >;
+};
+""",
+".tmp.dts:4 (column 7): parse error: character literals must be length 1")
+
+ verify_error("""
+/dts-v1/;
+
+/ {
+ a = < '12' >;
+};
+""",
+".tmp.dts:4 (column 7): parse error: character literals must be length 1")
+
+ #
# Test /incbin/
#
@@ -1115,6 +1166,7 @@
not2 = < (!1) >;
not3 = < (!2) >;
nest = < (((--3) + (-2)) * (--(-2))) >;
+ char_lits = < ('a' + 'b') >;
};
""",
"""
@@ -1166,6 +1218,7 @@
not2 = < 0x0 >;
not3 = < 0x0 >;
nest = < 0xfffffffe >;
+ char_lits = < 0xc3 >;
};
""")
@@ -1980,14 +2033,20 @@
// A leading \ is accepted but ignored in node/propert names
\aA0,._+*#?- = &_, &{/aA0,._+*#?@-};
- // Names that overlap with operators
+ // Names that overlap with operators and integer literals
+
+ = [ 00 ];
* = [ 02 ];
- = [ 01 ];
? = [ 03 ];
+ 0 = [ 04 ];
+ 0x123 = [ 05 ];
_: \aA0,._+*#?@- {
};
+
+ 0 {
+ };
};
""",
"""
@@ -1999,8 +2058,12 @@
* = [ 02 ];
- = [ 01 ];
? = [ 03 ];
+ 0 = [ 04 ];
+ 0x123 = [ 05 ];
_: aA0,._+*#?@- {
};
+ 0 {
+ };
};
""")