less.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. export var conf = {
  6. wordPattern: /(#?-?\d*\.\d\w*%?)|([@#!.:]?[\w-?]+%?)|[@#!.]/g,
  7. comments: {
  8. blockComment: ['/*', '*/'],
  9. lineComment: '//'
  10. },
  11. brackets: [
  12. ['{', '}'],
  13. ['[', ']'],
  14. ['(', ')']
  15. ],
  16. autoClosingPairs: [
  17. { open: '{', close: '}', notIn: ['string', 'comment'] },
  18. { open: '[', close: ']', notIn: ['string', 'comment'] },
  19. { open: '(', close: ')', notIn: ['string', 'comment'] },
  20. { open: '"', close: '"', notIn: ['string', 'comment'] },
  21. { open: "'", close: "'", notIn: ['string', 'comment'] }
  22. ],
  23. surroundingPairs: [
  24. { open: '{', close: '}' },
  25. { open: '[', close: ']' },
  26. { open: '(', close: ')' },
  27. { open: '"', close: '"' },
  28. { open: "'", close: "'" }
  29. ],
  30. folding: {
  31. markers: {
  32. start: new RegExp('^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/'),
  33. end: new RegExp('^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/')
  34. }
  35. }
  36. };
  37. export var language = {
  38. defaultToken: '',
  39. tokenPostfix: '.less',
  40. 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])))*',
  41. 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])))*',
  42. brackets: [
  43. { open: '{', close: '}', token: 'delimiter.curly' },
  44. { open: '[', close: ']', token: 'delimiter.bracket' },
  45. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  46. { open: '<', close: '>', token: 'delimiter.angle' }
  47. ],
  48. tokenizer: {
  49. root: [
  50. { include: '@nestedJSBegin' },
  51. ['[ \\t\\r\\n]+', ''],
  52. { include: '@comments' },
  53. { include: '@keyword' },
  54. { include: '@strings' },
  55. { include: '@numbers' },
  56. ['[*_]?[a-zA-Z\\-\\s]+(?=:.*(;|(\\\\$)))', 'attribute.name', '@attribute'],
  57. ['url(\\-prefix)?\\(', { token: 'tag', next: '@urldeclaration' }],
  58. ['[{}()\\[\\]]', '@brackets'],
  59. ['[,:;]', 'delimiter'],
  60. ['#@identifierPlus', 'tag.id'],
  61. ['&', 'tag'],
  62. ['\\.@identifierPlus(?=\\()', 'tag.class', '@attribute'],
  63. ['\\.@identifierPlus', 'tag.class'],
  64. ['@identifierPlus', 'tag'],
  65. { include: '@operators' },
  66. ['@(@identifier(?=[:,\\)]))', 'variable', '@attribute'],
  67. ['@(@identifier)', 'variable'],
  68. ['@', 'key', '@atRules']
  69. ],
  70. nestedJSBegin: [
  71. ['``', 'delimiter.backtick'],
  72. [
  73. '`',
  74. {
  75. token: 'delimiter.backtick',
  76. next: '@nestedJSEnd',
  77. nextEmbedded: 'text/javascript'
  78. }
  79. ]
  80. ],
  81. nestedJSEnd: [
  82. [
  83. '`',
  84. {
  85. token: 'delimiter.backtick',
  86. next: '@pop',
  87. nextEmbedded: '@pop'
  88. }
  89. ]
  90. ],
  91. operators: [['[<>=\\+\\-\\*\\/\\^\\|\\~]', 'operator']],
  92. keyword: [
  93. [
  94. '(@[\\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',
  95. 'keyword'
  96. ]
  97. ],
  98. urldeclaration: [
  99. { include: '@strings' },
  100. ['[^)\r\n]+', 'string'],
  101. ['\\)', { token: 'tag', next: '@pop' }]
  102. ],
  103. attribute: [
  104. { include: '@nestedJSBegin' },
  105. { include: '@comments' },
  106. { include: '@strings' },
  107. { include: '@numbers' },
  108. { include: '@keyword' },
  109. ['[a-zA-Z\\-]+(?=\\()', 'attribute.value', '@attribute'],
  110. ['>', 'operator', '@pop'],
  111. ['@identifier', 'attribute.value'],
  112. { include: '@operators' },
  113. ['@(@identifier)', 'variable'],
  114. ['[)\\}]', '@brackets', '@pop'],
  115. ['[{}()\\[\\]>]', '@brackets'],
  116. ['[;]', 'delimiter', '@pop'],
  117. ['[,=:]', 'delimiter'],
  118. ['\\s', ''],
  119. ['.', 'attribute.value']
  120. ],
  121. comments: [
  122. ['\\/\\*', 'comment', '@comment'],
  123. ['\\/\\/+.*', 'comment']
  124. ],
  125. comment: [
  126. ['\\*\\/', 'comment', '@pop'],
  127. ['.', 'comment']
  128. ],
  129. numbers: [
  130. [
  131. '(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?',
  132. { token: 'attribute.value.number', next: '@units' }
  133. ],
  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. };