vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
idl.lua
(1736B)
1 -- Copyright 2006-2025 Mitchell. See LICENSE.
2 -- IDL LPeg lexer.
3
4 local lexer = require('lexer')
5 local token, word_match = lexer.token, lexer.word_match
6 local P, S = lpeg.P, lpeg.S
7
8 local lex = lexer.new('idl')
9
10 -- Whitespace.
11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
12
13 -- Keywords.
14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
15 'abstract', 'attribute', 'case', 'const', 'context', 'custom', 'default', 'enum', 'exception',
16 'factory', 'FALSE', 'in', 'inout', 'interface', 'local', 'module', 'native', 'oneway', 'out',
17 'private', 'public', 'raises', 'readonly', 'struct', 'support', 'switch', 'TRUE', 'truncatable',
18 'typedef', 'union', 'valuetype'
19 }))
20
21 -- Types.
22 lex:add_rule('type', token(lexer.TYPE, word_match{
23 'any', 'boolean', 'char', 'double', 'fixed', 'float', 'long', 'Object', 'octet', 'sequence',
24 'short', 'string', 'unsigned', 'ValueBase', 'void', 'wchar', 'wstring'
25 }))
26
27 -- Identifiers.
28 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
29
30 -- Strings.
31 local sq_str = lexer.range("'", true)
32 local dq_str = lexer.range('"', true)
33 lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
34
35 -- Comments.
36 local line_comment = lexer.to_eol('//', true)
37 local block_comment = lexer.range('/*', '*/')
38 lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
39
40 -- Numbers.
41 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
42
43 -- Preprocessor.
44 lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') *
45 word_match('define undef ifdef ifndef if elif else endif include warning pragma')))
46
47 -- Operators.
48 lex:add_rule('operator', token(lexer.OPERATOR, S('!<>=+-/*%&|^~.,:;?()[]{}')))
49
50 lexer.property['scintillua.comment'] = '//'
51
52 return lex