yaml.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/yaml/yaml.ts
  8. var conf = {
  9. comments: {
  10. lineComment: "#"
  11. },
  12. brackets: [
  13. ["{", "}"],
  14. ["[", "]"],
  15. ["(", ")"]
  16. ],
  17. autoClosingPairs: [
  18. { open: "{", close: "}" },
  19. { open: "[", close: "]" },
  20. { open: "(", close: ")" },
  21. { open: '"', close: '"' },
  22. { open: "'", close: "'" }
  23. ],
  24. surroundingPairs: [
  25. { open: "{", close: "}" },
  26. { open: "[", close: "]" },
  27. { open: "(", close: ")" },
  28. { open: '"', close: '"' },
  29. { open: "'", close: "'" }
  30. ],
  31. folding: {
  32. offSide: true
  33. }
  34. };
  35. var language = {
  36. tokenPostfix: ".yaml",
  37. brackets: [
  38. { token: "delimiter.bracket", open: "{", close: "}" },
  39. { token: "delimiter.square", open: "[", close: "]" }
  40. ],
  41. keywords: ["true", "True", "TRUE", "false", "False", "FALSE", "null", "Null", "Null", "~"],
  42. numberInteger: /(?:0|[+-]?[0-9]+)/,
  43. numberFloat: /(?:0|[+-]?[0-9]+)(?:\.[0-9]+)?(?:e[-+][1-9][0-9]*)?/,
  44. numberOctal: /0o[0-7]+/,
  45. numberHex: /0x[0-9a-fA-F]+/,
  46. numberInfinity: /[+-]?\.(?:inf|Inf|INF)/,
  47. numberNaN: /\.(?:nan|Nan|NAN)/,
  48. numberDate: /\d{4}-\d\d-\d\d([Tt ]\d\d:\d\d:\d\d(\.\d+)?(( ?[+-]\d\d?(:\d\d)?)|Z)?)?/,
  49. escapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,
  50. tokenizer: {
  51. root: [
  52. { include: "@whitespace" },
  53. { include: "@comment" },
  54. [/%[^ ]+.*$/, "meta.directive"],
  55. [/---/, "operators.directivesEnd"],
  56. [/\.{3}/, "operators.documentEnd"],
  57. [/[-?:](?= )/, "operators"],
  58. { include: "@anchor" },
  59. { include: "@tagHandle" },
  60. { include: "@flowCollections" },
  61. { include: "@blockStyle" },
  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. [/(".*?"|'.*?'|.*?)([ \t]*)(:)( |$)/, ["type", "white", "operators", "white"]],
  70. { include: "@flowScalars" },
  71. [
  72. /[^#]+/,
  73. {
  74. cases: {
  75. "@keywords": "keyword",
  76. "@default": "string"
  77. }
  78. }
  79. ]
  80. ],
  81. object: [
  82. { include: "@whitespace" },
  83. { include: "@comment" },
  84. [/\}/, "@brackets", "@pop"],
  85. [/,/, "delimiter.comma"],
  86. [/:(?= )/, "operators"],
  87. [/(?:".*?"|'.*?'|[^,\{\[]+?)(?=: )/, "type"],
  88. { include: "@flowCollections" },
  89. { include: "@flowScalars" },
  90. { include: "@tagHandle" },
  91. { include: "@anchor" },
  92. { include: "@flowNumber" },
  93. [
  94. /[^\},]+/,
  95. {
  96. cases: {
  97. "@keywords": "keyword",
  98. "@default": "string"
  99. }
  100. }
  101. ]
  102. ],
  103. array: [
  104. { include: "@whitespace" },
  105. { include: "@comment" },
  106. [/\]/, "@brackets", "@pop"],
  107. [/,/, "delimiter.comma"],
  108. { include: "@flowCollections" },
  109. { include: "@flowScalars" },
  110. { include: "@tagHandle" },
  111. { include: "@anchor" },
  112. { include: "@flowNumber" },
  113. [
  114. /[^\],]+/,
  115. {
  116. cases: {
  117. "@keywords": "keyword",
  118. "@default": "string"
  119. }
  120. }
  121. ]
  122. ],
  123. multiString: [[/^( +).+$/, "string", "@multiStringContinued.$1"]],
  124. multiStringContinued: [
  125. [
  126. /^( *).+$/,
  127. {
  128. cases: {
  129. "$1==$S2": "string",
  130. "@default": { token: "@rematch", next: "@popall" }
  131. }
  132. }
  133. ]
  134. ],
  135. whitespace: [[/[ \t\r\n]+/, "white"]],
  136. comment: [[/#.*$/, "comment"]],
  137. flowCollections: [
  138. [/\[/, "@brackets", "@array"],
  139. [/\{/, "@brackets", "@object"]
  140. ],
  141. flowScalars: [
  142. [/"([^"\\]|\\.)*$/, "string.invalid"],
  143. [/'([^'\\]|\\.)*$/, "string.invalid"],
  144. [/'[^']*'/, "string"],
  145. [/"/, "string", "@doubleQuotedString"]
  146. ],
  147. doubleQuotedString: [
  148. [/[^\\"]+/, "string"],
  149. [/@escapes/, "string.escape"],
  150. [/\\./, "string.escape.invalid"],
  151. [/"/, "string", "@pop"]
  152. ],
  153. blockStyle: [[/[>|][0-9]*[+-]?$/, "operators", "@multiString"]],
  154. flowNumber: [
  155. [/@numberInteger(?=[ \t]*[,\]\}])/, "number"],
  156. [/@numberFloat(?=[ \t]*[,\]\}])/, "number.float"],
  157. [/@numberOctal(?=[ \t]*[,\]\}])/, "number.octal"],
  158. [/@numberHex(?=[ \t]*[,\]\}])/, "number.hex"],
  159. [/@numberInfinity(?=[ \t]*[,\]\}])/, "number.infinity"],
  160. [/@numberNaN(?=[ \t]*[,\]\}])/, "number.nan"],
  161. [/@numberDate(?=[ \t]*[,\]\}])/, "number.date"]
  162. ],
  163. tagHandle: [[/\![^ ]*/, "tag"]],
  164. anchor: [[/[&*][^ ]+/, "namespace"]]
  165. }
  166. };
  167. export {
  168. conf,
  169. language
  170. };