/
slate.lua
61 lines (47 loc) · 1.6 KB
/
slate.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- Copyright 2010 Alex Suraci
-- Slate LPeg Lexer
module(..., package.seeall)
local P, R, S = lpeg.P, lpeg.R, lpeg.S
local ws = token('whitespace', space^1)
-- comments
local comment = token('comment', delimited_range('"', '\\'))
-- strings
local string = token('string', delimited_range("'", '\\'))
-- chars
local char = token('char', '$' * (('\\' * P(1)) + P(1)))
-- numbers
local number = token('number', float + integer)
-- operators
local op = punct - S('()"\'') + S('\\[]]')
local operator = token('operator', op)
-- identifiers
local word = (alnum + S("._#"))^1
local identifier = token('identifier', word + (':' * word))
-- symbols
local symbol = token('symbol', '#' * word)
-- keywords
local keyword = token('slate_keyword', word * ':')
-- optional keywords
local optional_keyword = token('slate_optional_keyword', '&' * word * ':')
-- constructors
local constructor = token('type', upper * word)
function LoadTokens()
local slate = slate
add_token(slate, 'whitespace', ws)
add_token(slate, 'symbol', symbol)
add_token(slate, 'slate_keyword', keyword)
add_token(slate, 'slate_optional_keyword', optional_keyword)
add_token(slate, 'type', constructor)
add_token(slate, 'identifier', identifier)
add_token(slate, 'string', string)
add_token(slate, 'char', char)
add_token(slate, 'comment', comment)
add_token(slate, 'number', number)
add_token(slate, 'operator', operator)
add_token(slate, 'any_char', any_char)
end
function LoadStyles()
add_style('symbol', style_symbol)
add_style('slate_keyword', style_slate_keyword)
add_style('slate_optional_keyword', style_slate_keyword)
end