vis: implement :set cursorline
[vis.git] / lexers / smalltalk.lua
blob298173fa7de9c44e6d016ed45c0c6d0e46c684a4
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Smalltalk 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 = 'smalltalk'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, l.delimited_range('"', false, true))
16 -- Strings.
17 local sq_str = l.delimited_range("'")
18 local literal = '$' * l.word
19 local string = token(l.STRING, sq_str + literal)
21 -- Numbers.
22 local number = token(l.NUMBER, l.float + l.integer)
24 -- Keywords.
25 local keyword = token(l.KEYWORD, word_match{
26 'true', 'false', 'nil', 'self', 'super', 'isNil', 'not', 'Smalltalk',
27 'Transcript'
30 -- Types.
31 local type = token(l.TYPE, word_match{
32 'Date', 'Time', 'Boolean', 'True', 'False', 'Character', 'String', 'Array',
33 'Symbol', 'Integer', 'Object'
36 -- Identifiers.
37 local identifier = token(l.IDENTIFIER, l.word)
39 -- Operators.
40 local operator = token(l.OPERATOR, S(':=_<>+-/*!()[]'))
42 -- Labels.
43 local label = token(l.LABEL, '#' * l.word)
45 M._rules = {
46 {'whitespace', ws},
47 {'keyword', keyword},
48 {'type', type},
49 {'identifier', identifier},
50 {'string', string},
51 {'comment', comment},
52 {'number', number},
53 {'label', label},
54 {'operator', operator},
57 M._foldsymbols = {
58 _patterns = {'[%[%]]'},
59 [l.OPERATOR] = {['['] = 1, [']'] = -1}
62 return M