less.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/less/less.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: ".less",
  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. identifierPlus: "-?-?([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: "@nestedJSBegin" },
  54. ["[ \\t\\r\\n]+", ""],
  55. { include: "@comments" },
  56. { include: "@keyword" },
  57. { include: "@strings" },
  58. { include: "@numbers" },
  59. ["[*_]?[a-zA-Z\\-\\s]+(?=:.*(;|(\\\\$)))", "attribute.name", "@attribute"],
  60. ["url(\\-prefix)?\\(", { token: "tag", next: "@urldeclaration" }],
  61. ["[{}()\\[\\]]", "@brackets"],
  62. ["[,:;]", "delimiter"],
  63. ["#@identifierPlus", "tag.id"],
  64. ["&", "tag"],
  65. ["\\.@identifierPlus(?=\\()", "tag.class", "@attribute"],
  66. ["\\.@identifierPlus", "tag.class"],
  67. ["@identifierPlus", "tag"],
  68. { include: "@operators" },
  69. ["@(@identifier(?=[:,\\)]))", "variable", "@attribute"],
  70. ["@(@identifier)", "variable"],
  71. ["@", "key", "@atRules"]
  72. ],
  73. nestedJSBegin: [
  74. ["``", "delimiter.backtick"],
  75. [
  76. "`",
  77. {
  78. token: "delimiter.backtick",
  79. next: "@nestedJSEnd",
  80. nextEmbedded: "text/javascript"
  81. }
  82. ]
  83. ],
  84. nestedJSEnd: [
  85. [
  86. "`",
  87. {
  88. token: "delimiter.backtick",
  89. next: "@pop",
  90. nextEmbedded: "@pop"
  91. }
  92. ]
  93. ],
  94. operators: [["[<>=\\+\\-\\*\\/\\^\\|\\~]", "operator"]],
  95. keyword: [
  96. [
  97. "(@[\\s]*import|![\\s]*important|true|false|when|iscolor|isnumber|isstring|iskeyword|isurl|ispixel|ispercentage|isem|hue|saturation|lightness|alpha|lighten|darken|saturate|desaturate|fadein|fadeout|fade|spin|mix|round|ceil|floor|percentage)\\b",
  98. "keyword"
  99. ]
  100. ],
  101. urldeclaration: [
  102. { include: "@strings" },
  103. ["[^)\r\n]+", "string"],
  104. ["\\)", { token: "tag", next: "@pop" }]
  105. ],
  106. attribute: [
  107. { include: "@nestedJSBegin" },
  108. { include: "@comments" },
  109. { include: "@strings" },
  110. { include: "@numbers" },
  111. { include: "@keyword" },
  112. ["[a-zA-Z\\-]+(?=\\()", "attribute.value", "@attribute"],
  113. [">", "operator", "@pop"],
  114. ["@identifier", "attribute.value"],
  115. { include: "@operators" },
  116. ["@(@identifier)", "variable"],
  117. ["[)\\}]", "@brackets", "@pop"],
  118. ["[{}()\\[\\]>]", "@brackets"],
  119. ["[;]", "delimiter", "@pop"],
  120. ["[,=:]", "delimiter"],
  121. ["\\s", ""],
  122. [".", "attribute.value"]
  123. ],
  124. comments: [
  125. ["\\/\\*", "comment", "@comment"],
  126. ["\\/\\/+.*", "comment"]
  127. ],
  128. comment: [
  129. ["\\*\\/", "comment", "@pop"],
  130. [".", "comment"]
  131. ],
  132. numbers: [
  133. ["(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?", { token: "attribute.value.number", next: "@units" }],
  134. ["#[0-9a-fA-F_]+(?!\\w)", "attribute.value.hex"]
  135. ],
  136. units: [
  137. [
  138. "(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?",
  139. "attribute.value.unit",
  140. "@pop"
  141. ]
  142. ],
  143. strings: [
  144. ['~?"', { token: "string.delimiter", next: "@stringsEndDoubleQuote" }],
  145. ["~?'", { token: "string.delimiter", next: "@stringsEndQuote" }]
  146. ],
  147. stringsEndDoubleQuote: [
  148. ['\\\\"', "string"],
  149. ['"', { token: "string.delimiter", next: "@popall" }],
  150. [".", "string"]
  151. ],
  152. stringsEndQuote: [
  153. ["\\\\'", "string"],
  154. ["'", { token: "string.delimiter", next: "@popall" }],
  155. [".", "string"]
  156. ],
  157. atRules: [
  158. { include: "@comments" },
  159. { include: "@strings" },
  160. ["[()]", "delimiter"],
  161. ["[\\{;]", "delimiter", "@pop"],
  162. [".", "key"]
  163. ]
  164. }
  165. };
  166. export {
  167. conf,
  168. language
  169. };