ui: fall back to xterm-256color if term initialization fails
[vis.git] / lexers / ini.lua
blob15ea7fa8f3a51ac9709ed6acbd9371b8c93319b9
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Ini 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 = 'ini'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, l.starts_line(S(';#')) * l.nonnewline^0)
16 -- Strings.
17 local sq_str = l.delimited_range("'")
18 local dq_str = l.delimited_range('"')
19 local label = l.delimited_range('[]', true, true)
20 local string = token(l.STRING, sq_str + dq_str + label)
22 -- Numbers.
23 local dec = l.digit^1 * ('_' * l.digit^1)^0
24 local oct_num = '0' * S('01234567_')^1
25 local integer = S('+-')^-1 * (l.hex_num + oct_num + dec)
26 local number = token(l.NUMBER, (l.float + integer))
28 -- Keywords.
29 local keyword = token(l.KEYWORD, word_match{
30 'true', 'false', 'on', 'off', 'yes', 'no'
33 -- Identifiers.
34 local word = (l.alpha + '_') * (l.alnum + S('_.'))^0
35 local identifier = token(l.IDENTIFIER, word)
37 -- Operators.
38 local operator = token(l.OPERATOR, '=')
40 M._rules = {
41 {'whitespace', ws},
42 {'keyword', keyword},
43 {'identifier', identifier},
44 {'string', string},
45 {'comment', comment},
46 {'number', number},
47 {'operator', operator},
50 M._LEXBYLINE = true
52 return M