Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbc7d11

Browse files
committed
Add support for overlay/fragments in DevicetreeLexer and update example DTS file
The DTS lexer had issues with recognizing overlay/fragment syntax, whereby in the following snippet: &i2c1 { serlcd@72 { compatible = "sparkfun,serlcd"; reg = <0x72>; columns = <16>; rows = <2>; command-delay-ms = <10>; special-command-delay-ms = <50>; }; }; the "i2c1" was being tokenized as a Name.Attribute instead of a Name.Function, causing the rest of the lexing to fail as it encountered the "@" character. This fixes the issue by adding proper support for overlay/fragment syntax. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 28ec10c commit bbc7d11

3 files changed

Lines changed: 139 additions & 2 deletions

File tree

pygments/lexers/devicetree.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ class DevicetreeLexer(RegexLexer):
7171
'root': [
7272
include('whitespace'),
7373
include('macro'),
74-
74+
# Overlay/fragment: &label { ... } or &{/path/to/node} { ... }
75+
(r'(&)(?:([A-Za-z_]\w*)|(\{)([^}]+)(\}))(' + _ws + r')(\{)',
76+
bygroups(Operator, Name.Function, Punctuation, Name.Namespace,
77+
Punctuation, Comment.Multiline, Punctuation), 'node'),
7578
# Nodes
7679
(r'([^/*@\s&]+|/)(@?)((?:0x)?[0-9a-fA-F,]*)(' + _ws + r')(\{)',
7780
bygroups(Name.Function, Operator, Number.Integer,
@@ -87,7 +90,10 @@ class DevicetreeLexer(RegexLexer):
8790
'node': [
8891
include('whitespace'),
8992
include('macro'),
90-
93+
# Overlay/fragment: &label { ... } or &{/path/to/node} { ... }
94+
(r'(&)(?:([A-Za-z_]\w*)|(\{)([^}]+)(\}))(' + _ws + r')(\{)',
95+
bygroups(Operator, Name.Function, Punctuation, Name.Namespace,
96+
Punctuation, Comment.Multiline, Punctuation), '#push'),
9197
(r'([^/*@\s&]+|/)(@?)((?:0x)?[0-9a-fA-F,]*)(' + _ws + r')(\{)',
9298
bygroups(Name.Function, Operator, Number.Integer,
9399
Comment.Multiline, Punctuation), '#push'),

tests/examplefiles/devicetree/example.dts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@
7979
};
8080
};
8181

82+
&i2c1 {
83+
serlcd@72 {
84+
compatible = "sparkfun,serlcd";
85+
reg = <0x72>;
86+
columns = <16>;
87+
rows = <2>;
88+
command-delay-ms = <10>;
89+
special-command-delay-ms = <50>;
90+
};
91+
};
92+
93+
&{/soc/i2c@e000d800} {
94+
status = "okay";
95+
};
96+
8297
&i2c3 {
8398
clock-frequency = <100000>;
8499
pinctrl-names = "default";

tests/examplefiles/devicetree/example.dts.output

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)