prism-rust.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* TODO
  2. Add support for Markdown notation inside doc comments
  3. Add support for nested block comments...
  4. Match closure params even when not followed by dash or brace
  5. Add better support for macro definition
  6. */
  7. Prism.languages.rust = {
  8. 'comment': [
  9. {
  10. pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
  11. lookbehind: true
  12. },
  13. {
  14. pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/,
  15. lookbehind: true
  16. }
  17. ],
  18. 'string': [
  19. /b?r(#*)"(?:\\?.)*?"\1/,
  20. /b?("|')(?:\\?.)*?\1/
  21. ],
  22. 'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,
  23. 'attribute': {
  24. pattern: /#!?\[.+?\]/,
  25. alias: 'attr-name'
  26. },
  27. 'function': [
  28. /[a-z0-9_]+(?=\s*\()/i,
  29. // Macros can use parens or brackets
  30. /[a-z0-9_]+!(?=\s*\(|\[)/i
  31. ],
  32. 'macro-rules': {
  33. pattern: /[a-z0-9_]+!/i,
  34. alias: 'function'
  35. },
  36. // Hex, oct, bin, dec numbers with visual separators and type suffix
  37. 'number': /\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32)?|f32|f64))?\b/,
  38. // Closure params should not be confused with bitwise OR |
  39. 'closure-params': {
  40. pattern: /\|[^|]*\|(?=\s*[{-])/,
  41. inside: {
  42. 'punctuation': /[\|:,]/,
  43. 'operator': /[&*]/
  44. }
  45. },
  46. 'punctuation': /[{}[\];(),.:]|->/,
  47. 'operator': /[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/
  48. };