go.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. module.exports = function(hljs) {
  2. var GO_KEYWORDS = {
  3. keyword:
  4. 'break default func interface select case map struct chan else goto package switch ' +
  5. 'const fallthrough if range type continue for import return var go defer ' +
  6. 'bool byte complex64 complex128 float32 float64 int8 int16 int32 int64 string uint8 ' +
  7. 'uint16 uint32 uint64 int uint uintptr rune',
  8. literal:
  9. 'true false iota nil',
  10. built_in:
  11. 'append cap close complex copy imag len make new panic print println real recover delete'
  12. };
  13. return {
  14. aliases: ['golang'],
  15. keywords: GO_KEYWORDS,
  16. illegal: '</',
  17. contains: [
  18. hljs.C_LINE_COMMENT_MODE,
  19. hljs.C_BLOCK_COMMENT_MODE,
  20. {
  21. className: 'string',
  22. variants: [
  23. hljs.QUOTE_STRING_MODE,
  24. hljs.APOS_STRING_MODE,
  25. {begin: '`', end: '`'},
  26. ]
  27. },
  28. {
  29. className: 'number',
  30. variants: [
  31. {begin: hljs.C_NUMBER_RE + '[i]', relevance: 1},
  32. hljs.C_NUMBER_MODE
  33. ]
  34. },
  35. {
  36. begin: /:=/ // relevance booster
  37. },
  38. {
  39. className: 'function',
  40. beginKeywords: 'func', end: '\\s*(\\{|$)', excludeEnd: true,
  41. contains: [
  42. hljs.TITLE_MODE,
  43. {
  44. className: 'params',
  45. begin: /\(/, end: /\)/,
  46. keywords: GO_KEYWORDS,
  47. illegal: /["']/
  48. }
  49. ]
  50. }
  51. ]
  52. };
  53. };