vis: implement :set cursorline
[vis.git] / lexers / io_lang.lua
blob540628c5030dac56d68e964ec977a7420ecf97e0
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Io 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 = 'io_lang'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = (P('#') + '//') * l.nonnewline^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("'")
20 local dq_str = l.delimited_range('"')
21 local tq_str = '"""' * (l.any - '"""')^0 * P('"""')^-1
22 local string = token(l.STRING, tq_str + sq_str + dq_str)
24 -- Numbers.
25 local number = token(l.NUMBER, l.float + l.integer)
27 -- Keywords.
28 local keyword = token(l.KEYWORD, word_match{
29 'block', 'method', 'while', 'foreach', 'if', 'else', 'do', 'super', 'self',
30 'clone', 'proto', 'setSlot', 'hasSlot', 'type', 'write', 'print', 'forward'
33 -- Types.
34 local type = token(l.TYPE, word_match{
35 'Block', 'Buffer', 'CFunction', 'Date', 'Duration', 'File', 'Future', 'List',
36 'LinkedList', 'Map', 'Nop', 'Message', 'Nil', 'Number', 'Object', 'String',
37 'WeakLink'
40 -- Identifiers.
41 local identifier = token(l.IDENTIFIER, l.word)
43 -- Operators.
44 local operator = token(l.OPERATOR, S('`~@$%^&*-+/=\\<>?.,:;()[]{}'))
46 M._rules = {
47 {'whitespace', ws},
48 {'keyword', keyword},
49 {'type', type},
50 {'identifier', identifier},
51 {'string', string},
52 {'comment', comment},
53 {'number', number},
54 {'operator', operator},
57 M._foldsymbols = {
58 _patterns = {'[%(%)]', '/%*', '%*/', '#', '//'},
59 [l.OPERATOR] = {['('] = 1, [')'] = -1},
60 [l.COMMENT] = {
61 ['/*'] = 1, ['*/'] = -1, ['#'] = l.fold_line_comments('#'),
62 ['//'] = l.fold_line_comments('//')
66 return M