vis: implement :set cursorline
[vis.git] / lexers / vbscript.lua
blobf4d9f3652756ea7cf705e6854a8493fe517c4b51
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- VisualBasic 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 = 'vbscript'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, (P("'") + word_match({'rem'}, nil, true)) * l.nonnewline^0)
16 -- Strings.
17 local string = token(l.STRING, l.delimited_range('"', true, true))
19 -- Numbers.
20 local number = token(l.NUMBER, (l.float + l.integer) * S('LlUuFf')^-2)
22 -- Keywords.
23 local keyword = token(l.KEYWORD, word_match({
24 -- Control.
25 'If', 'Then', 'Else', 'ElseIf', 'While', 'Wend', 'For', 'To', 'Each',
26 'In', 'Step', 'Case', 'Select', 'Return', 'Continue', 'Do',
27 'Until', 'Loop', 'Next', 'With', 'Exit',
28 -- Operators.
29 'Mod', 'And', 'Not', 'Or', 'Xor', 'Is',
30 -- Storage types.
31 'Call', 'Class', 'Const', 'Dim', 'ReDim', 'Preserve', 'Function', 'Sub',
32 'Property', 'End', 'Set', 'Let', 'Get', 'New', 'Randomize', 'Option',
33 'Explicit', 'On', 'Error', 'Execute',
34 -- Storage modifiers.
35 'Private', 'Public', 'Default',
36 -- Constants.
37 'Empty', 'False', 'Nothing', 'Null', 'True'
38 }, nil, true))
40 -- Types.
41 local type = token(l.TYPE, word_match({
42 'Boolean', 'Byte', 'Char', 'Date', 'Decimal', 'Double', 'Long', 'Object',
43 'Short', 'Single', 'String'
44 }, nil, true))
46 -- Identifiers.
47 local identifier = token(l.IDENTIFIER, l.word)
49 -- Operators.
50 local operator = token(l.OPERATOR, S('=><+-*^&:.,_()'))
52 M._rules = {
53 {'whitespace', ws},
54 {'keyword', keyword},
55 {'type', type},
56 {'comment', comment},
57 {'identifier', identifier},
58 {'string', string},
59 {'number', number},
60 {'operator', operator},
63 return M