ui: add support for blink style attribute
[vis.git] / lexers / json.lua
blob6dcebecb32dc598eb0574faaa27c92dd1e396b00
1 -- Copyright 2006-2013 Brian "Sir Alaran" Schott. See LICENSE.
2 -- JSON LPeg lexer.
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'}
11 -- Whitespace.
12 local ws = token(l.WHITESPACE, l.space^1)
14 -- Comments.
15 local comment = token(l.COMMENT, '/*' * (l.any - '*/')^0 * P('*/')^-1)
17 -- Strings.
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)
22 -- Numbers.
23 local integer = S('+-')^-1 * l.digit^1 * S('Ll')^-1
24 local number = token(l.NUMBER, l.float + integer)
26 -- Keywords.
27 local keyword = token(l.KEYWORD, word_match{"true", "false", "null"})
29 -- Operators.
30 local operator = token(l.OPERATOR, S('[]{}:,'))
32 M._rules = {
33 {'whitespace', ws},
34 {'comment', comment},
35 {'string', string},
36 {'number', number},
37 {'keyword', keyword},
38 {'operator', operator},
41 M._foldsymbols = {
42 _patterns = {'[%[%]{}]', '/%*', '%*/'},
43 [l.OPERATOR] = {['['] = 1, [']'] = -1, ['{'] = 1, ['}'] = -1},
44 [l.COMMENT] = {['/*'] = 1, ['*/'] = -1}
47 return M