summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-vala.js
blob: b98969cfa1f5977b97db7bb317ef7ee41191ca95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Prism.languages.vala = Prism.languages.extend('clike', {
  // Classes copied from prism-csharp
  'class-name': [
    {
      // (Foo bar, Bar baz)
      pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?=(?:\?\s+|\*?\s+\*?)\w)/,
      inside: {
        punctuation: /\./,
      },
    },
    {
      // [Foo]
      pattern: /(\[)[A-Z]\w*(?:\.\w+)*\b/,
      lookbehind: true,
      inside: {
        punctuation: /\./,
      },
    },
    {
      // class Foo : Bar
      pattern:
        /(\b(?:class|interface)\s+[A-Z]\w*(?:\.\w+)*\s*:\s*)[A-Z]\w*(?:\.\w+)*\b/,
      lookbehind: true,
      inside: {
        punctuation: /\./,
      },
    },
    {
      // class Foo
      pattern:
        /((?:\b(?:class|enum|interface|new|struct)\s+)|(?:catch\s+\())[A-Z]\w*(?:\.\w+)*\b/,
      lookbehind: true,
      inside: {
        punctuation: /\./,
      },
    },
  ],
  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,
  function: /\b\w+(?=\s*\()/,
  number:
    /(?:\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)(?:f|u?l?)?/i,
  operator: /\+\+|--|&&|\|\||<<=?|>>=?|=>|->|~|[+\-*\/%&^|=!<>]=?|\?\??|\.\.\./,
  punctuation: /[{}[\];(),.:]/,
  constant: /\b[A-Z0-9_]+\b/,
});

Prism.languages.insertBefore('vala', 'string', {
  'raw-string': {
    pattern: /"""[\s\S]*?"""/,
    greedy: true,
    alias: 'string',
  },
  'template-string': {
    pattern: /@"[\s\S]*?"/,
    greedy: true,
    inside: {
      interpolation: {
        pattern: /\$(?:\([^)]*\)|[a-zA-Z]\w*)/,
        inside: {
          delimiter: {
            pattern: /^\$\(?|\)$/,
            alias: 'punctuation',
          },
          rest: Prism.languages.vala,
        },
      },
      string: /[\s\S]+/,
    },
  },
});

Prism.languages.insertBefore('vala', 'keyword', {
  regex: {
    pattern:
      /\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[imsx]{0,4}(?=\s*(?:$|[\r\n,.;})\]]))/,
    greedy: true,
    inside: {
      'regex-source': {
        pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
        lookbehind: true,
        alias: 'language-regex',
        inside: Prism.languages.regex,
      },
      'regex-delimiter': /^\//,
      'regex-flags': /^[a-z]+$/,
    },
  },
});