go.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/go/go.ts
  8. var 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. var 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. "&",
  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. ".",
  134. ":"
  135. ],
  136. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  137. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  138. tokenizer: {
  139. root: [
  140. [
  141. /[a-zA-Z_]\w*/,
  142. {
  143. cases: {
  144. "@keywords": { token: "keyword.$0" },
  145. "@default": "identifier"
  146. }
  147. }
  148. ],
  149. { include: "@whitespace" },
  150. [/\[\[.*\]\]/, "annotation"],
  151. [/^\s*#\w+/, "keyword"],
  152. [/[{}()\[\]]/, "@brackets"],
  153. [/[<>](?!@symbols)/, "@brackets"],
  154. [
  155. /@symbols/,
  156. {
  157. cases: {
  158. "@operators": "delimiter",
  159. "@default": ""
  160. }
  161. }
  162. ],
  163. [/\d*\d+[eE]([\-+]?\d+)?/, "number.float"],
  164. [/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
  165. [/0[xX][0-9a-fA-F']*[0-9a-fA-F]/, "number.hex"],
  166. [/0[0-7']*[0-7]/, "number.octal"],
  167. [/0[bB][0-1']*[0-1]/, "number.binary"],
  168. [/\d[\d']*/, "number"],
  169. [/\d/, "number"],
  170. [/[;,.]/, "delimiter"],
  171. [/"([^"\\]|\\.)*$/, "string.invalid"],
  172. [/"/, "string", "@string"],
  173. [/`/, "string", "@rawstring"],
  174. [/'[^\\']'/, "string"],
  175. [/(')(@escapes)(')/, ["string", "string.escape", "string"]],
  176. [/'/, "string.invalid"]
  177. ],
  178. whitespace: [
  179. [/[ \t\r\n]+/, ""],
  180. [/\/\*\*(?!\/)/, "comment.doc", "@doccomment"],
  181. [/\/\*/, "comment", "@comment"],
  182. [/\/\/.*$/, "comment"]
  183. ],
  184. comment: [
  185. [/[^\/*]+/, "comment"],
  186. [/\*\//, "comment", "@pop"],
  187. [/[\/*]/, "comment"]
  188. ],
  189. doccomment: [
  190. [/[^\/*]+/, "comment.doc"],
  191. [/\/\*/, "comment.doc.invalid"],
  192. [/\*\//, "comment.doc", "@pop"],
  193. [/[\/*]/, "comment.doc"]
  194. ],
  195. string: [
  196. [/[^\\"]+/, "string"],
  197. [/@escapes/, "string.escape"],
  198. [/\\./, "string.escape.invalid"],
  199. [/"/, "string", "@pop"]
  200. ],
  201. rawstring: [
  202. [/[^\`]/, "string"],
  203. [/`/, "string", "@pop"]
  204. ]
  205. }
  206. };
  207. export {
  208. conf,
  209. language
  210. };