dts.js 2.6 KB

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