vis: implement :set cursorline
[vis.git] / lexers / haskell.lua
blob46b543423a74e9ba6c4dbe7782d5532968fb2336
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Haskell LPeg lexer.
3 -- Modified by Alex Suraci.
5 local l = require('lexer')
6 local token, word_match = l.token, l.word_match
7 local P, R, S = lpeg.P, lpeg.R, lpeg.S
9 local M = {_NAME = 'haskell'}
11 -- Whitespace.
12 local ws = token(l.WHITESPACE, l.space^1)
14 -- Comments.
15 local line_comment = '--' * l.nonnewline_esc^0
16 local block_comment = '{-' * (l.any - '-}')^0 * P('-}')^-1
17 local comment = token(l.COMMENT, line_comment + block_comment)
19 -- Strings.
20 local string = token(l.STRING, l.delimited_range('"'))
22 -- Chars.
23 local char = token(l.STRING, l.delimited_range("'", true))
25 -- Numbers.
26 local number = token(l.NUMBER, l.float + l.integer)
28 -- Keywords.
29 local keyword = token(l.KEYWORD, word_match{
30 'case', 'class', 'data', 'default', 'deriving', 'do', 'else', 'if', 'import',
31 'in', 'infix', 'infixl', 'infixr', 'instance', 'let', 'module', 'newtype',
32 'of', 'then', 'type', 'where', '_', 'as', 'qualified', 'hiding'
35 -- Identifiers.
36 local word = (l.alnum + S("._'#"))^0
37 local identifier = token(l.IDENTIFIER, (l.alpha + '_') * word)
39 -- Operators.
40 local op = l.punct - S('()[]{}')
41 local operator = token(l.OPERATOR, op)
43 -- Types & type constructors.
44 local constructor = token(l.TYPE, (l.upper * word) + (P(":") * (op^1 - P(":"))))
46 M._rules = {
47 {'whitespace', ws},
48 {'keyword', keyword},
49 {'type', constructor},
50 {'identifier', identifier},
51 {'string', string},
52 {'char', char},
53 {'comment', comment},
54 {'number', number},
55 {'operator', operator},
58 M._FOLDBYINDENTATION = true
60 return M