yaml.js 6.4 KB

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