1 -- Copyright 2015-2017 Alejandro Baez (https://keybase.io/baez). See LICENSE.
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
= 'toml'}
11 local indent
= #l
.starts_line(S(' \t')) *
12 (token(l
.WHITESPACE
, ' ') + token('indent_error', '\t'))^
1
13 local ws
= token(l
.WHITESPACE
, S(' \t')^
1 + l
.newline^
1)
16 local comment
= token(l
.COMMENT
, '#' * l
.nonnewline^
0)
19 local string = token(l
.STRING
, l
.delimited_range("'") + l
.delimited_range('"'))
22 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
25 local ts
= token('timestamp', l
.digit
* l
.digit
* l
.digit
* l
.digit
* -- year
26 '-' * l
.digit
* l
.digit^
-1 * -- month
27 '-' * l
.digit
* l
.digit^
-1 * -- day
28 ((S(' \t')^
1 + S('tT'))^
-1 * -- separator
29 l
.digit
* l
.digit^
-1 * -- hour
30 ':' * l
.digit
* l
.digit
* -- minute
31 ':' * l
.digit
* l
.digit
* -- second
32 ('.' * l
.digit^
0)^
-1 * -- fraction
34 S(' \t')^
0 * S('-+') * l
.digit
* l
.digit^
-1 *
35 (':' * l
.digit
* l
.digit
)^
-1)^
-1)^
-1)
38 local keyword
= token(l
.KEYWORD
, word_match
{
44 local identifier
= token(l
.IDENTIFIER
, l
.word
)
47 local operator
= token(l
.OPERATOR
, S('#=+-,.{}[]()'))
53 {'identifier', identifier
},
54 {'operator', operator
},
62 indent_error
= 'back:red',
63 timestamp
= l
.STYLE_NUMBER
,
66 M
._FOLDBYINDENTATION
= true