scss.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. lineComment: '//'
  13. },
  14. brackets: [
  15. ['{', '}'],
  16. ['[', ']'],
  17. ['(', ')']
  18. ],
  19. autoClosingPairs: [
  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. { open: '\'', close: '\'', notIn: ['string', 'comment'] },
  25. ],
  26. surroundingPairs: [
  27. { open: '{', close: '}' },
  28. { open: '[', close: ']' },
  29. { open: '(', close: ')' },
  30. { open: '"', close: '"' },
  31. { open: '\'', close: '\'' },
  32. ],
  33. folding: {
  34. markers: {
  35. start: new RegExp("^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/"),
  36. end: new RegExp("^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/")
  37. }
  38. }
  39. };
  40. exports.language = {
  41. defaultToken: '',
  42. tokenPostfix: '.scss',
  43. ws: '[ \t\n\r\f]*',
  44. 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])))*',
  45. brackets: [
  46. { open: '{', close: '}', token: 'delimiter.curly' },
  47. { open: '[', close: ']', token: 'delimiter.bracket' },
  48. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  49. { open: '<', close: '>', token: 'delimiter.angle' }
  50. ],
  51. tokenizer: {
  52. root: [
  53. { include: '@selector' },
  54. ],
  55. selector: [
  56. { include: '@comments' },
  57. { include: '@import' },
  58. { include: '@variabledeclaration' },
  59. { include: '@warndebug' },
  60. ['[@](include)', { token: 'keyword', next: '@includedeclaration' }],
  61. ['[@](keyframes|-webkit-keyframes|-moz-keyframes|-o-keyframes)', { token: 'keyword', next: '@keyframedeclaration' }],
  62. ['[@](page|content|font-face|-moz-document)', { token: 'keyword' }],
  63. ['[@](charset|namespace)', { token: 'keyword', next: '@declarationbody' }],
  64. ['[@](function)', { token: 'keyword', next: '@functiondeclaration' }],
  65. ['[@](mixin)', { token: 'keyword', next: '@mixindeclaration' }],
  66. ['url(\\-prefix)?\\(', { token: 'meta', next: '@urldeclaration' }],
  67. { include: '@controlstatement' },
  68. { include: '@selectorname' },
  69. ['[&\\*]', 'tag'],
  70. ['[>\\+,]', 'delimiter'],
  71. ['\\[', { token: 'delimiter.bracket', next: '@selectorattribute' }],
  72. ['{', { token: 'delimiter.curly', next: '@selectorbody' }],
  73. ],
  74. selectorbody: [
  75. ['[*_]?@identifier@ws:(?=(\\s|\\d|[^{;}]*[;}]))', 'attribute.name', '@rulevalue'],
  76. { include: '@selector' },
  77. ['[@](extend)', { token: 'keyword', next: '@extendbody' }],
  78. ['[@](return)', { token: 'keyword', next: '@declarationbody' }],
  79. ['}', { token: 'delimiter.curly', next: '@pop' }],
  80. ],
  81. selectorname: [
  82. ['#{', { token: 'meta', next: '@variableinterpolation' }],
  83. ['(\\.|#(?=[^{])|%|(@identifier)|:)+', 'tag'],
  84. ],
  85. selectorattribute: [
  86. { include: '@term' },
  87. [']', { token: 'delimiter.bracket', next: '@pop' }],
  88. ],
  89. term: [
  90. { include: '@comments' },
  91. ['url(\\-prefix)?\\(', { token: 'meta', next: '@urldeclaration' }],
  92. { include: '@functioninvocation' },
  93. { include: '@numbers' },
  94. { include: '@strings' },
  95. { include: '@variablereference' },
  96. ['(and\\b|or\\b|not\\b)', 'operator'],
  97. { include: '@name' },
  98. ['([<>=\\+\\-\\*\\/\\^\\|\\~,])', 'operator'],
  99. [',', 'delimiter'],
  100. ['!default', 'literal'],
  101. ['\\(', { token: 'delimiter.parenthesis', next: '@parenthizedterm' }],
  102. ],
  103. rulevalue: [
  104. { include: '@term' },
  105. ['!important', 'literal'],
  106. [';', 'delimiter', '@pop'],
  107. ['{', { token: 'delimiter.curly', switchTo: '@nestedproperty' }],
  108. ['(?=})', { token: '', next: '@pop' }],
  109. ],
  110. nestedproperty: [
  111. ['[*_]?@identifier@ws:', 'attribute.name', '@rulevalue'],
  112. { include: '@comments' },
  113. ['}', { token: 'delimiter.curly', next: '@pop' }],
  114. ],
  115. warndebug: [
  116. ['[@](warn|debug)', { token: 'keyword', next: '@declarationbody' }],
  117. ],
  118. import: [
  119. ['[@](import)', { token: 'keyword', next: '@declarationbody' }],
  120. ],
  121. variabledeclaration: [
  122. ['\\$@identifier@ws:', 'variable.decl', '@declarationbody'],
  123. ],
  124. urldeclaration: [
  125. { include: '@strings' },
  126. ['[^)\r\n]+', 'string'],
  127. ['\\)', { token: 'meta', next: '@pop' }],
  128. ],
  129. parenthizedterm: [
  130. { include: '@term' },
  131. ['\\)', { token: 'delimiter.parenthesis', next: '@pop' }],
  132. ],
  133. declarationbody: [
  134. { include: '@term' },
  135. [';', 'delimiter', '@pop'],
  136. ['(?=})', { token: '', next: '@pop' }],
  137. ],
  138. extendbody: [
  139. { include: '@selectorname' },
  140. ['!optional', 'literal'],
  141. [';', 'delimiter', '@pop'],
  142. ['(?=})', { token: '', next: '@pop' }],
  143. ],
  144. variablereference: [
  145. ['\\$@identifier', 'variable.ref'],
  146. ['\\.\\.\\.', 'operator'],
  147. ['#{', { token: 'meta', next: '@variableinterpolation' }],
  148. ],
  149. variableinterpolation: [
  150. { include: '@variablereference' },
  151. ['}', { token: 'meta', next: '@pop' }],
  152. ],
  153. comments: [
  154. ['\\/\\*', 'comment', '@comment'],
  155. ['\\/\\/+.*', 'comment'],
  156. ],
  157. comment: [
  158. ['\\*\\/', 'comment', '@pop'],
  159. ['.', 'comment'],
  160. ],
  161. name: [
  162. ['@identifier', 'attribute.value'],
  163. ],
  164. numbers: [
  165. ['(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?', { token: 'number', next: '@units' }],
  166. ['#[0-9a-fA-F_]+(?!\\w)', 'number.hex'],
  167. ],
  168. units: [
  169. ['(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?', 'number', '@pop']
  170. ],
  171. functiondeclaration: [
  172. ['@identifier@ws\\(', { token: 'meta', next: '@parameterdeclaration' }],
  173. ['{', { token: 'delimiter.curly', switchTo: '@functionbody' }],
  174. ],
  175. mixindeclaration: [
  176. // mixin with parameters
  177. ['@identifier@ws\\(', { token: 'meta', next: '@parameterdeclaration' }],
  178. // mixin without parameters
  179. ['@identifier', 'meta'],
  180. ['{', { token: 'delimiter.curly', switchTo: '@selectorbody' }],
  181. ],
  182. parameterdeclaration: [
  183. ['\\$@identifier@ws:', 'variable.decl'],
  184. ['\\.\\.\\.', 'operator'],
  185. [',', 'delimiter'],
  186. { include: '@term' },
  187. ['\\)', { token: 'meta', next: '@pop' }],
  188. ],
  189. includedeclaration: [
  190. { include: '@functioninvocation' },
  191. ['@identifier', 'meta'],
  192. [';', 'delimiter', '@pop'],
  193. ['(?=})', { token: '', next: '@pop' }],
  194. ['{', { token: 'delimiter.curly', switchTo: '@selectorbody' }],
  195. ],
  196. keyframedeclaration: [
  197. ['@identifier', 'meta'],
  198. ['{', { token: 'delimiter.curly', switchTo: '@keyframebody' }],
  199. ],
  200. keyframebody: [
  201. { include: '@term' },
  202. ['{', { token: 'delimiter.curly', next: '@selectorbody' }],
  203. ['}', { token: 'delimiter.curly', next: '@pop' }],
  204. ],
  205. controlstatement: [
  206. ['[@](if|else|for|while|each|media)', { token: 'keyword.flow', next: '@controlstatementdeclaration' }],
  207. ],
  208. controlstatementdeclaration: [
  209. ['(in|from|through|if|to)\\b', { token: 'keyword.flow' }],
  210. { include: '@term' },
  211. ['{', { token: 'delimiter.curly', switchTo: '@selectorbody' }],
  212. ],
  213. functionbody: [
  214. ['[@](return)', { token: 'keyword' }],
  215. { include: '@variabledeclaration' },
  216. { include: '@term' },
  217. { include: '@controlstatement' },
  218. [';', 'delimiter'],
  219. ['}', { token: 'delimiter.curly', next: '@pop' }],
  220. ],
  221. functioninvocation: [
  222. ['@identifier\\(', { token: 'meta', next: '@functionarguments' }],
  223. ],
  224. functionarguments: [
  225. ['\\$@identifier@ws:', 'attribute.name'],
  226. ['[,]', 'delimiter'],
  227. { include: '@term' },
  228. ['\\)', { token: 'meta', next: '@pop' }],
  229. ],
  230. strings: [
  231. ['~?"', { token: 'string.delimiter', next: '@stringenddoublequote' }],
  232. ['~?\'', { token: 'string.delimiter', next: '@stringendquote' }]
  233. ],
  234. stringenddoublequote: [
  235. ['\\\\.', 'string'],
  236. ['"', { token: 'string.delimiter', next: '@pop' }],
  237. ['.', 'string']
  238. ],
  239. stringendquote: [
  240. ['\\\\.', 'string'],
  241. ['\'', { token: 'string.delimiter', next: '@pop' }],
  242. ['.', 'string']
  243. ]
  244. }
  245. };
  246. });