prism-go.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. Prism.languages.go = Prism.languages.extend('clike', {
  2. 'string': {
  3. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,
  4. lookbehind: true,
  5. greedy: true
  6. },
  7. 'keyword': /\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
  8. 'boolean': /\b(?:_|false|iota|nil|true)\b/,
  9. 'number': [
  10. // binary and octal integers
  11. /\b0(?:b[01_]+|o[0-7_]+)i?\b/i,
  12. // hexadecimal integers and floats
  13. /\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,
  14. // decimal integers and floats
  15. /(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i
  16. ],
  17. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  18. 'builtin': /\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/
  19. });
  20. Prism.languages.insertBefore('go', 'string', {
  21. 'char': {
  22. pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/,
  23. greedy: true
  24. }
  25. });
  26. delete Prism.languages.go['class-name'];