go.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. comments: {
  7. lineComment: '//',
  8. blockComment: ['/*', '*/']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')']
  14. ],
  15. autoClosingPairs: [
  16. { open: '{', close: '}' },
  17. { open: '[', close: ']' },
  18. { open: '(', close: ')' },
  19. { open: '`', close: '`', notIn: ['string'] },
  20. { open: '"', close: '"', notIn: ['string'] },
  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. { open: "'", close: "'" }
  30. ]
  31. };
  32. export var language = {
  33. defaultToken: '',
  34. tokenPostfix: '.go',
  35. keywords: [
  36. 'break',
  37. 'case',
  38. 'chan',
  39. 'const',
  40. 'continue',
  41. 'default',
  42. 'defer',
  43. 'else',
  44. 'fallthrough',
  45. 'for',
  46. 'func',
  47. 'go',
  48. 'goto',
  49. 'if',
  50. 'import',
  51. 'interface',
  52. 'map',
  53. 'package',
  54. 'range',
  55. 'return',
  56. 'select',
  57. 'struct',
  58. 'switch',
  59. 'type',
  60. 'var',
  61. 'bool',
  62. 'true',
  63. 'false',
  64. 'uint8',
  65. 'uint16',
  66. 'uint32',
  67. 'uint64',
  68. 'int8',
  69. 'int16',
  70. 'int32',
  71. 'int64',
  72. 'float32',
  73. 'float64',
  74. 'complex64',
  75. 'complex128',
  76. 'byte',
  77. 'rune',
  78. 'uint',
  79. 'int',
  80. 'uintptr',
  81. 'string',
  82. 'nil'
  83. ],
  84. operators: [
  85. '+',
  86. '-',
  87. '*',
  88. '/',
  89. '%',
  90. '&',
  91. '|',
  92. '^',
  93. '<<',
  94. '>>',
  95. '&^',
  96. '+=',
  97. '-=',
  98. '*=',
  99. '/=',
  100. '%=',
  101. '&=',
  102. '|=',
  103. '^=',
  104. '<<=',
  105. '>>=',
  106. '&^=',
  107. '&&',
  108. '||',
  109. '<-',
  110. '++',
  111. '--',
  112. '==',
  113. '<',
  114. '>',
  115. '=',
  116. '!',
  117. '!=',
  118. '<=',
  119. '>=',
  120. ':=',
  121. '...',
  122. '(',
  123. ')',
  124. '',
  125. ']',
  126. '{',
  127. '}',
  128. ',',
  129. ';',
  130. '.',
  131. ':'
  132. ],
  133. // we include these common regular expressions
  134. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  135. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  136. // The main tokenizer for our languages
  137. tokenizer: {
  138. root: [
  139. // identifiers and keywords
  140. [
  141. /[a-zA-Z_]\w*/,
  142. {
  143. cases: {
  144. '@keywords': { token: 'keyword.$0' },
  145. '@default': 'identifier'
  146. }
  147. }
  148. ],
  149. // whitespace
  150. { include: '@whitespace' },
  151. // [[ attributes ]].
  152. [/\[\[.*\]\]/, 'annotation'],
  153. // Preprocessor directive
  154. [/^\s*#\w+/, 'keyword'],
  155. // delimiters and operators
  156. [/[{}()\[\]]/, '@brackets'],
  157. [/[<>](?!@symbols)/, '@brackets'],
  158. [
  159. /@symbols/,
  160. {
  161. cases: {
  162. '@operators': 'delimiter',
  163. '@default': ''
  164. }
  165. }
  166. ],
  167. // numbers
  168. [/\d*\d+[eE]([\-+]?\d+)?/, 'number.float'],
  169. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  170. [/0[xX][0-9a-fA-F']*[0-9a-fA-F]/, 'number.hex'],
  171. [/0[0-7']*[0-7]/, 'number.octal'],
  172. [/0[bB][0-1']*[0-1]/, 'number.binary'],
  173. [/\d[\d']*/, 'number'],
  174. [/\d/, 'number'],
  175. // delimiter: after number because of .\d floats
  176. [/[;,.]/, 'delimiter'],
  177. // strings
  178. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  179. [/"/, 'string', '@string'],
  180. [/`/, 'string', '@rawstring'],
  181. // characters
  182. [/'[^\\']'/, 'string'],
  183. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  184. [/'/, 'string.invalid']
  185. ],
  186. whitespace: [
  187. [/[ \t\r\n]+/, ''],
  188. [/\/\*\*(?!\/)/, 'comment.doc', '@doccomment'],
  189. [/\/\*/, 'comment', '@comment'],
  190. [/\/\/.*$/, 'comment']
  191. ],
  192. comment: [
  193. [/[^\/*]+/, 'comment'],
  194. // [/\/\*/, 'comment', '@push' ], // nested comment not allowed :-(
  195. // [/\/\*/, 'comment.invalid' ], // this breaks block comments in the shape of /* //*/
  196. [/\*\//, 'comment', '@pop'],
  197. [/[\/*]/, 'comment']
  198. ],
  199. //Identical copy of comment above, except for the addition of .doc
  200. doccomment: [
  201. [/[^\/*]+/, 'comment.doc'],
  202. // [/\/\*/, 'comment.doc', '@push' ], // nested comment not allowed :-(
  203. [/\/\*/, 'comment.doc.invalid'],
  204. [/\*\//, 'comment.doc', '@pop'],
  205. [/[\/*]/, 'comment.doc']
  206. ],
  207. string: [
  208. [/[^\\"]+/, 'string'],
  209. [/@escapes/, 'string.escape'],
  210. [/\\./, 'string.escape.invalid'],
  211. [/"/, 'string', '@pop']
  212. ],
  213. rawstring: [
  214. [/[^\`]/, 'string'],
  215. [/`/, 'string', '@pop']
  216. ]
  217. }
  218. };