go.js 6.0 KB

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