@@ -27,13 +27,7 @@ local comment = token(l.COMMENT, block_comment + line_comment)
2727-- Strings.
2828local sq_str = l .delimited_range (" '" , ' \\ ' , true )
2929local dq_str = l .delimited_range (' "' , ' \\ ' , true )
30- local regex_str = l .delimited_range (' /' , ' \\ ' , nil , nil , ' \n ' ) * S (' igm' )^ 0
31- local string = token (l .STRING , sq_str + dq_str ) + P (function (input , index )
32- if index == 1 then return index end
33- local i = index
34- while input :sub (i - 1 , i - 1 ):match (' [ \t\r\n\f ]' ) do i = i - 1 end
35- return input :sub (i - 1 , i - 1 ):match (' [+%-*%%^!=&|?:;,()%[%]{}]' ) and index
36- end ) * token (' regex' , regex_str ) + token (' longstring' , longstring )
30+ local string = token (l .STRING , sq_str + dq_str + longstring )
3731
3832-- Numbers.
3933local number = token (l .NUMBER , l .float + l .integer )
@@ -44,11 +38,13 @@ local keyword = token(l.KEYWORD, word_match {
4438 ' if' , ' else' , ' elseif' , ' then' , ' export' ,
4539 ' import' , ' from' , ' with' , ' in' , ' and' ,
4640 ' or' , ' not' , ' class' , ' extends' , ' super' , ' do' ,
47- ' true ' , ' false ' , ' nil ' , ' using' , ' switch' , ' when' ,
41+ ' using' , ' switch' , ' when' ,
4842})
4943
44+ local special = token (" special" , word_match { " true" , " false" , " nil" })
45+
5046-- Functions.
51- local func = token (l .FUNCTION , word_match {
47+ local builtin = token (l .FUNCTION , word_match {
5248 ' assert' , ' collectgarbage' , ' dofile' , ' error' , ' getfenv' , ' getmetatable' ,
5349 ' ipairs' , ' load' , ' loadfile' , ' loadstring' , ' module' , ' next' , ' pairs' ,
5450 ' pcall' , ' print' , ' rawequal' , ' rawget' , ' rawset' , ' require' , ' setfenv' ,
@@ -58,34 +54,44 @@ local func = token(l.FUNCTION, word_match {
5854-- Identifiers.
5955local identifier = token (l .IDENTIFIER , l .word )
6056
57+ local fndef = token (" fndef" , P " ->" + P " =>" )
58+ local err = token (l .ERROR , word_match { " function" , " end" })
59+
6160-- Operators.
62- local operator = token (l .OPERATOR , ' ~=' + S (' +-*!\\ /%^#=<>;:,.{}[]()' ))
61+ local symbol = token (" symbol" , S (" (){}[]" ))
62+ local operator = token (l .OPERATOR , ' ~=' + S (' +-*!\\ /%^#=<>;:,.' ))
6363
6464-- self ref
65- local self_var = token (' self_ref' , " @" * l .word + " self" )
65+ local self_var = token (" self_ref" , " @" * l .word + " self" )
6666
67- local proper_ident = token (' proper_ident' , R (" AZ" ) * l .word )
67+ local proper_ident = token (" proper_ident" , R (" AZ" ) * l .word )
6868
6969_rules = {
7070 { ' whitespace' , ws },
71+ { ' error' , err },
7172 { ' self' , self_var },
73+ { ' special' , special },
7274 { ' keyword' , keyword },
73- { ' function ' , func },
75+ { ' builtin ' , builtin },
7476 { ' identifier' , proper_ident + identifier },
7577 { ' comment' , comment },
7678 { ' number' , number },
7779 { ' string' , string },
80+ { ' fndef' , fndef },
81+ { ' symbol' , symbol },
7882 { ' operator' , operator },
7983 { ' any_char' , l .any_char },
8084}
8185
82- local pink = l .color (" ED" , " 4E" , " 78" )
86+ local style_special = { fore = l .colors .light_blue }
87+ local style_fndef = { fore = l .colors .green }
8388
8489_tokenstyles = {
85- { ' regex' , l .style_string .. { back = l .color (' 44' , ' 44' , ' 44' )} },
86- { ' longstring' , l .style_string },
87- { ' self_ref' , { fore = l .colors .purple } },
88- { ' proper_ident' , { fore = pink , bold = true } },
90+ { ' self_ref' , style_special },
91+ { ' proper_ident' , l .style_class },
92+ { ' fndef' , style_fndef },
93+ { ' symbol' , style_fndef },
94+ { ' special' , style_special },
8995 { l .OPERATOR , { fore = l .colors .red , bold = true } },
9096 { l .FUNCTION , { fore = l .colors .orange } },
9197}
0 commit comments