vis: implement :set cursorline
[vis.git] / lexers / nemerle.lua
blobd628c8a60fcd2b18ae8107f92314b6b2184e1e56
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Nemerle 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 = 'nemerle'}
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 = P('L')^-1 * l.delimited_range("'", true)
20 local dq_str = P('L')^-1 * l.delimited_range('"', true)
21 local string = token(l.STRING, sq_str + dq_str)
23 -- Numbers.
24 local number = token(l.NUMBER, l.float + l.integer)
26 -- Preprocessor.
27 local preproc_word = word_match{
28 'define', 'elif', 'else', 'endif', 'endregion', 'error', 'if', 'ifdef',
29 'ifndef', 'line', 'pragma', 'region', 'undef', 'using', 'warning'
31 local preproc = token(l.PREPROCESSOR,
32 l.starts_line('#') * S('\t ')^0 * preproc_word)
34 -- Keywords.
35 local keyword = token(l.KEYWORD, word_match{
36 '_', 'abstract', 'and', 'array', 'as', 'base', 'catch', 'class', 'def', 'do',
37 'else', 'extends', 'extern', 'finally', 'foreach', 'for', 'fun', 'if',
38 'implements', 'in', 'interface', 'internal', 'lock', 'macro', 'match',
39 'module', 'mutable', 'namespace', 'new', 'out', 'override', 'params',
40 'private', 'protected', 'public', 'ref', 'repeat', 'sealed', 'static',
41 'struct', 'syntax', 'this', 'throw', 'try', 'type', 'typeof', 'unless',
42 'until', 'using', 'variant', 'virtual', 'when', 'where', 'while',
43 -- Values.
44 'null', 'true', 'false'
47 -- Types.
48 local type = token(l.TYPE, word_match{
49 'bool', 'byte', 'char', 'decimal', 'double', 'float', 'int', 'list', 'long',
50 'object', 'sbyte', 'short', 'string', 'uint', 'ulong', 'ushort', 'void'
53 -- Identifiers.
54 local identifier = token(l.IDENTIFIER, l.word)
56 -- Operators.
57 local operator = token(l.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))
59 M._rules = {
60 {'whitespace', ws},
61 {'keyword', keyword},
62 {'type', type},
63 {'identifier', identifier},
64 {'string', string},
65 {'comment', comment},
66 {'number', number},
67 {'preproc', preproc},
68 {'operator', operator},
71 M._foldsymbols = {
72 _patterns = {'%l+', '[{}]', '/%*', '%*/', '//'},
73 [l.PREPROCESSOR] = {
74 region = 1, endregion = -1,
75 ['if'] = 1, ifdef = 1, ifndef = 1, endif = -1
77 [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
78 [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')}
81 return M