X Tutup
Skip to content

Commit 9d69afd

Browse files
committed
fix some minor things:
* precedence of { type: x, class: x } etc. * @ is valid self ref cc @abaez
1 parent ca6580f commit 9d69afd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

syntaxhighlight/textadept/moonscript.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ local lex = lexer.new('moonscript', {fold_by_indentation = true})
1111
-- Whitespace.
1212
lex:add_rule('whitspace', token(lexer.WHITESPACE, lexer.space^1))
1313

14+
-- table keys have higher precedence than keywords
15+
local tbl_key = token('tbl_key', lexer.word * ':' + ':' * lexer.word )
16+
lex:add_rule('tbl_key', tbl_key)
17+
lex:add_style('tbl_key', lexer.STYLE_REGEX)
18+
1419
-- Keywords.
1520
lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[
1621
-- Lua.
@@ -24,7 +29,7 @@ lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[
2429
lex:add_rule('error', token(lexer.ERROR, word_match[[function end]]))
2530

2631
-- Self reference.
27-
lex:add_rule('self_ref', token('self_ref', '@' * lexer.word + 'self'))
32+
lex:add_rule('self_ref', token('self_ref', '@' * lexer.word^-1 + 'self'))
2833
lex:add_style('self_ref', lexer.STYLE_LABEL)
2934

3035
-- Functions.
@@ -105,10 +110,8 @@ lex:add_style('library', lexer.STYLE_TYPE)
105110
-- Identifiers.
106111
local identifier = token(lexer.IDENTIFIER, lexer.word)
107112
local proper_ident = token('proper_ident', R('AZ') * lexer.word)
108-
local tbl_key = token('tbl_key', lexer.word * ':' + ':' * lexer.word )
109-
lex:add_rule('identifier', tbl_key + proper_ident + identifier)
113+
lex:add_rule('identifier', proper_ident + identifier)
110114
lex:add_style('proper_ident', lexer.STYLE_CLASS)
111-
lex:add_style('tbl_key', lexer.STYLE_REGEX)
112115

113116
local longstring = lpeg.Cmt('[' * lpeg.C(P('=')^0) * '[',
114117
function(input, index, eq)

0 commit comments

Comments
 (0)
X Tutup