ui: make primary cursor blink even if no lua theme has been loaded
[vis.git] / lexers / idl.lua
blob8d2399cff89253ea12dfbb0cf9f48f4d9177eb87
1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- IDL 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 = 'idl'}
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 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', 'undef', 'ifdef', 'ifndef', 'if', 'elif', 'else', 'endif',
29 'include', 'warning', 'pragma'
31 local preproc = token(l.PREPROCESSOR,
32 l.starts_line('#') * preproc_word * l.nonnewline^0)
34 -- Keywords.
35 local keyword = token(l.KEYWORD, word_match{
36 'abstract', 'attribute', 'case', 'const', 'context', 'custom', 'default',
37 'exception', 'enum', 'factory', 'FALSE', 'in', 'inout', 'interface', 'local',
38 'module', 'native', 'oneway', 'out', 'private', 'public', 'raises',
39 'readonly', 'struct', 'support', 'switch', 'TRUE', 'truncatable', 'typedef',
40 'union', 'valuetype'
43 -- Types.
44 local type = token(l.TYPE, word_match{
45 'any', 'boolean', 'char', 'double', 'fixed', 'float', 'long', 'Object',
46 'octet', 'sequence', 'short', 'string', 'unsigned', 'ValueBase', 'void',
47 'wchar', 'wstring'
50 -- Identifiers.
51 local identifier = token(l.IDENTIFIER, l.word)
53 -- Operators.
54 local operator = token(l.OPERATOR, S('!<>=+-/*%&|^~.,:;?()[]{}'))
56 M._rules = {
57 {'whitespace', ws},
58 {'keyword', keyword},
59 {'type', type},
60 {'identifier', identifier},
61 {'string', string},
62 {'comment', comment},
63 {'number', number},
64 {'preprocessor', preproc},
65 {'operator', operator},
68 return M