dts.js 3.0 KB

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