diff options
Diffstat (limited to 'lexlua')
-rw-r--r-- | lexlua/awk.lua | 9 | ||||
-rw-r--r-- | lexlua/chuck.lua | 2 | ||||
-rw-r--r-- | lexlua/diff.lua | 8 | ||||
-rw-r--r-- | lexlua/html.lua | 4 | ||||
-rw-r--r-- | lexlua/lexer.lua | 314 | ||||
-rw-r--r-- | lexlua/lua.lua | 4 | ||||
-rw-r--r-- | lexlua/markdown.lua | 19 | ||||
-rw-r--r-- | lexlua/mediawiki.lua | 4 | ||||
-rw-r--r-- | lexlua/texinfo.lua | 4 | ||||
-rw-r--r-- | lexlua/themes/curses.lua | 84 | ||||
-rw-r--r-- | lexlua/themes/dark.lua | 143 | ||||
-rw-r--r-- | lexlua/themes/light.lua | 143 | ||||
-rw-r--r-- | lexlua/themes/scite.lua | 86 | ||||
-rw-r--r-- | lexlua/toml.lua | 2 | ||||
-rw-r--r-- | lexlua/txt2tags.lua | 48 |
15 files changed, 442 insertions, 432 deletions
diff --git a/lexlua/awk.lua b/lexlua/awk.lua index 40ff501e7..a34730e1a 100644 --- a/lexlua/awk.lua +++ b/lexlua/awk.lua @@ -249,18 +249,18 @@ lex:add_style('field', lexer.STYLE_LABEL) -- sequences like '\S', '\s' have special meanings with Gawk. Tokens that -- contain them are displayed differently. lex:add_rule('gawkRegex', token('gawkRegex', SLASH * P(scanGawkRegex))) -lex:add_style('gawkRegex', lexer.STYLE_PREPROCESSOR .. ',underlined') +lex:add_style('gawkRegex', lexer.STYLE_PREPROCESSOR .. {underlined = true}) lex:add_rule('regex', token(lexer.REGEX, SLASH * P(scanRegex))) -- Operators. lex:add_rule('gawkOperator', token('gawkOperator', P("|&") + "@" + "**=" + "**")) -lex:add_style('gawkOperator', lexer.STYLE_OPERATOR .. ',underlined') +lex:add_style('gawkOperator', lexer.STYLE_OPERATOR .. {underlined = true}) lex:add_rule('operator', token(lexer.OPERATOR, S('!%&()*+,-/:;<=>?[\\]^{|}~'))) -- Numbers. lex:add_rule('gawkNumber', token('gawkNumber', lexer.hex_num + lexer.oct_num)) -lex:add_style('gawkNumber', lexer.STYLE_NUMBER .. ',underlined') +lex:add_style('gawkNumber', lexer.STYLE_NUMBER .. {underlined = true}) lex:add_rule('number', token(lexer.NUMBER, float)) -- Keywords. @@ -281,7 +281,8 @@ lex:add_rule('gawkBuiltInVariable', token('gawkBuiltInVariable', word_match[[ ARGIND BINMODE ERRNO FIELDWIDTHS FPAT FUNCTAB IGNORECASE LINT PREC PROCINFO ROUNDMODE RT SYMTAB TEXTDOMAIN ]])) -lex:add_style('gawkBuiltInVariable', lexer.STYLE_CONSTANT .. ',underlined') +lex:add_style( + 'gawkBuiltInVariable', lexer.STYLE_CONSTANT .. {underlined = true}) -- Functions. lex:add_rule('function', token(lexer.FUNCTION, lexer.word * #P('('))) diff --git a/lexlua/chuck.lua b/lexlua/chuck.lua index 2f918ed73..d3dfd2417 100644 --- a/lexlua/chuck.lua +++ b/lexlua/chuck.lua @@ -48,7 +48,7 @@ lex:add_style('time', lexer.STYLE_NUMBER) -- Special special value. lex:add_rule('now', token('now', P('now'))) -lex:add_style('now', lexer.STYLE_CONSTANT .. ',bold') +lex:add_style('now', lexer.STYLE_CONSTANT .. {bold = true}) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) diff --git a/lexlua/diff.lua b/lexlua/diff.lua index 2b3b171f1..c5c6b8738 100644 --- a/lexlua/diff.lua +++ b/lexlua/diff.lua @@ -13,7 +13,7 @@ lex:add_rule('separator', token(lexer.COMMENT, ('---' + P('*')^4 + P('=')^1) * lexer.space^0 * -1)) lex:add_rule('header', token('header', (P('*** ') + '--- ' + '+++ ') * lexer.any^1)) -lex:add_style('header', lexer.STYLE_COMMENT) +lex:add_style('header', lexer.styles.comment) -- Location. lex:add_rule('location', token(lexer.NUMBER, ('@@' + lexer.digit^1 + '****') * @@ -21,11 +21,11 @@ lex:add_rule('location', token(lexer.NUMBER, ('@@' + lexer.digit^1 + '****') * -- Additions, deletions, and changes. lex:add_rule('addition', token('addition', S('>+') * lexer.any^0)) -lex:add_style('addition', 'fore:$(color.green)') +lex:add_style('addition', {fore = lexer.colors.green}) lex:add_rule('deletion', token('deletion', S('<-') * lexer.any^0)) -lex:add_style('deletion', 'fore:$(color.red)') +lex:add_style('deletion', {fore = lexer.colors.red}) lex:add_rule('change', token('change', '!' * lexer.any^0)) -lex:add_style('change', 'fore:$(color.yellow)') +lex:add_style('change', {fore = lexer.colors.yellow}) lex:add_rule('any_line', token(lexer.DEFAULT, lexer.any^1)) diff --git a/lexlua/html.lua b/lexlua/html.lua index 465a828b6..5ce566750 100644 --- a/lexlua/html.lua +++ b/lexlua/html.lua @@ -41,7 +41,7 @@ local element = known_element + unknown_element lex:add_rule('element', element) lex:add_style('single_element', lexer.STYLE_KEYWORD) lex:add_style('element', lexer.STYLE_KEYWORD) -lex:add_style('unknown_element', lexer.STYLE_KEYWORD .. ',italics') +lex:add_style('unknown_element', lexer.STYLE_KEYWORD .. {italics = true}) -- Closing tags. local tag_close = token('element', P('/')^-1 * '>') @@ -65,7 +65,7 @@ local unknown_attribute = token('unknown_attribute', (lexer.alnum + '-')^1) local attribute = (known_attribute + unknown_attribute) * #(lexer.space^0 * '=') lex:add_rule('attribute', attribute) lex:add_style('attribute', lexer.STYLE_TYPE) -lex:add_style('unknown_attribute', lexer.STYLE_TYPE .. ',italics') +lex:add_style('unknown_attribute', lexer.STYLE_TYPE .. {italics = true}) -- TODO: performance is terrible on large files. local in_tag = P(function(input, index) diff --git a/lexlua/lexer.lua b/lexlua/lexer.lua index 6f88d240f..0a92f6064 100644 --- a/lexlua/lexer.lua +++ b/lexlua/lexer.lua @@ -306,70 +306,39 @@ local M = {} -- different tokens. Instead of highlighting with just colors, Scintilla allows -- for more rich highlighting, or "styling", with different fonts, font sizes, -- font attributes, and foreground and background colors, just to name a few. --- The unit of this rich highlighting is called a "style". Styles are simply --- strings of comma-separated property settings. By default, lexers associate --- predefined token names like `lexer.WHITESPACE`, `lexer.COMMENT`, --- `lexer.STRING`, etc. with particular styles as part of a universal color --- theme. These predefined styles include [`lexer.STYLE_CLASS`](), --- [`lexer.STYLE_COMMENT`](), [`lexer.STYLE_CONSTANT`](), --- [`lexer.STYLE_ERROR`](), [`lexer.STYLE_EMBEDDED`](), --- [`lexer.STYLE_FUNCTION`](), [`lexer.STYLE_IDENTIFIER`](), --- [`lexer.STYLE_KEYWORD`](), [`lexer.STYLE_LABEL`](), [`lexer.STYLE_NUMBER`](), --- [`lexer.STYLE_OPERATOR`](), [`lexer.STYLE_PREPROCESSOR`](), --- [`lexer.STYLE_REGEX`](), [`lexer.STYLE_STRING`](), [`lexer.STYLE_TYPE`](), --- [`lexer.STYLE_VARIABLE`](), and [`lexer.STYLE_WHITESPACE`](). Like with --- predefined token names and LPeg patterns, you may define your own styles. At --- their core, styles are just strings, so you may create new ones and/or modify --- existing ones. Each style consists of the following comma-separated settings: --- --- Setting | Description --- ---------------|------------ --- font:_name_ | The name of the font the style uses. --- size:_int_ | The size of the font the style uses. --- [not]bold | Whether or not the font face is bold. --- weight:_int_ | The weight or boldness of a font, between 1 and 999. --- [not]italics | Whether or not the font face is italic. --- [not]underlined| Whether or not the font face is underlined. --- fore:_color_ | The foreground color of the font face. --- back:_color_ | The background color of the font face. --- [not]eolfilled | Does the background color extend to the end of the line? --- case:_char_ | The case of the font ('u': upper, 'l': lower, 'm': normal). --- [not]visible | Whether or not the text is visible. --- [not]changeable| Whether the text is changeable or read-only. --- --- Specify font colors in either "#RRGGBB" format, "0xBBGGRR" format, or the --- decimal equivalent of the latter. As with token names, LPeg patterns, and --- styles, there is a set of predefined color names, but they vary depending on --- the current color theme in use. Therefore, it is generally not a good idea to --- manually define colors within styles in your lexer since they might not fit --- into a user's chosen color theme. Try to refrain from even using predefined --- colors in a style because that color may be theme-specific. Instead, the best --- practice is to either use predefined styles or derive new color-agnostic --- styles from predefined ones. For example, Lua "longstring" tokens use the --- existing `lexer.STYLE_STRING` style instead of defining a new one. +-- The unit of this rich highlighting is called a "style". Styles are simply Lua +-- tables of properties. By default, lexers associate predefined token names +-- like `lexer.WHITESPACE`, `lexer.COMMENT`, `lexer.STRING`, etc. with +-- particular styles as part of a universal color theme. These predefined styles +-- are contained in [`lexer.styles`](), and you may define your own styles. See +-- that table's documentation for more information. As with token names, +-- LPeg patterns, and styles, there is a set of predefined color names, but they +-- vary depending on the current color theme in use. Therefore, it is generally +-- not a good idea to manually define colors within styles in your lexer since +-- they might not fit into a user's chosen color theme. Try to refrain from even +-- using predefined colors in a style because that color may be theme-specific. +-- Instead, the best practice is to either use predefined styles or derive new +-- color-agnostic styles from predefined ones. For example, Lua "longstring" +-- tokens use the existing `lexer.styles.string` style instead of defining a new +-- one. -- -- ##### Example Styles -- -- Defining styles is pretty straightforward. An empty style that inherits the --- default theme settings is simply an empty string: +-- default theme settings is simply an empty table: -- --- local style_nothing = '' +-- local style_nothing = {} -- -- A similar style but with a bold font face looks like this: -- --- local style_bold = 'bold' +-- local style_bold = {bold = true} -- --- If you want the same style, but also with an italic font face, define the new --- style in terms of the old one: +-- You can derive new styles from predefined ones without having to rewrite +-- them. This operation leaves the old style unchanged. For example, if you had +-- a "static variable" token whose style you wanted to base off of +-- `lexer.styles.variable`, it would probably look like: -- --- local style_bold_italic = style_bold .. ',italics' --- --- This allows you to derive new styles from predefined ones without having to --- rewrite them. This operation leaves the old style unchanged. Thus if you --- had a "static variable" token whose style you wanted to base off of --- `lexer.STYLE_VARIABLE`, it would probably look like: --- --- local style_static_var = lexer.STYLE_VARIABLE .. ',italics' +-- local style_static_var = lexer.styles.variable .. {italics = true} -- -- The color theme files in the *lexers/themes/* folder give more examples of -- style definitions. @@ -391,7 +360,7 @@ local M = {} -- -- Assigning a style to this token looks like: -- --- lex:add_style('custom_whitespace', lexer.STYLE_WHITESPACE) +-- lex:add_style('custom_whitespace', lexer.styles.whitespace) -- -- Do not confuse token names with rule names. They are completely different -- entities. In the example above, the lexer associates the "custom_whitespace" @@ -399,13 +368,11 @@ local M = {} -- prefer to color the background of whitespace a shade of grey, it might look -- like: -- --- local custom_style = lexer.STYLE_WHITESPACE .. ',back:$(color.grey)' --- lex:add_style('custom_whitespace', custom_style) +-- lex:add_style('custom_whitespace', +-- lexer.styles.whitespace .. {back = lexer.colors.grey}) -- --- Notice that the lexer peforms Scintilla-style "$()" property expansion. You --- may also use "%()". Remember to refrain from assigning specific colors in --- styles, but in this case, all user color themes probably define the --- "color.grey" property. +-- Remember to refrain from assigning specific colors in styles, but in this +-- case, all user color themes probably define `colors.grey`. -- -- #### Line Lexers -- @@ -491,7 +458,7 @@ local M = {} -- local html = lexer.load('html') -- local php_start_rule = token('php_tag', '<?php ') -- local php_end_rule = token('php_tag', '?>') --- lex:add_style('php_tag', lexer.STYLE_EMBEDDED) +-- lex:add_style('php_tag', lexer.styles.embedded) -- html:embed(lex, php_start_rule, php_end_rule) -- -- #### Lexers with Complex State @@ -702,7 +669,7 @@ local M = {} -- lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[foo bar baz]])) -- lex:add_rule('custom', token('custom', P('quux'))) --- lex:add_style('custom', lexer.STYLE_KEYWORD .. ',bold') +-- lex:add_style('custom', lexer.styles.keyword .. {bold = true}) -- lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) -- lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) @@ -796,58 +763,6 @@ local M = {} -- The token name for label tokens. -- @field REGEX (string) -- The token name for regex tokens. --- @field STYLE_CLASS (string) --- The style typically used for class definitions. --- @field STYLE_COMMENT (string) --- The style typically used for code comments. --- @field STYLE_CONSTANT (string) --- The style typically used for constants. --- @field STYLE_ERROR (string) --- The style typically used for erroneous syntax. --- @field STYLE_FUNCTION (string) --- The style typically used for function definitions. --- @field STYLE_KEYWORD (string) --- The style typically used for language keywords. --- @field STYLE_LABEL (string) --- The style typically used for labels. --- @field STYLE_NUMBER (string) --- The style typically used for numbers. --- @field STYLE_OPERATOR (string) --- The style typically used for operators. --- @field STYLE_REGEX (string) --- The style typically used for regular expression strings. --- @field STYLE_STRING (string) --- The style typically used for strings. --- @field STYLE_PREPROCESSOR (string) --- The style typically used for preprocessor statements. --- @field STYLE_TYPE (string) --- The style typically used for static types. --- @field STYLE_VARIABLE (string) --- The style typically used for variables. --- @field STYLE_WHITESPACE (string) --- The style typically used for whitespace. --- @field STYLE_EMBEDDED (string) --- The style typically used for embedded code. --- @field STYLE_IDENTIFIER (string) --- The style typically used for identifier words. --- @field STYLE_DEFAULT (string) --- The style all styles are based off of. --- @field STYLE_LINENUMBER (string) --- The style used for all margins except fold margins. --- @field STYLE_BRACELIGHT (string) --- The style used for highlighted brace characters. --- @field STYLE_BRACEBAD (string) --- The style used for unmatched brace characters. --- @field STYLE_CONTROLCHAR (string) --- The style used for control characters. --- Color attributes are ignored. --- @field STYLE_INDENTGUIDE (string) --- The style used for indentation guides. --- @field STYLE_CALLTIP (string) --- The style used by call tips if [`view.call_tip_use_style`]() is set. --- Only the font name, size, and color attributes are used. --- @field STYLE_FOLDDISPLAYTEXT (string) --- The style used for fold display text. -- @field any (pattern) -- A pattern that matches any single character. -- @field ascii (pattern) @@ -965,6 +880,98 @@ local function searchpath(name, path) return nil, table.concat(tried, '\n') end +--- +-- Map of color names strings to color values in `0xBBGGRR` or `"#RRGGBB"` +-- format. +-- @name colors +-- @class table +M.colors = setmetatable({}, { + __index = function(_, name) return M.property['color.' .. name] end, + __newindex = function(_, name, color) M.property['color.' .. name] = color end +}) + +-- A style object that distills into a property string that can be read by the +-- LPeg lexer. +local style_obj = {} +style_obj.__index = style_obj + +-- Create a style object from a style name, property table, or legacy style +-- string. +function style_obj.new(name_or_props) + local prop_string = tostring(name_or_props) + if type(name_or_props) == 'string' and name_or_props:find('^[%w_]+$') then + prop_string = string.format('$(style.%s)', name_or_props) + elseif type(name_or_props) == 'table' then + local settings = {} + for k, v in pairs(name_or_props) do + settings[#settings + 1] = type(v) ~= 'boolean' and + string.format('%s:%s', k, v) or + string.format('%s%s', v and '' or 'not', k) + end + prop_string = table.concat(settings, ',') + end + return setmetatable({prop_string = prop_string}, style_obj) +end + +-- Returns a new style based on this one with the properties defined in the +-- given table or legacy style string. +function style_obj.__concat(self, props) + if type(props) == 'table' then props = tostring(style_obj.new(props)) end + return setmetatable( + {prop_string = string.format('%s,%s', self.prop_string, props)}, style_obj) +end + +-- Returns this style object as property string for use with the LPeg lexer. +function style_obj.__tostring(self) return self.prop_string end + +--- +-- Map of style names to style definition tables. +-- +-- Style names consist of the following default names as well as the token names +-- defined by lexers. +-- +-- * `default`: The default style all others are based on. +-- * `line_number`: The line number margin style. +-- * `control_char`: The style of control character blocks. +-- * `indent_guide`: The style of indentation guides. +-- * `call_tip`: The style of call tip text. Only the `font`, `size`, `fore`, +-- and `back` style definition fields are supported. +-- * `fold_display_text`: The style of text displayed next to folded lines. +-- * `class`, `comment`, `constant`, `embedded`, `error`, `function`, +-- `identifier`, `keyword`, `label`, `number`, `operator`, `preprocessor`, +-- `regex`, `string`, `type`, `variable`, `whitespace`: Some token names used +-- by lexers. Some lexers may define more token names, so this list is not +-- exhaustive. +-- +-- Style definition tables may contain the following fields: +-- +-- * `font`: String font name. +-- * `size`: Integer font size. +-- * `bold`: Whether or not the font face is bold. The default value is `false`. +-- * `weight`: Integer weight or boldness of a font, between 1 and 999. +-- * `italics`: Whether or not the font face is italic. The default value is +-- `false`. +-- * `underlined`: Whether or not the font face is underlined. The default value +-- is `false`. +-- * `fore`: Font face foreground color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `back`: Font face background color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `eolfilled`: Whether or not the background color extends to the end of the +-- line. The default value is `false`. +-- * `case`: Font case, `'u'` for upper, `'l'` for lower, and `'m'` for normal, +-- mixed case. The default value is `'m'`. +-- * `visible`: Whether or not the text is visible. The default value is `true`. +-- * `changeable`: Whether the text is changeable instead of read-only. The +-- default value is `true`. +-- @class table +-- @name styles +M.styles = setmetatable({}, { + __index = function(_, name) return style_obj.new(name) end, + __newindex = function(_, name, style) + if getmetatable(style) ~= style_obj then style = style_obj.new(style) end + M.property['style.' .. name] = tostring(style) + end +}) + -- Default styles. local default = { 'nothing', 'whitespace', 'comment', 'string', 'number', 'keyword', @@ -973,16 +980,16 @@ local default = { } for _, name in ipairs(default) do M[name:upper()] = name - M['STYLE_' .. name:upper()] = string.format('$(style.%s)', name) + M['STYLE_' .. name:upper()] = style_obj.new(name) -- backward compatibility end -- Predefined styles. local predefined = { - 'default', 'linenumber', 'bracelight', 'bracebad', 'controlchar', - 'indentguide', 'calltip', 'folddisplaytext' + 'default', 'line_number', 'brace_light', 'brace_bad', 'control_char', + 'indent_guide', 'call_tip', 'fold_display_text' } for _, name in ipairs(predefined) do M[name:upper()] = name - M['STYLE_' .. name:upper()] = string.format('$(style.%s)', name) + M['STYLE_' .. name:upper()] = style_obj.new(name) -- backward compatibility end --- @@ -1032,44 +1039,47 @@ function M.get_rule(lexer, id) end --- --- Associates string *token_name* in lexer *lexer* with Scintilla style string --- *style*. --- Style strings are comma-separated property settings. Available property --- settings are: --- --- * `font:name`: Font name. --- * `size:int`: Font size. --- * `bold` or `notbold`: Whether or not the font face is bold. --- * `weight:int`: Font weight (between 1 and 999). --- * `italics` or `notitalics`: Whether or not the font face is italic. --- * `underlined` or `notunderlined`: Whether or not the font face is --- underlined. --- * `fore:color`: Font face foreground color in "#RRGGBB" or 0xBBGGRR format. --- * `back:color`: Font face background color in "#RRGGBB" or 0xBBGGRR format. --- * `eolfilled` or `noteolfilled`: Whether or not the background color --- extends to the end of the line. --- * `case:char`: Font case ('u' for uppercase, 'l' for lowercase, and 'm' for --- mixed case). --- * `visible` or `notvisible`: Whether or not the text is visible. --- * `changeable` or `notchangeable`: Whether or not the text is changeable or --- read-only. --- --- Property settings may also contain "$(property.name)" expansions for --- properties defined in Scintilla, theme files, etc. +-- Associates string *token_name* in lexer *lexer* with style table *style*. +-- *style* may have the following fields: +-- +-- * `font`: String font name. +-- * `size`: Integer font size. +-- * `bold`: Whether or not the font face is bold. The default value is `false`. +-- * `weight`: Integer weight or boldness of a font, between 1 and 999. +-- * `italics`: Whether or not the font face is italic. The default value is +-- `false`. +-- * `underlined`: Whether or not the font face is underlined. The default value +-- is `false`. +-- * `fore`: Font face foreground color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `back`: Font face background color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `eolfilled`: Whether or not the background color extends to the end of the +-- line. The default value is `false`. +-- * `case`: Font case, `'u'` for upper, `'l'` for lower, and `'m'` for normal, +-- mixed case. The default value is `'m'`. +-- * `visible`: Whether or not the text is visible. The default value is `true`. +-- * `changeable`: Whether the text is changeable instead of read-only. The +-- default value is `true`. +-- +-- Field values may also contain "$(property.name)" expansions for properties +-- defined in Scintilla, theme files, etc. -- @param lexer The lexer to add a style to. -- @param token_name The name of the token to associated with the style. -- @param style A style string for Scintilla. --- @usage lex:add_style('longstring', lexer.STYLE_STRING) --- @usage lex:add_style('deprecated_func', lexer.STYLE_FUNCTION .. ',italics') --- @usage lex:add_style('visible_ws', --- lexer.STYLE_WHITESPACE .. ',back:$(color.grey)') +-- @usage lex:add_style('longstring', lexer.styles.string) +-- @usage lex:add_style('deprecated_func', lexer.styles['function'] .. +-- {italics = true} +-- @usage lex:add_style('visible_ws', lexer.styles.whitespace .. +-- {back = lexer.colors.grey} -- @name add_style function M.add_style(lexer, token_name, style) local num_styles = lexer._numstyles if num_styles == 33 then num_styles = num_styles + 8 end -- skip predefined if num_styles >= 256 then print('Too many styles defined (256 MAX)') end lexer._TOKENSTYLES[token_name], lexer._numstyles = num_styles, num_styles + 1 - lexer._EXTRASTYLES[token_name] = style + if type(style) == 'table' and not getmetatable(style) then + style = style_obj.new(style) + end + lexer._EXTRASTYLES[token_name] = tostring(style) -- If the lexer is a proxy or a child that embedded itself, copy this style to -- the parent lexer. if lexer._lexer then lexer._lexer:add_style(token_name, style) end @@ -1529,7 +1539,11 @@ function M.load(name, alt_name, cache) -- `property_int` tables do not exist (they are not useful). Create them in -- order prevent errors from occurring. if not M.property then - M.property = {['lexer.lpeg.home'] = package.path:gsub('/%?%.lua', '')} + M.property = setmetatable( + {['lexer.lpeg.home'] = package.path:gsub('/%?%.lua', '')}, { + __index = function() return '' end, + __newindex = function(t, k, v) rawset(t, k, tostring(v)) end + }) M.property_int = setmetatable({}, { __index = function(t, k) return tonumber(M.property[k]) or 0 end, __newindex = function() error('read-only property') end @@ -1555,7 +1569,7 @@ function M.load(name, alt_name, cache) process_legacy_lexer(lexer._lexer) -- mainly for `_foldsymbols` edits end end - lexer:add_style((alt_name or name) .. '_whitespace', M.STYLE_WHITESPACE) + lexer:add_style((alt_name or name) .. '_whitespace', M.styles.whitespace) -- If the lexer is a proxy or a child that embedded itself, set the parent to -- be the main lexer. Keep a reference to the old parent name since embedded diff --git a/lexlua/lua.lua b/lexlua/lua.lua index 655f237f5..7c5a83de8 100644 --- a/lexlua/lua.lua +++ b/lexlua/lua.lua @@ -32,7 +32,7 @@ local deprecated_func = token('deprecated_function', word_match[[ getfenv loadstring module setfenv unpack ]]) lex:add_rule('function', func + deprecated_func) -lex:add_style('deprecated_function', lexer.STYLE_FUNCTION .. ',italics') +lex:add_style('deprecated_function', lexer.STYLE_FUNCTION .. {italics = true}) -- Constants. lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ @@ -103,7 +103,7 @@ local deprecated_library = token('deprecated_library', word_match[[ ]]) lex:add_rule('library', library + deprecated_library) lex:add_style('library', lexer.STYLE_TYPE) -lex:add_style('deprecated_library', lexer.STYLE_TYPE .. ',italics') +lex:add_style('deprecated_library', lexer.STYLE_TYPE .. {italics = true}) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/lexlua/markdown.lua b/lexlua/markdown.lua index fbedb2418..733c39fec 100644 --- a/lexlua/markdown.lua +++ b/lexlua/markdown.lua @@ -12,10 +12,11 @@ local function h(n) return token('h' .. n, lexer.to_eol(lexer.starts_line(string.rep('#', n)))) end lex:add_rule('header', h(6) + h(5) + h(4) + h(3) + h(2) + h(1)) +local font_size = + tonumber(lexer.property_expanded['style.default']:match('size:(%d+)')) or 10 local function add_header_style(n) - local font_size = lexer.property_int['fontsize'] > 0 and - lexer.property_int['fontsize'] or 10 - lex:add_style('h' .. n, 'fore:$(color.red),size:' .. (font_size + (6 - n))) + lex:add_style( + 'h' .. n, {fore = lexer.colors.red, size = (font_size + (6 - n))}) end for i = 1, 6 do add_header_style(i) end @@ -42,7 +43,7 @@ local code_inline = lpeg.Cmt(lpeg.C(P('`')^1), function(input, index, bt) return (e or #input) + 1 end) lex:add_rule('block_code', token('code', code_line + code_block + code_inline)) -lex:add_style('code', lexer.STYLE_EMBEDDED .. ',eolfilled') +lex:add_style('code', lexer.STYLE_EMBEDDED .. {eolfilled = true}) lex:add_rule('hr', token('hr', lpeg.Cmt( lexer.starts_line(S(' \t')^0 * lpeg.C(S('*-_'))), function(input, index, c) @@ -50,7 +51,7 @@ lex:add_rule('hr', token('hr', lpeg.Cmt( if line:find('[^' .. c .. ']') or #line < 2 then return nil end return (select(2, input:find('\r?\n', index)) or #input) + 1 end))) -lex:add_style('hr', 'back:$(color.black),eolfilled') +lex:add_style('hr', {back = lexer.colors.black, eolfilled = true}) -- Whitespace. local ws = token(lexer.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1) @@ -66,7 +67,7 @@ local ref_link_title = token(lexer.STRING, lexer.range('"', true, false) + lex:add_rule('link_label', ref_link_label * ws * ref_link_url * (ws * ref_link_title)^-1) lex:add_style('link_label', lexer.STYLE_LABEL) -lex:add_style('link_url', 'underlined') +lex:add_style('link_url', {underlined = true}) local link_label = P('!')^-1 * lexer.range('[', ']', true) local link_target = P('(') * (lexer.any - S(') \t'))^0 * @@ -75,7 +76,7 @@ local link_ref = S(' \t')^0 * lexer.range('[', ']', true) local link_url = 'http' * P('s')^-1 * '://' * (lexer.any - lexer.space)^1 lex:add_rule('link', token('link', link_label * (link_target + link_ref) + link_url)) -lex:add_style('link', 'underlined') +lex:add_style('link', {underlined = true}) local punct_space = lexer.punct + lexer.space @@ -95,12 +96,12 @@ end lex:add_rule('strong', token('strong', flanked_range('**') + (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('__', true) * #(punct_space + -1))) -lex:add_style('strong', 'bold') +lex:add_style('strong', {bold = true}) lex:add_rule('em', token('em', flanked_range('*') + (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('_', true) * #(punct_space + -1))) -lex:add_style('em', 'italics') +lex:add_style('em', {italics = true}) -- Embedded HTML. local html = lexer.load('html') diff --git a/lexlua/mediawiki.lua b/lexlua/mediawiki.lua index 27a7409d8..942e06612 100644 --- a/lexlua/mediawiki.lua +++ b/lexlua/mediawiki.lua @@ -28,7 +28,7 @@ lex:add_style('tag_end', lexer.STYLE_KEYWORD) lex:add_rule('link', token(lexer.STRING, S('[]'))) lex:add_rule('internal_link', B('[[') * token('link_article', (lexer.any - '|' - ']]')^1)) -lex:add_style('link_article', lexer.STYLE_STRING .. ',underlined') +lex:add_style('link_article', lexer.STYLE_STRING .. {underlined = true}) -- Templates and parser functions. lex:add_rule('template', token(lexer.OPERATOR, S('{}'))) @@ -37,7 +37,7 @@ lex:add_rule('parser_func', B('{{') * lex:add_rule('template_name', B('{{') * token('template_name', (lexer.any - S('{}|'))^1)) lex:add_style('parser_func', lexer.STYLE_FUNCTION) -lex:add_style('template_name', lexer.STYLE_OPERATOR .. ',underlined') +lex:add_style('template_name', lexer.STYLE_OPERATOR .. {underlined = true}) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('-=|#~!'))) diff --git a/lexlua/texinfo.lua b/lexlua/texinfo.lua index bb5ba55c6..a5a7148cb 100644 --- a/lexlua/texinfo.lua +++ b/lexlua/texinfo.lua @@ -182,11 +182,11 @@ local nested_braces = lexer.range('{', '}', false, false, true) -- Italics lex:add_rule('emph', token('emph', '@emph' * nested_braces)) -lex:add_style('emph', lexer.STYLE_STRING .. ',italics') +lex:add_style('emph', lexer.STYLE_STRING .. {italics = true}) -- Bold lex:add_rule('strong', token('strong', '@strong' * nested_braces)) -lex:add_style('strong', lexer.STYLE_STRING .. ',bold') +lex:add_style('strong', lexer.STYLE_STRING .. {bold = true}) -- Identifiers lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/lexlua/themes/curses.lua b/lexlua/themes/curses.lua index 1ac1928df..b0d6066db 100644 --- a/lexlua/themes/curses.lua +++ b/lexlua/themes/curses.lua @@ -2,54 +2,56 @@ -- Curses theme for Lua lexers. -- Contributions by Ana Balan. -local property = require('lexer').property +local lexer = require('lexer') +local colors, styles = lexer.colors, lexer.styles -- Normal colors. -property['color.black'] = '#000000' -property['color.red'] = '#800000' -property['color.green'] = '#008000' -property['color.yellow'] = '#808000' -property['color.blue'] = '#000080' -property['color.magenta'] = '#800080' -property['color.cyan'] = '#008080' -property['color.white'] = '#C0C0C0' +colors.black = '#000000' +colors.red = '#800000' +colors.green = '#008000' +colors.yellow = '#808000' +colors.blue = '#000080' +colors.magenta = '#800080' +colors.cyan = '#008080' +colors.white = '#C0C0C0' -- Light colors. (16 color terminals only.) -- These only apply to 16 color terminals. For other terminals, set the -- style's `bold` attribute to use the light color variant. -property['color.light_black'] = '#404040' -property['color.light_red'] = '#FF0000' -property['color.light_green'] = '#00FF00' ---property['color.light_yellow'] = '#FFFF00' -property['color.light_blue'] = '#0000FF' -property['color.light_magenta'] = '#FF00FF' ---property['color.light_cyan'] = '#0000FF' -property['color.light_white'] = '#FFFFFF' +colors.light_black = '#404040' +colors.light_red = '#FF0000' +colors.light_green = '#00FF00' +colors.light_yellow = '#FFFF00' +colors.light_blue = '#0000FF' +colors.light_magenta = '#FF00FF' +colors.light_cyan = '#0000FF' +colors.light_white = '#FFFFFF' -- Predefined styles. -property['style.default'] = 'fore:$(color.white),back:$(color.black)' -property['style.linenumber'] = '' -property['style.bracelight'] = 'fore:$(color.black),back:$(color.white)' -property['style.controlchar'] = '' -property['style.indentguide'] = '' -property['style.calltip'] = '$(style.default)' -property['style.folddisplaytext'] = 'fore:$(color.black),bold' +styles.default = {fore = colors.white, back = colors.black} +styles.line_number = {fore = colors.black, bold = true} +styles.brace_light = {fore = colors.black, back = colors.white} +styles.control_char = {} +styles.indent_guide = {} +styles.call_tip = {} +styles.fold_display_text = {fore = colors.black, bold = true} -- Token styles. -property['style.class'] = 'fore:$(color.yellow)' -property['style.comment'] = 'fore:$(color.black),bold' -property['style.constant'] = 'fore:$(color.red)' -property['style.embedded'] = '$(style.keyword),back:$(color.black)' -property['style.error'] = 'fore:$(color.red),bold' -property['style.function'] = 'fore:$(color.blue)' -property['style.identifier'] = '' -property['style.keyword'] = 'fore:$(color.white),bold' -property['style.label'] = 'fore:$(color.red),bold' -property['style.number'] = 'fore:$(color.cyan)' -property['style.operator'] = 'fore:$(color.yellow)' -property['style.preprocessor'] = 'fore:$(color.magenta)' -property['style.regex'] = 'fore:$(color.green),bold' -property['style.string'] = 'fore:$(color.green)' -property['style.type'] = 'fore:$(color.magenta),bold' -property['style.variable'] = 'fore:$(color.blue),bold' -property['style.whitespace'] = '' +styles.class = {fore = colors.yellow} +styles.comment = {fore = colors.black, bold = true} +styles.constant = {fore = colors.red} +styles.embedded = {fore = colors.white, bold = true, back = colors.black} +styles.error = {fore = colors.red, bold = true} +styles['function'] = {fore = colors.blue} +styles.identifier = {} +styles.keyword = {fore = colors.white, bold = true} +styles.label = {fore = colors.red, bold = true} +styles.number = {fore = colors.cyan} +styles.operator = {fore = colors.yellow} +styles.preprocessor = {fore = colors.magenta} +styles.regex = {fore = colors.green, bold = true} +styles.string = {fore = colors.green} +styles.type = {fore = colors.magenta, bold = true} +styles.variable = {fore = colors.blue, bold = true} +styles.whitespace = {} + diff --git a/lexlua/themes/dark.lua b/lexlua/themes/dark.lua index e187c4e7c..f0ebdf6b6 100644 --- a/lexlua/themes/dark.lua +++ b/lexlua/themes/dark.lua @@ -2,88 +2,87 @@ -- Dark theme for Lua lexers. -- Contributions by Ana Balan. -local property = require('lexer').property +local lexer = require('lexer') +local colors, styles = lexer.colors, lexer.styles -- Greyscale colors. ---property['color.dark_black'] = '#000000' -property['color.black'] = '#1A1A1A' -property['color.light_black'] = '#333333' ---property['color.grey_black'] = '#4D4D4D' -property['color.dark_grey'] = '#666666' ---property['color.grey'] = '#808080' -property['color.light_grey'] = '#999999' ---property['color.grey_white'] = '#B3B3B3' -property['color.dark_white'] = '#CCCCCC' ---property['color.white'] = '#E6E6E6' ---property['color.light_white'] = '#FFFFFF' +colors.dark_black = '#000000' +colors.black = '#1A1A1A' +colors.light_black = '#333333' +colors.grey_black = '#4D4D4D' +colors.dark_grey = '#666666' +colors.grey = '#808080' +colors.light_grey = '#999999' +colors.grey_white = '#B3B3B3' +colors.dark_white = '#CCCCCC' +colors.white = '#E6E6E6' +colors.light_white = '#FFFFFF' -- Dark colors. ---property['color.dark_red'] = '#661A1A' ---property['color.dark_yellow'] = '#66661A' ---property['color.dark_green'] = '#1A661A' ---property['color.dark_teal'] = '#1A6666' ---property['color.dark_purple'] = '#661A66' ---property['color.dark_orange'] = '#B3661A' ---property['color.dark_pink'] = '#B36666' ---property['color.dark_lavender'] = '#6666B3' ---property['color.dark_blue'] = '#1A66B3' +colors.dark_red = '#661A1A' +colors.dark_yellow = '#66661A' +colors.dark_green = '#1A661A' +colors.dark_teal = '#1A6666' +colors.dark_purple = '#661A66' +colors.dark_orange = '#B3661A' +colors.dark_pink = '#B36666' +colors.dark_lavender = '#6666B3' +colors.dark_blue = '#1A66B3' -- Normal colors. -property['color.red'] = '#994D4D' -property['color.yellow'] = '#99994D' -property['color.green'] = '#4D994D' -property['color.teal'] = '#4D9999' -property['color.purple'] = '#994D99' -property['color.orange'] = '#E6994D' ---property['color.pink'] = '#E69999' -property['color.lavender'] = '#9999E6' -property['color.blue'] = '#4D99E6' +colors.red = '#994D4D' +colors.yellow = '#99994D' +colors.green = '#4D994D' +colors.teal = '#4D9999' +colors.purple = '#994D99' +colors.orange = '#E6994D' +colors.pink = '#E69999' +colors.lavender = '#9999E6' +colors.blue = '#4D99E6' -- Light colors. -property['color.light_red'] = '#CC8080' -property['color.light_yellow'] = '#CCCC80' -property['color.light_green'] = '#80CC80' ---property['color.light_teal'] = '#80CCCC' ---property['color.light_purple'] = '#CC80CC' ---property['color.light_orange'] = '#FFCC80' ---property['color.light_pink'] = '#FFCCCC' ---property['color.light_lavender'] = '#CCCCFF' -property['color.light_blue'] = '#80CCFF' +colors.light_red = '#CC8080' +colors.light_yellow = '#CCCC80' +colors.light_green = '#80CC80' +colors.light_teal = '#80CCCC' +colors.light_purple = '#CC80CC' +colors.light_orange = '#FFCC80' +colors.light_pink = '#FFCCCC' +colors.light_lavender = '#CCCCFF' +colors.light_blue = '#80CCFF' --- Default style. -property['font'], property['fontsize'] = 'Bitstream Vera Sans Mono', '10' -if WIN32 then - property['font'] = 'Courier New' -elseif OSX then - property['font'], property['fontsize'] = 'Monaco', '12' -end +-- Default font. +local font = WIN32 and 'Courier New' or OSX and 'Monaco' or + 'Bitstream Vera Sans Mono' +local size = not OSX and 10 or 12 -- Predefined styles. -property['style.default'] = 'font:$(font),size:$(fontsize),'.. - 'fore:$(color.light_grey),back:$(color.black)' -property['style.linenumber'] = 'fore:$(color.dark_grey),back:$(color.black)' -property['style.bracelight'] = 'fore:$(color.light_blue)' -property['style.bracebad'] = 'fore:$(color.light_red)' -property['style.controlchar'] = '' -property['style.indentguide'] = 'fore:$(color.light_black)' -property['style.calltip'] = 'fore:$(color.light_grey),back:$(color.light_black)' -property['style.folddisplaytext'] = 'fore:$(color.dark_grey)' +styles.default = { + font = font, size = size, fore = colors.light_grey, back = colors.black +} +styles.line_number = {fore = colors.grey, back = colors.black} +styles.brace_light = {fore = colors.light_blue} +styles.brace_bad = {fore = colors.light_red} +styles.control_char = {} +styles.indent_guide = {fore = colors.light_black} +styles.call_tip = {fore = colors.light_grey, back = colors.light_black} +styles.fold_display_text = {fore = colors.dark_grey} -- Token styles. -property['style.class'] = 'fore:$(color.light_yellow)' -property['style.comment'] = 'fore:$(color.dark_grey)' -property['style.constant'] = 'fore:$(color.red)' -property['style.embedded'] = '$(style.keyword),back:$(color.light_black)' -property['style.error'] = 'fore:$(color.red),italics' -property['style.function'] = 'fore:$(color.blue)' -property['style.identifier'] = '' -property['style.keyword'] = 'fore:$(color.dark_white)' -property['style.label'] = 'fore:$(color.orange)' -property['style.number'] = 'fore:$(color.teal)' -property['style.operator'] = 'fore:$(color.yellow)' -property['style.preprocessor'] = 'fore:$(color.purple)' -property['style.regex'] = 'fore:$(color.light_green)' -property['style.string'] = 'fore:$(color.green)' -property['style.type'] = 'fore:$(color.lavender)' -property['style.variable'] = 'fore:$(color.light_blue)' -property['style.whitespace'] = '' +styles.class = {fore = colors.light_yellow} +styles.comment = {fore = colors.dark_grey} +styles.constant = {fore = colors.red} +styles.embedded = {fore = colors.dark_white, back = colors.light_black} +styles.error = {fore = colors.red, italics = true} +styles['function'] = {fore = colors.blue} +styles.identifier = {} +styles.keyword = {fore = colors.dark_white} +styles.label = {fore = colors.orange} +styles.number = {fore = colors.teal} +styles.operator = {fore = colors.yellow} +styles.preprocessor = {fore = colors.purple} +styles.regex = {fore = colors.light_green} +styles.string = {fore = colors.green} +styles.type = {fore = colors.lavender} +styles.variable = {fore = colors.light_blue} +styles.whitespace = {} diff --git a/lexlua/themes/light.lua b/lexlua/themes/light.lua index e3d1a63eb..0de6a9dcf 100644 --- a/lexlua/themes/light.lua +++ b/lexlua/themes/light.lua @@ -2,88 +2,87 @@ -- Light theme for Lua lexers. -- Contributions by Ana Balan. -local property = require('lexer').property +local lexer = require('lexer') +local colors, styles = lexer.colors, lexer.styles -- Greyscale colors. ---property['color.dark_black'] = '#000000' ---property['color.black'] = '#1A1A1A' -property['color.light_black'] = '#333333' ---property['color.grey_black'] = '#4D4D4D' ---property['color.dark_grey'] = '#666666' -property['color.grey'] = '#808080' ---property['color.light_grey'] = '#999999' ---property['grey_white'] = '#B3B3B3' -property['color.dark_white'] = '#CCCCCC' -property['color.white'] = '#E6E6E6' ---property['color.light_white'] = '#FFFFFF' +colors.dark_black = '#000000' +colors.black = '#1A1A1A' +colors.light_black = '#333333' +colors.grey_black = '#4D4D4D' +colors.dark_grey = '#666666' +colors.grey = '#808080' +colors.light_grey = '#999999' +colors.grey_white = '#B3B3B3' +colors.dark_white = '#CCCCCC' +colors.white = '#E6E6E6' +colors.light_white = '#FFFFFF' -- Dark colors. ---property['color.dark_red'] = '#661A1A' -property['color.dark_yellow'] = '#66661A' -property['color.dark_green'] = '#1A661A' ---property['color.dark_teal'] = '#1A6666' ---property['color.dark_purple'] = '#661A66' -property['color.dark_orange'] = '#B3661A' ---property['color.dark_pink'] = '#B36666' -property['color.dark_lavender'] = '#6666B3' -property['color.dark_blue'] = '#1A66B3' +colors.dark_red = '#661A1A' +colors.dark_yellow = '#66661A' +colors.dark_green = '#1A661A' +colors.dark_teal = '#1A6666' +colors.dark_purple = '#661A66' +colors.dark_orange = '#B3661A' +colors.dark_pink = '#B36666' +colors.dark_lavender = '#6666B3' +colors.dark_blue = '#1A66B3' -- Normal colors. -property['color.red'] = '#994D4D' -property['color.yellow'] = '#99994D' -property['color.green'] = '#4D994D' -property['color.teal'] = '#4D9999' -property['color.purple'] = '#994D99' ---property['color.orange'] = '#E6994D' ---property['color.pink'] = '#E69999' -property['color.lavender'] = '#9999E6' ---property['color.blue'] = '#4D99E6' +colors.red = '#994D4D' +colors.yellow = '#99994D' +colors.green = '#4D994D' +colors.teal = '#4D9999' +colors.purple = '#994D99' +colors.orange = '#E6994D' +colors.pink = '#E69999' +colors.lavender = '#9999E6' +colors.blue = '#4D99E6' -- Light colors. -property['color.light_red'] = '#C08080' ---property['color.light_yellow'] = '#CCCC80' ---property['color.light_green'] = '#80CC80' ---property['color.light_teal'] = '#80CCCC' ---property['color.light_purple'] = '#CC80CC' ---property['color.light_orange'] = '#FFCC80' ---property['color.light_pink'] = '#FFCCCC' ---property['color.light_lavender'] = '#CCCCFF' -property['color.light_blue'] = '#80CCFF' +colors.light_red = '#C08080' +colors.light_yellow = '#CCCC80' +colors.light_green = '#80CC80' +colors.light_teal = '#80CCCC' +colors.light_purple = '#CC80CC' +colors.light_orange = '#FFCC80' +colors.light_pink = '#FFCCCC' +colors.light_lavender = '#CCCCFF' +colors.light_blue = '#80CCFF' --- Default style. -property['font'], property['fontsize'] = 'Bitstream Vera Sans Mono', '10' -if WIN32 then - property['font'] = 'Courier New' -elseif OSX then - property['font'], property['fontsize'] = 'Monaco', '12' -end +-- Default font. +local font = WIN32 and 'Courier New' or OSX and 'Monaco' or + 'Bitstream Vera Sans Mono' +local size = not OSX and 10 or 12 -- Predefined styles. -property['style.default'] = 'font:$(font),size:$(fontsize),'.. - 'fore:$(color.light_black),back:$(color.white)' -property['style.linenumber'] = 'fore:$(color.grey),back:$(color.white)' -property['style.bracelight'] = 'fore:$(color.light_blue)' -property['style.bracebad'] = 'fore:$(color.light_red)' -property['style.controlchar'] = '' -property['style.indentguide'] = 'fore:$(color.dark_white)' -property['style.calltip'] = 'fore:$(color.light_black),back:$(color.dark_white)' -property['style.folddisplaytext'] = 'fore:$(color.grey)' +styles.default = { + font = font, size = size, fore = colors.light_black, back = colors.white +} +styles.line_number = {fore = colors.grey, back = colors.white} +styles.brace_light = {fore = colors.light_blue} +styles.brace_bad = {fore = colors.light_red} +styles.control_char = {} +styles.indent_guide = {fore = colors.dark_white} +styles.call_tip = {fore = colors.light_black, back = colors.dark_white} +styles.fold_display_text = {fore = colors.grey} -- Token styles. -property['style.class'] = 'fore:$(color.yellow)' -property['style.comment'] = 'fore:$(color.grey)' -property['style.constant'] = 'fore:$(color.red)' -property['style.embedded'] = '$(style.keyword),back:$(color.dark_white)' -property['style.error'] = 'fore:$(color.red),italics' -property['style.function'] = 'fore:$(color.dark_orange)' -property['style.identifier'] = '' -property['style.keyword'] = 'fore:$(color.dark_blue)' -property['style.label'] = 'fore:$(color.dark_orange)' -property['style.number'] = 'fore:$(color.teal)' -property['style.operator'] = 'fore:$(color.purple)' -property['style.preprocessor'] = 'fore:$(color.dark_yellow)' -property['style.regex'] = 'fore:$(color.dark_green)' -property['style.string'] = 'fore:$(color.green)' -property['style.type'] = 'fore:$(color.lavender)' -property['style.variable'] = 'fore:$(color.dark_lavender)' -property['style.whitespace'] = '' +styles.class = {fore = colors.yellow} +styles.comment = {fore = colors.grey} +styles.constant = {fore = colors.red} +styles.embedded = {fore = colors.dark_blue, back = colors.dark_white} +styles.error = {fore = colors.red, italics} +styles['function'] = {fore = colors.dark_orange} +styles.identifier = {} +styles.keyword = {fore = colors.dark_blue} +styles.label = {fore = colors.dark_orange} +styles.number = {fore = colors.teal} +styles.operator = {fore = colors.purple} +styles.preprocessor = {fore = colors.dark_yellow} +styles.regex = {fore = colors.dark_green} +styles.string = {fore = colors.green} +styles.type = {fore = colors.lavender} +styles.variable = {fore = colors.dark_lavender} +styles.whitespace = {} diff --git a/lexlua/themes/scite.lua b/lexlua/themes/scite.lua index a7642290c..d9fc3d373 100644 --- a/lexlua/themes/scite.lua +++ b/lexlua/themes/scite.lua @@ -1,53 +1,51 @@ -- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. -- SciTE theme for Lua lexers. -local property = require('lexer').property +local lexer = require('lexer') +local colors, styles = lexer.colors, lexer.styles -property['color.red'] = '#7F0000' -property['color.yellow'] = '#7F7F00' -property['color.green'] = '#007F00' -property['color.teal'] = '#007F7F' -property['color.purple'] = '#7F007F' -property['color.orange'] = '#B07F00' -property['color.blue'] = '#00007F' -property['color.black'] = '#000000' -property['color.grey'] = '#808080' -property['color.white'] = '#FFFFFF' +colors.red = '#7F0000' +colors.yellow = '#7F7F00' +colors.green = '#007F00' +colors.teal = '#007F7F' +colors.purple = '#7F007F' +colors.orange = '#B07F00' +colors.blue = '#00007F' +colors.black = '#000000' +colors.grey = '#808080' +colors.white = '#FFFFFF' --- Default style. -property['font'], property['fontsize'] = 'Monospace', '11' -if WIN32 then - property['font'] = 'Courier New' -elseif OSX then - property['font'], property['fontsize'] = 'Monaco', '12' -end +-- Default font. +local font = WIN32 and 'Courier New' or OSX and 'Monaco' or 'Monospace' +local size = not OSX and 11 or 12 -- Predefined styles. -property['style.default'] = 'font:$(font),size:$(fontsize),'.. - 'fore:$(color.black),back:$(color.white)' -property['style.linenumber'] = 'back:#C0C0C0' -property['style.bracelight'] = 'fore:#0000FF,bold' -property['style.bracebad'] = 'fore:#FF0000,bold' -property['style.controlchar'] = '' -property['style.indentguide'] = 'fore:#C0C0C0,back:$(color.white)' -property['style.calltip'] = 'fore:$(color.white),back:#444444' -property['style.folddisplaytext'] = '' +styles.default = { + font = font, size = size, fore = colors.black, back = colors.white +} +styles.line_number = {back = '#C0C0C0'} +styles.brace_light = {fore = '#0000FF', bold = true} +styles.brace_bad = {fore = '#FF0000', bold = true} +styles.control_char = {} +styles.indent_guide = {fore = '#C0C0C0', back = colors.white} +styles.call_tip = {fore = colors.white, back = '#444444'} +styles.fold_display_text = {} -- Token styles. -property['style.class'] = 'fore:$(color.black),bold' -property['style.comment'] = 'fore:$(color.green)' -property['style.constant'] = 'fore:$(color.teal),bold' -property['style.embedded'] = 'fore:$(color.blue)' -property['style.error'] = 'fore:$(color.red)' -property['style.function'] = 'fore:$(color.black),bold' -property['style.identifier'] = '' -property['style.keyword'] = 'fore:$(color.blue),bold' -property['style.label'] = 'fore:$(color.teal),bold' -property['style.number'] = 'fore:$(color.teal)' -property['style.operator'] = 'fore:$(color.black),bold' -property['style.preprocessor'] = 'fore:$(color.yellow)' -property['style.regex'] = '$(style.string)' -property['style.string'] = 'fore:$(color.purple)' -property['style.type'] = 'fore:$(color.blue)' -property['style.variable'] = 'fore:$(color.black)' -property['style.whitespace'] = '' +styles.class = {fore = colors.black, bold = true} +styles.comment = {fore = colors.green} +styles.constant = {fore = colors.teal, bold = true} +styles.embedded = {fore = colors.blue} +styles.error = {fore = colors.red} +styles['function'] = {fore = colors.black, bold = true} +styles.identifier = {} +styles.keyword = {fore = colors.blue, bold = true} +styles.label = {fore = colors.teal, bold = true} +styles.number = {fore = colors.teal} +styles.operator = {fore = colors.black, bold = true} +styles.preprocessor = {fore = colors.yellow} +styles.regex = lexer.STYLE_STRING +styles.string = {fore = colors.purple} +styles.type = {fore = colors.blue} +styles.variable = {fore = colors.black} +styles.whitespace = {} diff --git a/lexlua/toml.lua b/lexlua/toml.lua index ae6835174..e96860e44 100644 --- a/lexlua/toml.lua +++ b/lexlua/toml.lua @@ -12,7 +12,7 @@ lex:add_rule('indent', #lexer.starts_line(S(' \t')) * (token(lexer.WHITESPACE, ' ') + token('indent_error', '\t'))^1) lex:add_rule('whitespace', token(lexer.WHITESPACE, S(' \t')^1 + lexer.newline^1)) -lex:add_style('indent_error', 'back:%(color.red)') +lex:add_style('indent_error', {back = lexer.colors.red}) -- kewwords. lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[true false]])) diff --git a/lexlua/txt2tags.lua b/lexlua/txt2tags.lua index 1fca8a695..9a7b753e3 100644 --- a/lexlua/txt2tags.lua +++ b/lexlua/txt2tags.lua @@ -120,36 +120,32 @@ lex:add_rule('verbatim_area', verbatim_area) lex:add_rule('raw_area', raw_area) lex:add_rule('tagged_area', tagged_area) -local font_size = lexer.property_int['fontsize'] > 0 and - lexer.property_int['fontsize'] or 10 -local hstyle = 'fore:$(color.red)' - -lex:add_style('line', 'bold') -lex:add_style('h5', hstyle .. ',size:' .. (font_size + 1)) -lex:add_style('h4', hstyle .. ',size:' .. (font_size + 2)) -lex:add_style('h3', hstyle .. ',size:' .. (font_size + 3)) -lex:add_style('h2', hstyle .. ',size:' .. (font_size + 4)) -lex:add_style('h1', hstyle .. ',size:' .. (font_size + 5)) +lex:add_style('line', {bold = true}) +local font_size = + tonumber(lexer.property_expanded['style.default']:match('size:(%d+)')) or 10 +for n = 5, 1, -1 do + lex:add_style('h' .. n, {fore = lexer.colors.red, size = font_size + (6 - n)}) +end lex:add_style('header_label', lexer.STYLE_LABEL) -lex:add_style('email', 'underlined') -lex:add_style('host', 'underlined') -lex:add_style('url', 'underlined') +lex:add_style('email', {underlined = true}) +lex:add_style('host', {underlined = true}) +lex:add_style('url', {underlined = true}) lex:add_style('address_label', lexer.STYLE_LABEL) -lex:add_style('address', 'underlined') -lex:add_style('image', 'fore:$(color.green)') -lex:add_style('image_link', 'underlined') +lex:add_style('address', {underlined = true}) +lex:add_style('image', {fore = lexer.colors.green}) +lex:add_style('image_link', {underlined = true}) lex:add_style('macro', lexer.STYLE_PREPROCESSOR) -lex:add_style('bold', 'bold') -lex:add_style('italic', 'italics') -lex:add_style('underline', 'underlined') -lex:add_style('strike', 'italics') -- a strike style is not available -lex:add_style('mono', 'font:mono') -lex:add_style('raw', 'back:$(color.grey)') +lex:add_style('bold', {bold = true}) +lex:add_style('italic', {italics = true}) +lex:add_style('underline', {underlined = true}) +lex:add_style('strike', {italics = true}) -- a strike style is not available +lex:add_style('mono', {font = 'mono'}) +lex:add_style('raw', {back = lexer.colors.grey}) lex:add_style('tagged', lexer.STYLE_EMBEDDED) -lex:add_style('verbatim_area', 'font:mono') -- in consistency with mono -lex:add_style('raw_area', 'back:$(color.grey)') -- in consistency with raw +lex:add_style('verbatim_area', {font = 'mono'}) -- in consistency with mono +lex:add_style('raw_area', {back = lexer.colors.grey}) -- in consistency with raw lex:add_style('tagged_area', lexer.STYLE_EMBEDDED) -- in consistency with tagged -lex:add_style('table_sep', 'fore:$(color.green)') -lex:add_style('header_cell_content', 'fore:$(color.green)') +lex:add_style('table_sep', {fore = lexer.colors.green}) +lex:add_style('header_cell_content', {fore = lexer.colors.green}) return lex |