scss.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/scss/scss.ts
  8. var 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. var language = {
  41. defaultToken: "",
  42. tokenPostfix: ".scss",
  43. ws: "[ \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: [{ include: "@selector" }],
  53. selector: [
  54. { include: "@comments" },
  55. { include: "@import" },
  56. { include: "@variabledeclaration" },
  57. { include: "@warndebug" },
  58. ["[@](include)", { token: "keyword", next: "@includedeclaration" }],
  59. [
  60. "[@](keyframes|-webkit-keyframes|-moz-keyframes|-o-keyframes)",
  61. { token: "keyword", next: "@keyframedeclaration" }
  62. ],
  63. ["[@](page|content|font-face|-moz-document)", { token: "keyword" }],
  64. ["[@](charset|namespace)", { token: "keyword", next: "@declarationbody" }],
  65. ["[@](function)", { token: "keyword", next: "@functiondeclaration" }],
  66. ["[@](mixin)", { token: "keyword", next: "@mixindeclaration" }],
  67. ["url(\\-prefix)?\\(", { token: "meta", next: "@urldeclaration" }],
  68. { include: "@controlstatement" },
  69. { include: "@selectorname" },
  70. ["[&\\*]", "tag"],
  71. ["[>\\+,]", "delimiter"],
  72. ["\\[", { token: "delimiter.bracket", next: "@selectorattribute" }],
  73. ["{", { token: "delimiter.curly", next: "@selectorbody" }]
  74. ],
  75. selectorbody: [
  76. ["[*_]?@identifier@ws:(?=(\\s|\\d|[^{;}]*[;}]))", "attribute.name", "@rulevalue"],
  77. { include: "@selector" },
  78. ["[@](extend)", { token: "keyword", next: "@extendbody" }],
  79. ["[@](return)", { token: "keyword", next: "@declarationbody" }],
  80. ["}", { token: "delimiter.curly", next: "@pop" }]
  81. ],
  82. selectorname: [
  83. ["#{", { token: "meta", next: "@variableinterpolation" }],
  84. ["(\\.|#(?=[^{])|%|(@identifier)|:)+", "tag"]
  85. ],
  86. selectorattribute: [{ include: "@term" }, ["]", { token: "delimiter.bracket", next: "@pop" }]],
  87. term: [
  88. { include: "@comments" },
  89. ["url(\\-prefix)?\\(", { token: "meta", next: "@urldeclaration" }],
  90. { include: "@functioninvocation" },
  91. { include: "@numbers" },
  92. { include: "@strings" },
  93. { include: "@variablereference" },
  94. ["(and\\b|or\\b|not\\b)", "operator"],
  95. { include: "@name" },
  96. ["([<>=\\+\\-\\*\\/\\^\\|\\~,])", "operator"],
  97. [",", "delimiter"],
  98. ["!default", "literal"],
  99. ["\\(", { token: "delimiter.parenthesis", next: "@parenthizedterm" }]
  100. ],
  101. rulevalue: [
  102. { include: "@term" },
  103. ["!important", "literal"],
  104. [";", "delimiter", "@pop"],
  105. ["{", { token: "delimiter.curly", switchTo: "@nestedproperty" }],
  106. ["(?=})", { token: "", next: "@pop" }]
  107. ],
  108. nestedproperty: [
  109. ["[*_]?@identifier@ws:", "attribute.name", "@rulevalue"],
  110. { include: "@comments" },
  111. ["}", { token: "delimiter.curly", next: "@pop" }]
  112. ],
  113. warndebug: [["[@](warn|debug)", { token: "keyword", next: "@declarationbody" }]],
  114. import: [["[@](import)", { token: "keyword", next: "@declarationbody" }]],
  115. variabledeclaration: [
  116. ["\\$@identifier@ws:", "variable.decl", "@declarationbody"]
  117. ],
  118. urldeclaration: [
  119. { include: "@strings" },
  120. ["[^)\r\n]+", "string"],
  121. ["\\)", { token: "meta", next: "@pop" }]
  122. ],
  123. parenthizedterm: [
  124. { include: "@term" },
  125. ["\\)", { token: "delimiter.parenthesis", next: "@pop" }]
  126. ],
  127. declarationbody: [
  128. { include: "@term" },
  129. [";", "delimiter", "@pop"],
  130. ["(?=})", { token: "", next: "@pop" }]
  131. ],
  132. extendbody: [
  133. { include: "@selectorname" },
  134. ["!optional", "literal"],
  135. [";", "delimiter", "@pop"],
  136. ["(?=})", { token: "", next: "@pop" }]
  137. ],
  138. variablereference: [
  139. ["\\$@identifier", "variable.ref"],
  140. ["\\.\\.\\.", "operator"],
  141. ["#{", { token: "meta", next: "@variableinterpolation" }]
  142. ],
  143. variableinterpolation: [
  144. { include: "@variablereference" },
  145. ["}", { token: "meta", next: "@pop" }]
  146. ],
  147. comments: [
  148. ["\\/\\*", "comment", "@comment"],
  149. ["\\/\\/+.*", "comment"]
  150. ],
  151. comment: [
  152. ["\\*\\/", "comment", "@pop"],
  153. [".", "comment"]
  154. ],
  155. name: [["@identifier", "attribute.value"]],
  156. numbers: [
  157. ["(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?", { token: "number", next: "@units" }],
  158. ["#[0-9a-fA-F_]+(?!\\w)", "number.hex"]
  159. ],
  160. units: [
  161. [
  162. "(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?",
  163. "number",
  164. "@pop"
  165. ]
  166. ],
  167. functiondeclaration: [
  168. ["@identifier@ws\\(", { token: "meta", next: "@parameterdeclaration" }],
  169. ["{", { token: "delimiter.curly", switchTo: "@functionbody" }]
  170. ],
  171. mixindeclaration: [
  172. ["@identifier@ws\\(", { token: "meta", next: "@parameterdeclaration" }],
  173. ["@identifier", "meta"],
  174. ["{", { token: "delimiter.curly", switchTo: "@selectorbody" }]
  175. ],
  176. parameterdeclaration: [
  177. ["\\$@identifier@ws:", "variable.decl"],
  178. ["\\.\\.\\.", "operator"],
  179. [",", "delimiter"],
  180. { include: "@term" },
  181. ["\\)", { token: "meta", next: "@pop" }]
  182. ],
  183. includedeclaration: [
  184. { include: "@functioninvocation" },
  185. ["@identifier", "meta"],
  186. [";", "delimiter", "@pop"],
  187. ["(?=})", { token: "", next: "@pop" }],
  188. ["{", { token: "delimiter.curly", switchTo: "@selectorbody" }]
  189. ],
  190. keyframedeclaration: [
  191. ["@identifier", "meta"],
  192. ["{", { token: "delimiter.curly", switchTo: "@keyframebody" }]
  193. ],
  194. keyframebody: [
  195. { include: "@term" },
  196. ["{", { token: "delimiter.curly", next: "@selectorbody" }],
  197. ["}", { token: "delimiter.curly", next: "@pop" }]
  198. ],
  199. controlstatement: [
  200. [
  201. "[@](if|else|for|while|each|media)",
  202. { token: "keyword.flow", next: "@controlstatementdeclaration" }
  203. ]
  204. ],
  205. controlstatementdeclaration: [
  206. ["(in|from|through|if|to)\\b", { token: "keyword.flow" }],
  207. { include: "@term" },
  208. ["{", { token: "delimiter.curly", switchTo: "@selectorbody" }]
  209. ],
  210. functionbody: [
  211. ["[@](return)", { token: "keyword" }],
  212. { include: "@variabledeclaration" },
  213. { include: "@term" },
  214. { include: "@controlstatement" },
  215. [";", "delimiter"],
  216. ["}", { token: "delimiter.curly", next: "@pop" }]
  217. ],
  218. functioninvocation: [["@identifier\\(", { token: "meta", next: "@functionarguments" }]],
  219. functionarguments: [
  220. ["\\$@identifier@ws:", "attribute.name"],
  221. ["[,]", "delimiter"],
  222. { include: "@term" },
  223. ["\\)", { token: "meta", next: "@pop" }]
  224. ],
  225. strings: [
  226. ['~?"', { token: "string.delimiter", next: "@stringenddoublequote" }],
  227. ["~?'", { token: "string.delimiter", next: "@stringendquote" }]
  228. ],
  229. stringenddoublequote: [
  230. ["\\\\.", "string"],
  231. ['"', { token: "string.delimiter", next: "@pop" }],
  232. [".", "string"]
  233. ],
  234. stringendquote: [
  235. ["\\\\.", "string"],
  236. ["'", { token: "string.delimiter", next: "@pop" }],
  237. [".", "string"]
  238. ]
  239. }
  240. };
  241. export {
  242. conf,
  243. language
  244. };