prism-wren.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // https://wren.io/
  2. Prism.languages.wren = {
  3. // Multiline comments in Wren can have nested multiline comments
  4. // Comments: // and /* */
  5. 'comment': [
  6. {
  7. // support 3 levels of nesting
  8. // regex: \/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\/
  9. pattern: /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*))*\*\/)*\*\/)*\*\//,
  10. greedy: true
  11. },
  12. {
  13. pattern: /(^|[^\\:])\/\/.*/,
  14. lookbehind: true,
  15. greedy: true
  16. }
  17. ],
  18. // Triple quoted strings are multiline but cannot have interpolation (raw strings)
  19. // Based on prism-python.js
  20. 'triple-quoted-string': {
  21. pattern: /"""[\s\S]*?"""/,
  22. greedy: true,
  23. alias: 'string'
  24. },
  25. // see below
  26. 'string-literal': null,
  27. // #!/usr/bin/env wren on the first line
  28. 'hashbang': {
  29. pattern: /^#!\/.+/,
  30. greedy: true,
  31. alias: 'comment'
  32. },
  33. // Attributes are special keywords to add meta data to classes
  34. 'attribute': {
  35. // #! attributes are stored in class properties
  36. // #!myvar = true
  37. // #attributes are not stored and dismissed at compilation
  38. pattern: /#!?[ \t\u3000]*\w+/,
  39. alias: 'keyword'
  40. },
  41. 'class-name': [
  42. {
  43. // class definition
  44. // class Meta {}
  45. pattern: /(\bclass\s+)\w+/,
  46. lookbehind: true
  47. },
  48. // A class must always start with an uppercase.
  49. // File.read
  50. /\b[A-Z][a-z\d_]*\b/,
  51. ],
  52. // A constant can be a variable, class, property or method. Just named in all uppercase letters
  53. 'constant': /\b[A-Z][A-Z\d_]*\b/,
  54. 'null': {
  55. pattern: /\bnull\b/,
  56. alias: 'keyword'
  57. },
  58. 'keyword': /\b(?:as|break|class|construct|continue|else|for|foreign|if|import|in|is|return|static|super|this|var|while)\b/,
  59. 'boolean': /\b(?:false|true)\b/,
  60. 'number': /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
  61. // Functions can be Class.method()
  62. 'function': /\b[a-z_]\w*(?=\s*[({])/i,
  63. 'operator': /<<|>>|[=!<>]=?|&&|\|\||[-+*/%~^&|?:]|\.{2,3}/,
  64. 'punctuation': /[\[\](){}.,;]/,
  65. };
  66. Prism.languages.wren['string-literal'] = {
  67. // A single quote string is multiline and can have interpolation (similar to JS backticks ``)
  68. pattern: /(^|[^\\"])"(?:[^\\"%]|\\[\s\S]|%(?!\()|%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\))*"/,
  69. lookbehind: true,
  70. greedy: true,
  71. inside: {
  72. 'interpolation': {
  73. // "%(interpolation)"
  74. pattern: /((?:^|[^\\])(?:\\{2})*)%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\)/,
  75. lookbehind: true,
  76. inside: {
  77. 'expression': {
  78. pattern: /^(%\()[\s\S]+(?=\)$)/,
  79. lookbehind: true,
  80. inside: Prism.languages.wren
  81. },
  82. 'interpolation-punctuation': {
  83. pattern: /^%\(|\)$/,
  84. alias: 'punctuation'
  85. },
  86. }
  87. },
  88. 'string': /[\s\S]+/
  89. }
  90. };