css.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export var conf = {
  6. wordPattern: /(#?-?\d*\.\d\w*%?)|((::|[@#.!:])?[\w-?]+%?)|::|[@#.!:]/g,
  7. comments: {
  8. blockComment: ['/*', '*/']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')']
  14. ],
  15. autoClosingPairs: [
  16. { open: '{', close: '}', notIn: ['string', 'comment'] },
  17. { open: '[', close: ']', notIn: ['string', 'comment'] },
  18. { open: '(', close: ')', notIn: ['string', 'comment'] },
  19. { open: '"', close: '"', notIn: ['string', 'comment'] },
  20. { open: "'", close: "'", notIn: ['string', 'comment'] }
  21. ],
  22. surroundingPairs: [
  23. { open: '{', close: '}' },
  24. { open: '[', close: ']' },
  25. { open: '(', close: ')' },
  26. { open: '"', close: '"' },
  27. { open: "'", close: "'" }
  28. ],
  29. folding: {
  30. markers: {
  31. start: new RegExp('^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/'),
  32. end: new RegExp('^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/')
  33. }
  34. }
  35. };
  36. export var language = {
  37. defaultToken: '',
  38. tokenPostfix: '.css',
  39. ws: '[ \t\n\r\f]*',
  40. identifier: '-?-?([a-zA-Z]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))([\\w\\-]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))*',
  41. brackets: [
  42. { open: '{', close: '}', token: 'delimiter.bracket' },
  43. { open: '[', close: ']', token: 'delimiter.bracket' },
  44. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  45. { open: '<', close: '>', token: 'delimiter.angle' }
  46. ],
  47. tokenizer: {
  48. root: [{ include: '@selector' }],
  49. selector: [
  50. { include: '@comments' },
  51. { include: '@import' },
  52. { include: '@strings' },
  53. [
  54. '[@](keyframes|-webkit-keyframes|-moz-keyframes|-o-keyframes)',
  55. { token: 'keyword', next: '@keyframedeclaration' }
  56. ],
  57. ['[@](page|content|font-face|-moz-document)', { token: 'keyword' }],
  58. ['[@](charset|namespace)', { token: 'keyword', next: '@declarationbody' }],
  59. [
  60. '(url-prefix)(\\()',
  61. ['attribute.value', { token: 'delimiter.parenthesis', next: '@urldeclaration' }]
  62. ],
  63. [
  64. '(url)(\\()',
  65. ['attribute.value', { token: 'delimiter.parenthesis', next: '@urldeclaration' }]
  66. ],
  67. { include: '@selectorname' },
  68. ['[\\*]', 'tag'],
  69. ['[>\\+,]', 'delimiter'],
  70. ['\\[', { token: 'delimiter.bracket', next: '@selectorattribute' }],
  71. ['{', { token: 'delimiter.bracket', next: '@selectorbody' }]
  72. ],
  73. selectorbody: [
  74. { include: '@comments' },
  75. ['[*_]?@identifier@ws:(?=(\\s|\\d|[^{;}]*[;}]))', 'attribute.name', '@rulevalue'],
  76. ['}', { token: 'delimiter.bracket', next: '@pop' }]
  77. ],
  78. selectorname: [
  79. ['(\\.|#(?=[^{])|%|(@identifier)|:)+', 'tag'] // selector (.foo, div, ...)
  80. ],
  81. selectorattribute: [
  82. { include: '@term' },
  83. [']', { token: 'delimiter.bracket', next: '@pop' }]
  84. ],
  85. term: [
  86. { include: '@comments' },
  87. [
  88. '(url-prefix)(\\()',
  89. ['attribute.value', { token: 'delimiter.parenthesis', next: '@urldeclaration' }]
  90. ],
  91. [
  92. '(url)(\\()',
  93. ['attribute.value', { token: 'delimiter.parenthesis', next: '@urldeclaration' }]
  94. ],
  95. { include: '@functioninvocation' },
  96. { include: '@numbers' },
  97. { include: '@name' },
  98. { include: '@strings' },
  99. ['([<>=\\+\\-\\*\\/\\^\\|\\~,])', 'delimiter'],
  100. [',', 'delimiter']
  101. ],
  102. rulevalue: [
  103. { include: '@comments' },
  104. { include: '@strings' },
  105. { include: '@term' },
  106. ['!important', 'keyword'],
  107. [';', 'delimiter', '@pop'],
  108. ['(?=})', { token: '', next: '@pop' }] // missing semicolon
  109. ],
  110. warndebug: [['[@](warn|debug)', { token: 'keyword', next: '@declarationbody' }]],
  111. import: [['[@](import)', { token: 'keyword', next: '@declarationbody' }]],
  112. urldeclaration: [
  113. { include: '@strings' },
  114. ['[^)\r\n]+', 'string'],
  115. ['\\)', { token: 'delimiter.parenthesis', next: '@pop' }]
  116. ],
  117. parenthizedterm: [
  118. { include: '@term' },
  119. ['\\)', { token: 'delimiter.parenthesis', next: '@pop' }]
  120. ],
  121. declarationbody: [
  122. { include: '@term' },
  123. [';', 'delimiter', '@pop'],
  124. ['(?=})', { token: '', next: '@pop' }] // missing semicolon
  125. ],
  126. comments: [
  127. ['\\/\\*', 'comment', '@comment'],
  128. ['\\/\\/+.*', 'comment']
  129. ],
  130. comment: [
  131. ['\\*\\/', 'comment', '@pop'],
  132. [/[^*/]+/, 'comment'],
  133. [/./, 'comment']
  134. ],
  135. name: [['@identifier', 'attribute.value']],
  136. numbers: [
  137. [
  138. '-?(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?',
  139. { token: 'attribute.value.number', next: '@units' }
  140. ],
  141. ['#[0-9a-fA-F_]+(?!\\w)', 'attribute.value.hex']
  142. ],
  143. units: [
  144. [
  145. '(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?',
  146. 'attribute.value.unit',
  147. '@pop'
  148. ]
  149. ],
  150. keyframedeclaration: [
  151. ['@identifier', 'attribute.value'],
  152. ['{', { token: 'delimiter.bracket', switchTo: '@keyframebody' }]
  153. ],
  154. keyframebody: [
  155. { include: '@term' },
  156. ['{', { token: 'delimiter.bracket', next: '@selectorbody' }],
  157. ['}', { token: 'delimiter.bracket', next: '@pop' }]
  158. ],
  159. functioninvocation: [
  160. ['@identifier\\(', { token: 'attribute.value', next: '@functionarguments' }]
  161. ],
  162. functionarguments: [
  163. ['\\$@identifier@ws:', 'attribute.name'],
  164. ['[,]', 'delimiter'],
  165. { include: '@term' },
  166. ['\\)', { token: 'attribute.value', next: '@pop' }]
  167. ],
  168. strings: [
  169. ['~?"', { token: 'string', next: '@stringenddoublequote' }],
  170. ["~?'", { token: 'string', next: '@stringendquote' }]
  171. ],
  172. stringenddoublequote: [
  173. ['\\\\.', 'string'],
  174. ['"', { token: 'string', next: '@pop' }],
  175. [/[^\\"]+/, 'string'],
  176. ['.', 'string']
  177. ],
  178. stringendquote: [
  179. ['\\\\.', 'string'],
  180. ["'", { token: 'string', next: '@pop' }],
  181. [/[^\\']+/, 'string'],
  182. ['.', 'string']
  183. ]
  184. }
  185. };