build: set version to 0.5
[vis.git] / lua / lexers / rstats.lua
blobad9b5aa31f99bec26bd8b3b2442955a0601d6865
1 -- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- R 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 = 'rstats'}
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.float + l.integer) * P('i')^-1)
24 -- Keywords.
25 local keyword = token(l.KEYWORD, word_match{
26 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch',
27 'try', 'while', 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE'
30 -- Types.
31 local type = token(l.TYPE, word_match{
32 'array', 'character', 'complex', 'data.frame', 'double', 'factor', 'function',
33 'integer', 'list', 'logical', 'matrix', 'numeric', 'vector'
36 -- Identifiers.
37 local identifier = token(l.IDENTIFIER, l.word)
39 -- Operators.
40 local operator = token(l.OPERATOR, S('<->+*/^=.,:;|$()[]{}'))
42 M._rules = {
43 {'whitespace', ws},
44 {'keyword', keyword},
45 {'type', type},
46 {'identifier', identifier},
47 {'string', string},
48 {'comment', comment},
49 {'number', number},
50 {'operator', operator},
53 return M