prism-nim.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Prism.languages.nim = {
  2. 'comment': {
  3. pattern: /#.*/,
  4. greedy: true
  5. },
  6. 'string': {
  7. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  8. pattern: /(?:\b(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")/,
  9. greedy: true
  10. },
  11. 'char': {
  12. // Character literals are handled specifically to prevent issues with numeric type suffixes
  13. pattern: /'(?:\\(?:\d+|x[\da-fA-F]{0,2}|.)|[^'])'/,
  14. greedy: true
  15. },
  16. 'function': {
  17. pattern: /(?:(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  18. greedy: true,
  19. inside: {
  20. 'operator': /\*$/
  21. }
  22. },
  23. // We don't want to highlight operators (and anything really) inside backticks
  24. 'identifier': {
  25. pattern: /`[^`\r\n]+`/,
  26. greedy: true,
  27. inside: {
  28. 'punctuation': /`/
  29. }
  30. },
  31. // The negative look ahead prevents wrong highlighting of the .. operator
  32. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  33. 'keyword': /\b(?:addr|as|asm|atomic|bind|block|break|case|cast|concept|const|continue|converter|defer|discard|distinct|do|elif|else|end|enum|except|export|finally|for|from|func|generic|if|import|include|interface|iterator|let|macro|method|mixin|nil|object|out|proc|ptr|raise|ref|return|static|template|try|tuple|type|using|var|when|while|with|without|yield)\b/,
  34. 'operator': {
  35. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  36. // but allow the slice operator .. to take precedence over them
  37. // One can define his own operators in Nim so all combination of operators might be an operator.
  38. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|in|is|isnot|mod|not|notin|of|or|shl|shr|xor)\b)/m,
  39. lookbehind: true
  40. },
  41. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  42. };