1 -- Copyright 2010 Alex Suraci
4 module(..., package
.seeall
)
5 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
7 local ws
= token('whitespace', space^
1)
10 local comment
= token('comment', delimited_range('"', '\\'))
13 local string = token('string', delimited_range("'", '\\'))
16 local char
= token('char', '$' * (('\\' * P(1)) + P(1)))
19 local number = token('number', float
+ integer
)
22 local op
= punct
- S('()"\'') + S('\\[]]')
23 local operator
= token('operator', op
)
26 local word
= (alnum
+ S("._#"))^
1
27 local identifier
= token('identifier', word
+ (':' * word
))
30 local symbol
= token('symbol', '#' * word
)
33 local keyword
= token('slate_keyword', word
* ':')
36 local optional_keyword
= token('slate_optional_keyword', '&' * word
* ':')
39 local constructor
= token('type', upper
* word
)
43 add_token(slate
, 'whitespace', ws
)
44 add_token(slate
, 'symbol', symbol
)
45 add_token(slate
, 'slate_keyword', keyword
)
46 add_token(slate
, 'slate_optional_keyword', optional_keyword
)
47 add_token(slate
, 'type', constructor
)
48 add_token(slate
, 'identifier', identifier
)
49 add_token(slate
, 'string', string)
50 add_token(slate
, 'char', char
)
51 add_token(slate
, 'comment', comment
)
52 add_token(slate
, 'number', number)
53 add_token(slate
, 'operator', operator
)
54 add_token(slate
, 'any_char', any_char
)
58 add_style('symbol', style_symbol
)
59 add_style('slate_keyword', style_slate_keyword
)
60 add_style('slate_optional_keyword', style_slate_keyword
)