scss.js 11 KB

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