dts.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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, {
  14. begin: '((u8?|U)|L)?"'
  15. }),
  16. {
  17. begin: '(u8?|U)?R"',
  18. end: '"',
  19. contains: [hljs.BACKSLASH_ESCAPE]
  20. },
  21. {
  22. begin: '\'\\\\?.',
  23. end: '\'',
  24. illegal: '.'
  25. }
  26. ]
  27. };
  28. const NUMBERS = {
  29. className: 'number',
  30. variants: [
  31. {
  32. begin: '\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)'
  33. },
  34. {
  35. begin: hljs.C_NUMBER_RE
  36. }
  37. ],
  38. relevance: 0
  39. };
  40. const PREPROCESSOR = {
  41. className: 'meta',
  42. begin: '#',
  43. end: '$',
  44. keywords: {
  45. 'meta-keyword': 'if else elif endif define undef ifdef ifndef'
  46. },
  47. contains: [
  48. {
  49. begin: /\\\n/,
  50. relevance: 0
  51. },
  52. {
  53. beginKeywords: 'include',
  54. end: '$',
  55. keywords: {
  56. 'meta-keyword': 'include'
  57. },
  58. contains: [
  59. hljs.inherit(STRINGS, {
  60. className: 'meta-string'
  61. }),
  62. {
  63. className: 'meta-string',
  64. begin: '<',
  65. end: '>',
  66. illegal: '\\n'
  67. }
  68. ]
  69. },
  70. STRINGS,
  71. hljs.C_LINE_COMMENT_MODE,
  72. hljs.C_BLOCK_COMMENT_MODE
  73. ]
  74. };
  75. const DTS_REFERENCE = {
  76. className: 'variable',
  77. begin: /&[a-z\d_]*\b/
  78. };
  79. const DTS_KEYWORD = {
  80. className: 'meta-keyword',
  81. begin: '/[a-z][a-z\\d-]*/'
  82. };
  83. const DTS_LABEL = {
  84. className: 'symbol',
  85. begin: '^\\s*[a-zA-Z_][a-zA-Z\\d_]*:'
  86. };
  87. const DTS_CELL_PROPERTY = {
  88. className: 'params',
  89. begin: '<',
  90. end: '>',
  91. contains: [
  92. NUMBERS,
  93. DTS_REFERENCE
  94. ]
  95. };
  96. const DTS_NODE = {
  97. className: 'class',
  98. begin: /[a-zA-Z_][a-zA-Z\d_@]*\s\{/,
  99. end: /[{;=]/,
  100. returnBegin: true,
  101. excludeEnd: true
  102. };
  103. const DTS_ROOT_NODE = {
  104. className: 'class',
  105. begin: '/\\s*\\{',
  106. end: /\};/,
  107. relevance: 10,
  108. contains: [
  109. DTS_REFERENCE,
  110. DTS_KEYWORD,
  111. DTS_LABEL,
  112. DTS_NODE,
  113. DTS_CELL_PROPERTY,
  114. hljs.C_LINE_COMMENT_MODE,
  115. hljs.C_BLOCK_COMMENT_MODE,
  116. NUMBERS,
  117. STRINGS
  118. ]
  119. };
  120. return {
  121. name: 'Device Tree',
  122. keywords: "",
  123. contains: [
  124. DTS_ROOT_NODE,
  125. DTS_REFERENCE,
  126. DTS_KEYWORD,
  127. DTS_LABEL,
  128. DTS_NODE,
  129. DTS_CELL_PROPERTY,
  130. hljs.C_LINE_COMMENT_MODE,
  131. hljs.C_BLOCK_COMMENT_MODE,
  132. NUMBERS,
  133. STRINGS,
  134. PREPROCESSOR,
  135. {
  136. begin: hljs.IDENT_RE + '::',
  137. keywords: ""
  138. }
  139. ]
  140. };
  141. }
  142. module.exports = dts;