From aa85c4611428a99b05dae83d35aad0a4c399f072 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 20 Nov 2011 20:29:55 -0800 Subject: [PATCH] updated scintillua lexer a bit, added moon theme --- extra/scintillua/lexers/moonscript.lua | 42 +++++++++-------- extra/scintillua/lexers/themes/moon.lua | 61 +++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 extra/scintillua/lexers/themes/moon.lua diff --git a/extra/scintillua/lexers/moonscript.lua b/extra/scintillua/lexers/moonscript.lua index 27372ed..664b4a6 100644 --- a/extra/scintillua/lexers/moonscript.lua +++ b/extra/scintillua/lexers/moonscript.lua @@ -27,13 +27,7 @@ local comment = token(l.COMMENT, block_comment + line_comment) -- Strings. local sq_str = l.delimited_range("'", '\\', true) local dq_str = l.delimited_range('"', '\\', true) -local regex_str = l.delimited_range('/', '\\', nil, nil, '\n') * S('igm')^0 -local string = token(l.STRING, sq_str + dq_str) + P(function(input, index) - if index == 1 then return index end - local i = index - while input:sub(i - 1, i - 1):match('[ \t\r\n\f]') do i = i - 1 end - return input:sub(i - 1, i - 1):match('[+%-*%%^!=&|?:;,()%[%]{}]') and index -end) * token('regex', regex_str) + token('longstring', longstring) +local string = token(l.STRING, sq_str + dq_str + longstring) -- Numbers. local number = token(l.NUMBER, l.float + l.integer) @@ -44,11 +38,13 @@ local keyword = token(l.KEYWORD, word_match { 'if', 'else', 'elseif', 'then', 'export', 'import', 'from', 'with', 'in', 'and', 'or', 'not', 'class', 'extends', 'super', 'do', - 'true', 'false', 'nil', 'using', 'switch', 'when', + 'using', 'switch', 'when', }) +local special = token("special", word_match { "true", "false", "nil" }) + -- Functions. -local func = token(l.FUNCTION, word_match { +local builtin = token(l.FUNCTION, word_match { 'assert', 'collectgarbage', 'dofile', 'error', 'getfenv', 'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring', 'module', 'next', 'pairs', 'pcall', 'print', 'rawequal', 'rawget', 'rawset', 'require', 'setfenv', @@ -58,34 +54,44 @@ local func = token(l.FUNCTION, word_match { -- Identifiers. local identifier = token(l.IDENTIFIER, l.word) +local fndef = token("fndef", P"->" + P"=>") +local err = token(l.ERROR, word_match { "function", "end" }) + -- Operators. -local operator = token(l.OPERATOR, '~=' + S('+-*!\\/%^#=<>;:,.{}[]()')) +local symbol = token("symbol", S("(){}[]")) +local operator = token(l.OPERATOR, '~=' + S('+-*!\\/%^#=<>;:,.')) -- self ref -local self_var = token('self_ref', "@" * l.word + "self") +local self_var = token("self_ref", "@" * l.word + "self") -local proper_ident = token('proper_ident', R("AZ") * l.word) +local proper_ident = token("proper_ident", R("AZ") * l.word) _rules = { { 'whitespace', ws }, + { 'error', err }, { 'self', self_var }, + { 'special', special }, { 'keyword', keyword }, - { 'function', func }, + { 'builtin', builtin }, { 'identifier', proper_ident + identifier }, { 'comment', comment }, { 'number', number }, { 'string', string }, + { 'fndef', fndef }, + { 'symbol', symbol }, { 'operator', operator }, { 'any_char', l.any_char }, } -local pink = l.color("ED", "4E", "78") +local style_special = { fore = l.colors.light_blue } +local style_fndef = { fore = l.colors.green } _tokenstyles = { - { 'regex', l.style_string..{ back = l.color('44', '44', '44')} }, - { 'longstring', l.style_string }, - { 'self_ref', { fore = l.colors.purple } }, - { 'proper_ident', { fore = pink, bold = true } }, + { 'self_ref', style_special }, + { 'proper_ident', l.style_class }, + { 'fndef', style_fndef }, + { 'symbol', style_fndef }, + { 'special', style_special }, { l.OPERATOR, { fore = l.colors.red, bold = true } }, { l.FUNCTION, { fore = l.colors.orange } }, } diff --git a/extra/scintillua/lexers/themes/moon.lua b/extra/scintillua/lexers/themes/moon.lua new file mode 100644 index 0000000..0f35a50 --- /dev/null +++ b/extra/scintillua/lexers/themes/moon.lua @@ -0,0 +1,61 @@ +-- Copyright 2006-2011 Mitchell mitchellcaladbolg.net. See LICENSE. +-- moon lexer theme for Scintillua. + +module('lexer', package.seeall) + +colors = { + green = color('9F', 'FF', '98'), -- + blue = color('94', '95', 'FF'), -- + light_blue = color('98', 'D9', 'FF'), -- + red = color('FF', '98', '98'), -- + bright_red = color("F9", "26", "32"), -- + yellow = color('FF', 'E8', '98'), -- + teal = color('4D', '99', '99'), + white = color('FF', 'FF', 'FF'), -- + black = color('2E', '2E', '2E'), -- + grey = color('92', '92', '92'), -- + purple = color('CB', '98', 'FF'), -- + orange = color('FF', '92', '00'), -- + pink = color("ED", "4E", "78"), -- +} + +style_nothing = style { } +style_char = style { fore = colors.red, bold = true } +style_class = style { fore = colors.light_blue, bold = true } +style_comment = style { fore = colors.grey, } +style_constant = style { fore = colors.teal, bold = true } +style_definition = style { fore = colors.red, bold = true } +style_error = style { fore = colors.white, back = colors.bright_red, bold = true} +style_function = style { fore = colors.white, bold = true } +style_keyword = style { fore = colors.purple, bold = true } +style_number = style { fore = colors.blue } +style_operator = style { fore = colors.white, bold = true } +style_string = style { fore = colors.yellow, bold = true } +style_preproc = style { fore = colors.light_blue } +style_tag = style { fore = colors.teal, bold = true } +style_type = style { fore = colors.green } +style_variable = style { fore = colors.white, italic = true } +style_embedded = style_tag..{ back = color('44', '44', '44') } +style_identifier = style_nothing + +-- Default styles. +local font_face = '!Bitstream Vera Sans Mono' +local font_size = 12 +if WIN32 then + font_face = not GTK and 'Courier New' or '!Courier New' +elseif OSX then + font_face = '!Monaco' + font_size = 12 +end +style_default = style{ + font = font_face, + size = font_size, + fore = colors.white, + back = colors.black +} +style_line_number = style { fore = colors.black, back = colors.grey } +style_bracelight = style { fore = color('66', '99', 'FF'), bold = true } +style_bracebad = style { fore = color('FF', '66', '99'), bold = true } +style_controlchar = style_nothing +style_indentguide = style { fore = colors.grey, back = colors.white } +style_calltip = style { fore = colors.white, back = color('44', '44', '44') }