vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
ini.lua
(1128B)
1 -- Copyright 2006-2025 Mitchell. See LICENSE.
2 -- Ini 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('ini')
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('true false on off yes no')))
15
16 -- Identifiers.
17 lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0))
18
19 -- Strings.
20 local sq_str = lexer.range("'")
21 local dq_str = lexer.range('"')
22 lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
23
24 -- Labels.
25 lex:add_rule('label', token(lexer.LABEL, lexer.range('[', ']', true)))
26
27 -- Comments.
28 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(lexer.starts_line(S(';#')))))
29
30 -- Numbers.
31 local integer = S('+-')^-1 * (lexer.hex_num + lexer.oct_num_('_') + lexer.dec_num_('_'))
32 lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer))
33
34 -- Operators.
35 lex:add_rule('operator', token(lexer.OPERATOR, '='))
36
37 lexer.property['scintillua.comment'] = '#'
38
39 return lex