1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. 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
= 'ini'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local comment
= token(l
.COMMENT
, l
.starts_line(S(';#')) * l
.nonnewline^
0)
17 local sq_str
= l
.delimited_range("'")
18 local dq_str
= l
.delimited_range('"')
19 local label
= l
.delimited_range('[]', true, true)
20 local string = token(l
.STRING
, sq_str
+ dq_str
+ label
)
23 local dec
= l
.digit^
1 * ('_' * l
.digit^
1)^
0
24 local oct_num
= '0' * S('01234567_')^
1
25 local integer
= S('+-')^
-1 * (l
.hex_num
+ oct_num
+ dec
)
26 local number = token(l
.NUMBER
, (l
.float
+ integer
))
29 local keyword
= token(l
.KEYWORD
, word_match
{
30 'true', 'false', 'on', 'off', 'yes', 'no'
34 local word
= (l
.alpha
+ '_') * (l
.alnum
+ S('_.'))^
0
35 local identifier
= token(l
.IDENTIFIER
, word
)
38 local operator
= token(l
.OPERATOR
, '=')
43 {'identifier', identifier
},
47 {'operator', operator
},