prism-scala.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Prism.languages.scala = Prism.languages.extend('java', {
  2. 'triple-quoted-string': {
  3. pattern: /"""[\s\S]*?"""/,
  4. greedy: true,
  5. alias: 'string'
  6. },
  7. 'string': {
  8. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  9. greedy: true
  10. },
  11. 'keyword': /<-|=>|\b(?:abstract|case|catch|class|def|derives|do|else|enum|extends|extension|final|finally|for|forSome|given|if|implicit|import|infix|inline|lazy|match|new|null|object|opaque|open|override|package|private|protected|return|sealed|self|super|this|throw|trait|transparent|try|type|using|val|var|while|with|yield)\b/,
  12. 'number': /\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,
  13. 'builtin': /\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,
  14. 'symbol': /'[^\d\s\\]\w*/
  15. });
  16. Prism.languages.insertBefore('scala', 'triple-quoted-string', {
  17. 'string-interpolation': {
  18. pattern: /\b[a-z]\w*(?:"""(?:[^$]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*?"""|"(?:[^$"\r\n]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*")/i,
  19. greedy: true,
  20. inside: {
  21. 'id': {
  22. pattern: /^\w+/,
  23. greedy: true,
  24. alias: 'function'
  25. },
  26. 'escape': {
  27. pattern: /\\\$"|\$[$"]/,
  28. greedy: true,
  29. alias: 'symbol'
  30. },
  31. 'interpolation': {
  32. pattern: /\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
  33. greedy: true,
  34. inside: {
  35. 'punctuation': /^\$\{?|\}$/,
  36. 'expression': {
  37. pattern: /[\s\S]+/,
  38. inside: Prism.languages.scala
  39. }
  40. }
  41. },
  42. 'string': /[\s\S]+/
  43. }
  44. }
  45. });
  46. delete Prism.languages.scala['class-name'];
  47. delete Prism.languages.scala['function'];
  48. delete Prism.languages.scala['constant'];