css.js 7.5 KB

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