1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
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'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
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
)
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
)
26 local number = token(l
.NUMBER
, (l
.float
+ l
.integer
) * S('uUlLfFdDmM')^
-1)
29 local keyword
= token(l
.KEYWORD
, word_match
{
30 'class', 'delegate', 'enum', 'errordomain', 'interface', 'namespace',
31 'signal', 'struct', 'using',
33 'abstract', 'const', 'dynamic', 'extern', 'inline', 'out', 'override',
34 'private', 'protected', 'public', 'ref', 'static', 'virtual', 'volatile',
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',
42 'null', 'true', 'false'
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'
53 local identifier
= token(l
.IDENTIFIER
, l
.word
)
56 local operator
= token(l
.OPERATOR
, S('+-/*%<>!=^&|?~:;.()[]{}'))
62 {'identifier', identifier
},
66 {'operator', operator
},
70 _patterns
= {'[{}]', '/%*', '%*/', '//'},
71 [l
.OPERATOR
] = {['{'] = 1, ['}'] = -1},
72 [l
.COMMENT
] = {['/*'] = 1, ['*/'] = -1, ['//'] = l
.fold_line_comments('//')}