prism-vala.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Prism.languages.vala = Prism.languages.extend('clike', {
  2. // Classes copied from prism-csharp
  3. 'class-name': [
  4. {
  5. // (Foo bar, Bar baz)
  6. pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?=(?:\?\s+|\*?\s+\*?)\w)/,
  7. inside: {
  8. punctuation: /\./
  9. }
  10. },
  11. {
  12. // [Foo]
  13. pattern: /(\[)[A-Z]\w*(?:\.\w+)*\b/,
  14. lookbehind: true,
  15. inside: {
  16. punctuation: /\./
  17. }
  18. },
  19. {
  20. // class Foo : Bar
  21. pattern: /(\b(?:class|interface)\s+[A-Z]\w*(?:\.\w+)*\s*:\s*)[A-Z]\w*(?:\.\w+)*\b/,
  22. lookbehind: true,
  23. inside: {
  24. punctuation: /\./
  25. }
  26. },
  27. {
  28. // class Foo
  29. pattern: /((?:\b(?:class|enum|interface|new|struct)\s+)|(?:catch\s+\())[A-Z]\w*(?:\.\w+)*\b/,
  30. lookbehind: true,
  31. inside: {
  32. punctuation: /\./
  33. }
  34. }
  35. ],
  36. 'keyword': /\b(?:abstract|as|assert|async|base|bool|break|case|catch|char|class|const|construct|continue|default|delegate|delete|do|double|dynamic|else|ensures|enum|errordomain|extern|finally|float|for|foreach|get|if|in|inline|int|int16|int32|int64|int8|interface|internal|is|lock|long|namespace|new|null|out|override|owned|params|private|protected|public|ref|requires|return|set|short|signal|sizeof|size_t|ssize_t|static|string|struct|switch|this|throw|throws|try|typeof|uchar|uint|uint16|uint32|uint64|uint8|ulong|unichar|unowned|ushort|using|value|var|virtual|void|volatile|weak|while|yield)\b/i,
  37. 'function': /\b\w+(?=\s*\()/,
  38. 'number': /(?:\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)(?:f|u?l?)?/i,
  39. 'operator': /\+\+|--|&&|\|\||<<=?|>>=?|=>|->|~|[+\-*\/%&^|=!<>]=?|\?\??|\.\.\./,
  40. 'punctuation': /[{}[\];(),.:]/,
  41. 'constant': /\b[A-Z0-9_]+\b/
  42. });
  43. Prism.languages.insertBefore('vala', 'string', {
  44. 'raw-string': {
  45. pattern: /"""[\s\S]*?"""/,
  46. greedy: true,
  47. alias: 'string'
  48. },
  49. 'template-string': {
  50. pattern: /@"[\s\S]*?"/,
  51. greedy: true,
  52. inside: {
  53. 'interpolation': {
  54. pattern: /\$(?:\([^)]*\)|[a-zA-Z]\w*)/,
  55. inside: {
  56. 'delimiter': {
  57. pattern: /^\$\(?|\)$/,
  58. alias: 'punctuation'
  59. },
  60. rest: Prism.languages.vala
  61. }
  62. },
  63. 'string': /[\s\S]+/
  64. }
  65. }
  66. });
  67. Prism.languages.insertBefore('vala', 'keyword', {
  68. 'regex': {
  69. pattern: /\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[imsx]{0,4}(?=\s*(?:$|[\r\n,.;})\]]))/,
  70. greedy: true,
  71. inside: {
  72. 'regex-source': {
  73. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  74. lookbehind: true,
  75. alias: 'language-regex',
  76. inside: Prism.languages.regex
  77. },
  78. 'regex-delimiter': /^\//,
  79. 'regex-flags': /^[a-z]+$/,
  80. }
  81. }
  82. });