go.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. Language: Go
  3. Author: Stephan Kountso aka StepLg <steplg@gmail.com>
  4. Contributors: Evgeny Stepanischev <imbolk@gmail.com>
  5. Description: Google go language (golang). For info about language
  6. Website: http://golang.org/
  7. Category: common, system
  8. */
  9. function go(hljs) {
  10. const LITERALS = [
  11. "true",
  12. "false",
  13. "iota",
  14. "nil"
  15. ];
  16. const BUILT_INS = [
  17. "append",
  18. "cap",
  19. "close",
  20. "complex",
  21. "copy",
  22. "imag",
  23. "len",
  24. "make",
  25. "new",
  26. "panic",
  27. "print",
  28. "println",
  29. "real",
  30. "recover",
  31. "delete"
  32. ];
  33. const TYPES = [
  34. "bool",
  35. "byte",
  36. "complex64",
  37. "complex128",
  38. "error",
  39. "float32",
  40. "float64",
  41. "int8",
  42. "int16",
  43. "int32",
  44. "int64",
  45. "string",
  46. "uint8",
  47. "uint16",
  48. "uint32",
  49. "uint64",
  50. "int",
  51. "uint",
  52. "uintptr",
  53. "rune"
  54. ];
  55. const KWS = [
  56. "break",
  57. "case",
  58. "chan",
  59. "const",
  60. "continue",
  61. "default",
  62. "defer",
  63. "else",
  64. "fallthrough",
  65. "for",
  66. "func",
  67. "go",
  68. "goto",
  69. "if",
  70. "import",
  71. "interface",
  72. "map",
  73. "package",
  74. "range",
  75. "return",
  76. "select",
  77. "struct",
  78. "switch",
  79. "type",
  80. "var",
  81. ];
  82. const KEYWORDS = {
  83. keyword: KWS,
  84. type: TYPES,
  85. literal: LITERALS,
  86. built_in: BUILT_INS
  87. };
  88. return {
  89. name: 'Go',
  90. aliases: [ 'golang' ],
  91. keywords: KEYWORDS,
  92. illegal: '</',
  93. contains: [
  94. hljs.C_LINE_COMMENT_MODE,
  95. hljs.C_BLOCK_COMMENT_MODE,
  96. {
  97. className: 'string',
  98. variants: [
  99. hljs.QUOTE_STRING_MODE,
  100. hljs.APOS_STRING_MODE,
  101. {
  102. begin: '`',
  103. end: '`'
  104. }
  105. ]
  106. },
  107. {
  108. className: 'number',
  109. variants: [
  110. {
  111. match: /-?\b0[xX]\.[a-fA-F0-9](_?[a-fA-F0-9])*[pP][+-]?\d(_?\d)*i?/, // hex without a present digit before . (making a digit afterwards required)
  112. relevance: 0
  113. },
  114. {
  115. match: /-?\b0[xX](_?[a-fA-F0-9])+((\.([a-fA-F0-9](_?[a-fA-F0-9])*)?)?[pP][+-]?\d(_?\d)*)?i?/, // hex with a present digit before . (making a digit afterwards optional)
  116. relevance: 0
  117. },
  118. {
  119. match: /-?\b0[oO](_?[0-7])*i?/, // leading 0o octal
  120. relevance: 0
  121. },
  122. {
  123. match: /-?\.\d(_?\d)*([eE][+-]?\d(_?\d)*)?i?/, // decimal without a present digit before . (making a digit afterwards required)
  124. relevance: 0
  125. },
  126. {
  127. match: /-?\b\d(_?\d)*(\.(\d(_?\d)*)?)?([eE][+-]?\d(_?\d)*)?i?/, // decimal with a present digit before . (making a digit afterwards optional)
  128. relevance: 0
  129. }
  130. ]
  131. },
  132. { begin: /:=/ // relevance booster
  133. },
  134. {
  135. className: 'function',
  136. beginKeywords: 'func',
  137. end: '\\s*(\\{|$)',
  138. excludeEnd: true,
  139. contains: [
  140. hljs.TITLE_MODE,
  141. {
  142. className: 'params',
  143. begin: /\(/,
  144. end: /\)/,
  145. endsParent: true,
  146. keywords: KEYWORDS,
  147. illegal: /["']/
  148. }
  149. ]
  150. }
  151. ]
  152. };
  153. }
  154. export { go as default };