UNPKG

3.14 kBJavaScriptView Raw
1/*
2Language: Device Tree
3Description: *.dts files used in the Linux kernel
4Author: Martin Braun <martin.braun@ettus.com>, Moritz Fischer <moritz.fischer@ettus.com>
5Website: https://elinux.org/Device_Tree_Reference
6Category: config
7*/
8
9/** @type LanguageFn */
10function dts(hljs) {
11 const STRINGS = {
12 className: 'string',
13 variants: [
14 hljs.inherit(hljs.QUOTE_STRING_MODE, {
15 begin: '((u8?|U)|L)?"'
16 }),
17 {
18 begin: '(u8?|U)?R"',
19 end: '"',
20 contains: [hljs.BACKSLASH_ESCAPE]
21 },
22 {
23 begin: '\'\\\\?.',
24 end: '\'',
25 illegal: '.'
26 }
27 ]
28 };
29
30 const NUMBERS = {
31 className: 'number',
32 variants: [
33 {
34 begin: '\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)'
35 },
36 {
37 begin: hljs.C_NUMBER_RE
38 }
39 ],
40 relevance: 0
41 };
42
43 const PREPROCESSOR = {
44 className: 'meta',
45 begin: '#',
46 end: '$',
47 keywords: {
48 keyword: 'if else elif endif define undef ifdef ifndef'
49 },
50 contains: [
51 {
52 begin: /\\\n/,
53 relevance: 0
54 },
55 {
56 beginKeywords: 'include',
57 end: '$',
58 keywords: {
59 keyword: 'include'
60 },
61 contains: [
62 hljs.inherit(STRINGS, {
63 className: 'string'
64 }),
65 {
66 className: 'string',
67 begin: '<',
68 end: '>',
69 illegal: '\\n'
70 }
71 ]
72 },
73 STRINGS,
74 hljs.C_LINE_COMMENT_MODE,
75 hljs.C_BLOCK_COMMENT_MODE
76 ]
77 };
78
79 const REFERENCE = {
80 className: 'variable',
81 begin: /&[a-z\d_]*\b/
82 };
83
84 const KEYWORD = {
85 className: 'keyword',
86 begin: '/[a-z][a-z\\d-]*/'
87 };
88
89 const LABEL = {
90 className: 'symbol',
91 begin: '^\\s*[a-zA-Z_][a-zA-Z\\d_]*:'
92 };
93
94 const CELL_PROPERTY = {
95 className: 'params',
96 relevance: 0,
97 begin: '<',
98 end: '>',
99 contains: [
100 NUMBERS,
101 REFERENCE
102 ]
103 };
104
105 const NODE = {
106 className: 'title.class',
107 begin: /[a-zA-Z_][a-zA-Z\d_@-]*(?=\s\{)/
108 };
109
110 const ROOT_NODE = {
111 className: 'title.class',
112 begin: /^\/(?=\s*\{)/,
113 relevance: 10
114 };
115
116 // TODO: `attribute` might be the right scope here, unsure
117 // I'm not sure if all these key names have semantic meaning or not
118 const ATTR_NO_VALUE = {
119 match: /[a-z][a-z-,]+(?=;)/,
120 relevance: 0,
121 scope: "attr"
122 };
123 const ATTR = {
124 relevance: 0,
125 match: [
126 /[a-z][a-z-,]+/,
127 /\s*/,
128 /=/
129 ],
130 scope: {
131 1: "attr",
132 3: "operator"
133 }
134 };
135
136 const PUNC = {
137 scope: "punctuation",
138 relevance: 0,
139 // `};` combined is just to avoid tons of useless punctuation nodes
140 match: /\};|[;{}]/
141 };
142
143 return {
144 name: 'Device Tree',
145 contains: [
146 ROOT_NODE,
147 REFERENCE,
148 KEYWORD,
149 LABEL,
150 NODE,
151 ATTR,
152 ATTR_NO_VALUE,
153 CELL_PROPERTY,
154 hljs.C_LINE_COMMENT_MODE,
155 hljs.C_BLOCK_COMMENT_MODE,
156 NUMBERS,
157 STRINGS,
158 PREPROCESSOR,
159 PUNC,
160 {
161 begin: hljs.IDENT_RE + '::',
162 keywords: ""
163 }
164 ]
165 };
166}
167
168export { dts as default };