1 -- Copyright 2006-2013 Brian "Sir Alaran" Schott. See LICENSE.
3 -- Based off of lexer code by Mitchell.
5 local l
= require('lexer')
6 local token
, word_match
= l
.token
, l
.word_match
7 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
9 local M
= {_NAME
= 'json'}
12 local ws
= token(l
.WHITESPACE
, l
.space^
1)
15 local comment
= token(l
.COMMENT
, '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1)
18 local sq_str
= P('u')^
-1 * l
.delimited_range("'", true)
19 local dq_str
= P('U')^
-1 * l
.delimited_range('"', true)
20 local string = token(l
.STRING
, sq_str
+ dq_str
)
23 local integer
= S('+-')^
-1 * l
.digit^
1 * S('Ll')^
-1
24 local number = token(l
.NUMBER
, l
.float
+ integer
)
27 local keyword
= token(l
.KEYWORD
, word_match
{"true", "false", "null"})
30 local operator
= token(l
.OPERATOR
, S('[]{}:,'))
38 {'operator', operator
},
42 _patterns
= {'[%[%]{}]', '/%*', '%*/'},
43 [l
.OPERATOR
] = {['['] = 1, [']'] = -1, ['{'] = 1, ['}'] = -1},
44 [l
.COMMENT
] = {['/*'] = 1, ['*/'] = -1}