ui: make primary cursor blink even if no lua theme has been loaded
[vis.git] / lexers / gap.lua
blob3d9f7a4dc9a64b1a78806060234560f3f4e9dbaf
1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Gap 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 = 'gap'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, '#' * l.nonnewline^0)
16 -- Strings.
17 local sq_str = l.delimited_range("'", true)
18 local dq_str = l.delimited_range('"', true)
19 local string = token(l.STRING, sq_str + dq_str)
21 -- Numbers.
22 local number = token(l.NUMBER, l.digit^1 * -l.alpha)
24 -- Keywords.
25 local keyword = token(l.KEYWORD, word_match{
26 'and', 'break', 'continue', 'do', 'elif', 'else', 'end', 'fail', 'false',
27 'fi', 'for', 'function', 'if', 'in', 'infinity', 'local', 'not', 'od', 'or',
28 'rec', 'repeat', 'return', 'then', 'true', 'until', 'while'
31 -- Identifiers.
32 local identifier = token(l.IDENTIFIER, l.word)
34 -- Operators.
35 local operator = token(l.OPERATOR, S('*+-,./:;<=>~^#()[]{}'))
37 M._rules = {
38 {'whitespace', ws},
39 {'keyword', keyword},
40 {'identifier', identifier},
41 {'string', string},
42 {'comment', comment},
43 {'number', number},
44 {'operator', operator},
47 M._foldsymbols = {
48 _patterns = {'[a-z]+', '#'},
49 [l.KEYWORD] = {
50 ['function'] = 1, ['end'] = -1, ['do'] = 1, od = -1, ['if'] = 1, fi = -1,
51 ['repeat'] = 1, ['until'] = -1
53 [l.COMMENT] = {['#'] = l.fold_line_comments('#')}
56 return M