prism-chaiscript.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Prism.languages.chaiscript = Prism.languages.extend('clike', {
  2. 'string': {
  3. pattern: /(^|[^\\])'(?:[^'\\]|\\[\s\S])*'/,
  4. lookbehind: true,
  5. greedy: true
  6. },
  7. 'class-name': [
  8. {
  9. // e.g. class Rectangle { ... }
  10. pattern: /(\bclass\s+)\w+/,
  11. lookbehind: true
  12. },
  13. {
  14. // e.g. attr Rectangle::height, def Rectangle::area() { ... }
  15. pattern: /(\b(?:attr|def)\s+)\w+(?=\s*::)/,
  16. lookbehind: true
  17. }
  18. ],
  19. 'keyword': /\b(?:attr|auto|break|case|catch|class|continue|def|default|else|finally|for|fun|global|if|return|switch|this|try|var|while)\b/,
  20. 'number': [
  21. Prism.languages.cpp.number,
  22. /\b(?:Infinity|NaN)\b/
  23. ],
  24. 'operator': />>=?|<<=?|\|\||&&|:[:=]?|--|\+\+|[=!<>+\-*/%|&^]=?|[?~]|`[^`\r\n]{1,4}`/,
  25. });
  26. Prism.languages.insertBefore('chaiscript', 'operator', {
  27. 'parameter-type': {
  28. // e.g. def foo(int x, Vector y) {...}
  29. pattern: /([,(]\s*)\w+(?=\s+\w)/,
  30. lookbehind: true,
  31. alias: 'class-name'
  32. },
  33. });
  34. Prism.languages.insertBefore('chaiscript', 'string', {
  35. 'string-interpolation': {
  36. pattern: /(^|[^\\])"(?:[^"$\\]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*"/,
  37. lookbehind: true,
  38. greedy: true,
  39. inside: {
  40. 'interpolation': {
  41. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/,
  42. lookbehind: true,
  43. inside: {
  44. 'interpolation-expression': {
  45. pattern: /(^\$\{)[\s\S]+(?=\}$)/,
  46. lookbehind: true,
  47. inside: Prism.languages.chaiscript
  48. },
  49. 'interpolation-punctuation': {
  50. pattern: /^\$\{|\}$/,
  51. alias: 'punctuation'
  52. }
  53. }
  54. },
  55. 'string': /[\s\S]+/
  56. }
  57. },
  58. });