less.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: '.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. ['`', { token: 'delimiter.backtick', next: '@nestedJSEnd', nextEmbedded: 'text/javascript' }],
  76. ],
  77. nestedJSEnd: [
  78. ['`', { token: 'delimiter.backtick', next: '@pop', nextEmbedded: '@pop' }],
  79. ],
  80. operators: [
  81. ['[<>=\\+\\-\\*\\/\\^\\|\\~]', 'operator']
  82. ],
  83. keyword: [
  84. ['(@[\\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', 'keyword']
  85. ],
  86. urldeclaration: [
  87. { include: '@strings' },
  88. ['[^)\r\n]+', 'string'],
  89. ['\\)', { token: 'tag', next: '@pop' }],
  90. ],
  91. attribute: [
  92. { include: '@nestedJSBegin' },
  93. { include: '@comments' },
  94. { include: '@strings' },
  95. { include: '@numbers' },
  96. { include: '@keyword' },
  97. ['[a-zA-Z\\-]+(?=\\()', 'attribute.value', '@attribute'],
  98. ['>', 'operator', '@pop'],
  99. ['@identifier', 'attribute.value'],
  100. { include: '@operators' },
  101. ['@(@identifier)', 'variable'],
  102. ['[)\\}]', '@brackets', '@pop'],
  103. ['[{}()\\[\\]>]', '@brackets'],
  104. ['[;]', 'delimiter', '@pop'],
  105. ['[,=:]', 'delimiter'],
  106. ['\\s', ''],
  107. ['.', 'attribute.value']
  108. ],
  109. comments: [
  110. ['\\/\\*', 'comment', '@comment'],
  111. ['\\/\\/+.*', 'comment'],
  112. ],
  113. comment: [
  114. ['\\*\\/', 'comment', '@pop'],
  115. ['.', 'comment'],
  116. ],
  117. numbers: [
  118. ['(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?', { token: 'attribute.value.number', next: '@units' }],
  119. ['#[0-9a-fA-F_]+(?!\\w)', 'attribute.value.hex']
  120. ],
  121. units: [
  122. ['(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?', 'attribute.value.unit', '@pop']
  123. ],
  124. strings: [
  125. ['~?"', { token: 'string.delimiter', next: '@stringsEndDoubleQuote' }],
  126. ['~?\'', { token: 'string.delimiter', next: '@stringsEndQuote' }]
  127. ],
  128. stringsEndDoubleQuote: [
  129. ['\\\\"', 'string'],
  130. ['"', { token: 'string.delimiter', next: '@popall' }],
  131. ['.', 'string']
  132. ],
  133. stringsEndQuote: [
  134. ['\\\\\'', 'string'],
  135. ['\'', { token: 'string.delimiter', next: '@popall' }],
  136. ['.', 'string']
  137. ],
  138. atRules: [
  139. { include: '@comments' },
  140. { include: '@strings' },
  141. ['[()]', 'delimiter'],
  142. ['[\\{;]', 'delimiter', '@pop'],
  143. ['.', 'key']
  144. ]
  145. }
  146. };
  147. });