ui: make primary cursor blink even if no lua theme has been loaded
[vis.git] / lexers / vala.lua
blob46f074c80bddb06904ff46e2f69aa1f4acecad7c
1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Vala LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'vala'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = '//' * l.nonnewline_esc^0
15 local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1
16 local comment = token(l.COMMENT, line_comment + block_comment)
18 -- Strings.
19 local sq_str = l.delimited_range("'", true)
20 local dq_str = l.delimited_range('"', true)
21 local tq_str = '"""' * (l.any - '"""')^0 * P('"""')^-1
22 local ml_str = '@' * l.delimited_range('"', false, true)
23 local string = token(l.STRING, tq_str + sq_str + dq_str + ml_str)
25 -- Numbers.
26 local number = token(l.NUMBER, (l.float + l.integer) * S('uUlLfFdDmM')^-1)
28 -- Keywords.
29 local keyword = token(l.KEYWORD, word_match{
30 'class', 'delegate', 'enum', 'errordomain', 'interface', 'namespace',
31 'signal', 'struct', 'using',
32 -- Modifiers.
33 'abstract', 'const', 'dynamic', 'extern', 'inline', 'out', 'override',
34 'private', 'protected', 'public', 'ref', 'static', 'virtual', 'volatile',
35 'weak',
36 -- Other.
37 'as', 'base', 'break', 'case', 'catch', 'construct', 'continue', 'default',
38 'delete', 'do', 'else', 'ensures', 'finally', 'for', 'foreach', 'get', 'if',
39 'in', 'is', 'lock', 'new', 'requires', 'return', 'set', 'sizeof', 'switch',
40 'this', 'throw', 'throws', 'try', 'typeof', 'value', 'var', 'void', 'while',
41 -- Etc.
42 'null', 'true', 'false'
45 -- Types.
46 local type = token(l.TYPE, word_match{
47 'bool', 'char', 'double', 'float', 'int', 'int8', 'int16', 'int32', 'int64',
48 'long', 'short', 'size_t', 'ssize_t', 'string', 'uchar', 'uint', 'uint8',
49 'uint16', 'uint32', 'uint64', 'ulong', 'unichar', 'ushort'
52 -- Identifiers.
53 local identifier = token(l.IDENTIFIER, l.word)
55 -- Operators.
56 local operator = token(l.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))
58 M._rules = {
59 {'whitespace', ws},
60 {'keyword', keyword},
61 {'type', type},
62 {'identifier', identifier},
63 {'string', string},
64 {'comment', comment},
65 {'number', number},
66 {'operator', operator},
69 M._foldsymbols = {
70 _patterns = {'[{}]', '/%*', '%*/', '//'},
71 [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
72 [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')}
75 return M