yaml.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. define(["require", "exports"], function (require, exports) {
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. exports.conf = {
  5. comments: {
  6. lineComment: '#'
  7. },
  8. brackets: [
  9. ['{', '}'],
  10. ['[', ']'],
  11. ['(', ')']
  12. ],
  13. autoClosingPairs: [
  14. { open: '{', close: '}' },
  15. { open: '[', close: ']' },
  16. { open: '(', close: ')' },
  17. { open: '"', close: '"' },
  18. { open: '\'', close: '\'' },
  19. ],
  20. surroundingPairs: [
  21. { open: '{', close: '}' },
  22. { open: '[', close: ']' },
  23. { open: '(', close: ')' },
  24. { open: '"', close: '"' },
  25. { open: '\'', close: '\'' },
  26. ],
  27. folding: {
  28. offSide: true
  29. }
  30. };
  31. exports.language = {
  32. tokenPostfix: '.yaml',
  33. brackets: [
  34. { token: 'delimiter.bracket', open: '{', close: '}' },
  35. { token: 'delimiter.square', open: '[', close: ']' }
  36. ],
  37. keywords: ['true', 'True', 'TRUE', 'false', 'False', 'FALSE', 'null', 'Null', 'Null', '~'],
  38. numberInteger: /(?:0|[+-]?[0-9]+)/,
  39. numberFloat: /(?:0|[+-]?[0-9]+)(?:\.[0-9]+)?(?:e[-+][1-9][0-9]*)?/,
  40. numberOctal: /0o[0-7]+/,
  41. numberHex: /0x[0-9a-fA-F]+/,
  42. numberInfinity: /[+-]?\.(?:inf|Inf|INF)/,
  43. numberNaN: /\.(?:nan|Nan|NAN)/,
  44. numberDate: /\d{4}-\d\d-\d\d([Tt ]\d\d:\d\d:\d\d(\.\d+)?(( ?[+-]\d\d?(:\d\d)?)|Z)?)?/,
  45. escapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,
  46. tokenizer: {
  47. root: [
  48. { include: '@whitespace' },
  49. { include: '@comment' },
  50. // Directive
  51. [/%[^ ]+.*$/, 'meta.directive'],
  52. // Document Markers
  53. [/---/, 'operators.directivesEnd'],
  54. [/\.{3}/, 'operators.documentEnd'],
  55. // Block Structure Indicators
  56. [/[-?:](?= )/, 'operators'],
  57. { include: '@anchor' },
  58. { include: '@tagHandle' },
  59. { include: '@flowCollections' },
  60. { include: '@blockStyle' },
  61. // Numbers
  62. [/@numberInteger(?![ \t]*\S+)/, 'number'],
  63. [/@numberFloat(?![ \t]*\S+)/, 'number.float'],
  64. [/@numberOctal(?![ \t]*\S+)/, 'number.octal'],
  65. [/@numberHex(?![ \t]*\S+)/, 'number.hex'],
  66. [/@numberInfinity(?![ \t]*\S+)/, 'number.infinity'],
  67. [/@numberNaN(?![ \t]*\S+)/, 'number.nan'],
  68. [/@numberDate(?![ \t]*\S+)/, 'number.date'],
  69. // Key:Value pair
  70. [/(".*?"|'.*?'|.*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']],
  71. { include: '@flowScalars' },
  72. // String nodes
  73. [/.+$/, {
  74. cases: {
  75. '@keywords': 'keyword',
  76. '@default': 'string'
  77. }
  78. }]
  79. ],
  80. // Flow Collection: Flow Mapping
  81. object: [
  82. { include: '@whitespace' },
  83. { include: '@comment' },
  84. // Flow Mapping termination
  85. [/\}/, '@brackets', '@pop'],
  86. // Flow Mapping delimiter
  87. [/,/, 'delimiter.comma'],
  88. // Flow Mapping Key:Value delimiter
  89. [/:(?= )/, 'operators'],
  90. // Flow Mapping Key:Value key
  91. [/(?:".*?"|'.*?'|[^,\{\[]+?)(?=: )/, 'type'],
  92. // Start Flow Style
  93. { include: '@flowCollections' },
  94. { include: '@flowScalars' },
  95. // Scalar Data types
  96. { include: '@tagHandle' },
  97. { include: '@anchor' },
  98. { include: '@flowNumber' },
  99. // Other value (keyword or string)
  100. [/[^\},]+/, {
  101. cases: {
  102. '@keywords': 'keyword',
  103. '@default': 'string'
  104. }
  105. }]
  106. ],
  107. // Flow Collection: Flow Sequence
  108. array: [
  109. { include: '@whitespace' },
  110. { include: '@comment' },
  111. // Flow Sequence termination
  112. [/\]/, '@brackets', '@pop'],
  113. // Flow Sequence delimiter
  114. [/,/, 'delimiter.comma'],
  115. // Start Flow Style
  116. { include: '@flowCollections' },
  117. { include: '@flowScalars' },
  118. // Scalar Data types
  119. { include: '@tagHandle' },
  120. { include: '@anchor' },
  121. { include: '@flowNumber' },
  122. // Other value (keyword or string)
  123. [/[^\],]+/, {
  124. cases: {
  125. '@keywords': 'keyword',
  126. '@default': 'string'
  127. }
  128. }]
  129. ],
  130. // First line of a Block Style
  131. multiString: [
  132. [/^( +).+$/, 'string', '@multiStringContinued.$1']
  133. ],
  134. // Further lines of a Block Style
  135. // Workaround for indentation detection
  136. multiStringContinued: [
  137. [/^( *).+$/, {
  138. cases: {
  139. '$1==$S2': 'string',
  140. '@default': { token: '@rematch', next: '@popall' }
  141. }
  142. }]
  143. ],
  144. whitespace: [
  145. [/[ \t\r\n]+/, 'white']
  146. ],
  147. // Only line comments
  148. comment: [
  149. [/#.*$/, 'comment']
  150. ],
  151. // Start Flow Collections
  152. flowCollections: [
  153. [/\[/, '@brackets', '@array'],
  154. [/\{/, '@brackets', '@object']
  155. ],
  156. // Start Flow Scalars (quoted strings)
  157. flowScalars: [
  158. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  159. [/'([^'\\]|\\.)*$/, 'string.invalid'],
  160. [/'[^']*'/, 'string'],
  161. [/"/, 'string', '@doubleQuotedString']
  162. ],
  163. doubleQuotedString: [
  164. [/[^\\"]+/, 'string'],
  165. [/@escapes/, 'string.escape'],
  166. [/\\./, 'string.escape.invalid'],
  167. [/"/, 'string', '@pop']
  168. ],
  169. // Start Block Scalar
  170. blockStyle: [
  171. [/[>|][0-9]*[+-]?$/, 'operators', '@multiString']
  172. ],
  173. // Numbers in Flow Collections (terminate with ,]})
  174. flowNumber: [
  175. [/@numberInteger(?=[ \t]*[,\]\}])/, 'number'],
  176. [/@numberFloat(?=[ \t]*[,\]\}])/, 'number.float'],
  177. [/@numberOctal(?=[ \t]*[,\]\}])/, 'number.octal'],
  178. [/@numberHex(?=[ \t]*[,\]\}])/, 'number.hex'],
  179. [/@numberInfinity(?=[ \t]*[,\]\}])/, 'number.infinity'],
  180. [/@numberNaN(?=[ \t]*[,\]\}])/, 'number.nan'],
  181. [/@numberDate(?=[ \t]*[,\]\}])/, 'number.date']
  182. ],
  183. tagHandle: [
  184. [/\![^ ]*/, 'tag']
  185. ],
  186. anchor: [
  187. [/[&*][^ ]+/, 'namespace']
  188. ]
  189. }
  190. };
  191. });