aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/LPegLexer.html609
-rw-r--r--lexlua/awk.lua9
-rw-r--r--lexlua/chuck.lua2
-rw-r--r--lexlua/diff.lua8
-rw-r--r--lexlua/html.lua4
-rw-r--r--lexlua/lexer.lua314
-rw-r--r--lexlua/lua.lua4
-rw-r--r--lexlua/markdown.lua19
-rw-r--r--lexlua/mediawiki.lua4
-rw-r--r--lexlua/texinfo.lua4
-rw-r--r--lexlua/themes/curses.lua84
-rw-r--r--lexlua/themes/dark.lua143
-rw-r--r--lexlua/themes/light.lua143
-rw-r--r--lexlua/themes/scite.lua86
-rw-r--r--lexlua/toml.lua2
-rw-r--r--lexlua/txt2tags.lua48
-rw-r--r--test/test_lexlua.lua79
17 files changed, 722 insertions, 840 deletions
diff --git a/doc/LPegLexer.html b/doc/LPegLexer.html
index 291995710..f58c8e21e 100644
--- a/doc/LPegLexer.html
+++ b/doc/LPegLexer.html
@@ -453,7 +453,8 @@
<a class="message" href="#SCI_PROPERTYNAMES"><code>SCI_PROPERTYNAMES</code></a></p>
<p><b id="SCI_GETNAMEDSTYLES">SCI_PRIVATELEXERCALL(SCI_GETNAMEDSTYLES, const char *styleName)</b><br/>
- Returns the style number associated with <code>styleName</code>.</p>
+ Returns the style number associated with <code>styleName</code>, or <code>STYLE_DEFAULT</code>
+ if <code>styleName</code> is not in use.</p>
<p>Usage:</p>
@@ -581,7 +582,7 @@ operator 30
lexer. The next part deals with more advanced techniques, such as custom
coloring and embedding lexers within one another. Following that is a
discussion about code folding, or being able to tell Scintilla which code
- blocks are "foldable" (temporarily hideable from view). After that are
+ blocks are &ldquo;foldable&rdquo; (temporarily hideable from view). After that are
instructions on how to use Lua lexers with the aforementioned Textadept
editor. Finally there are comments on lexer performance and limitations.</p>
@@ -597,16 +598,16 @@ operator 30
language in lower case followed by a <em>.lua</em> extension. For example, a new Lua
lexer has the name <em>lua.lua</em>.</p>
- <p>Note: Try to refrain from using one-character language names like "c", "d",
- or "r". For example, Lua lexers for those languages are named "ansi_c", "dmd", and "rstats",
- respectively.</p>
+ <p>Note: Try to refrain from using one-character language names like &ldquo;c&rdquo;, &ldquo;d&rdquo;,
+ or &ldquo;r&rdquo;. For example, Lua lexers for those language names are named &ldquo;ansi_c&rdquo;,
+ &ldquo;dmd&rdquo;, and &ldquo;rstats&rdquo;, respectively.</p>
<p><a id="lexer.New.Lexer.Template"></a></p>
<h4>New Lexer Template</h4>
<p>There is a <em>lexlua/template.txt</em> file that contains a simple template for a
- new lexer. Feel free to use it, replacing the '?'s with the name of your
+ new lexer. Feel free to use it, replacing the &lsquo;?&rsquo;s with the name of your
lexer. Consider this snippet from the template:</p>
<pre><code>
@@ -630,23 +631,23 @@ operator 30
<p>The first 3 lines of code simply define often used convenience variables. The
fourth and last lines <a href="#lexer.new">define</a> and return the lexer object
Scintilla uses; they are very important and must be part of every lexer. The
- fifth line defines something called a "token", an essential building block of
+ fifth line defines something called a &ldquo;token&rdquo;, an essential building block of
lexers. You will learn about tokens shortly. The sixth line defines a lexer
grammar rule, which you will learn about later, as well as token styles. (Be
aware that it is common practice to combine these two lines for short rules.)
Note, however, the <code>local</code> prefix in front of variables, which is needed
- so-as not to affect Lua's global environment. All in all, this is a minimal,
+ so-as not to affect Lua&rsquo;s global environment. All in all, this is a minimal,
working lexer that you can build on.</p>
<p><a id="lexer.Tokens"></a></p>
<h4>Tokens</h4>
- <p>Take a moment to think about your programming language's structure. What kind
+ <p>Take a moment to think about your programming language&rsquo;s structure. What kind
of key elements does it have? In the template shown earlier, one predefined
element all languages have is whitespace. Your language probably also has
elements like comments, strings, and keywords. Lexers refer to these elements
- as "tokens". Tokens are the fundamental "building blocks" of lexers. Lexers
+ as &ldquo;tokens&rdquo;. Tokens are the fundamental &ldquo;building blocks&rdquo; of lexers. Lexers
break down source code into tokens for coloring, which results in the syntax
highlighting familiar to you. It is up to you how specific your lexer is when
it comes to tokens. Perhaps only distinguishing between keywords and
@@ -661,7 +662,7 @@ operator 30
<p>In a lexer, tokens consist of a token name and an LPeg pattern that matches a
sequence of characters recognized as an instance of that token. Create tokens
- using the <a href="#lexer.token"><code>lexer.token()</code></a> function. Let us examine the "whitespace" token
+ using the <a href="#lexer.token"><code>lexer.token()</code></a> function. Let us examine the &ldquo;whitespace&rdquo; token
defined in the template shown earlier:</p>
<pre><code>
@@ -690,10 +691,10 @@ operator 30
<a href="#lexer.punct"><code>lexer.punct</code></a>, <a href="#lexer.space"><code>lexer.space</code></a>, <a href="#lexer.newline"><code>lexer.newline</code></a>,
<a href="#lexer.nonnewline"><code>lexer.nonnewline</code></a>, <a href="#lexer.nonnewline_esc"><code>lexer.nonnewline_esc</code></a>, <a href="#lexer.dec_num"><code>lexer.dec_num</code></a>,
<a href="#lexer.hex_num"><code>lexer.hex_num</code></a>, <a href="#lexer.oct_num"><code>lexer.oct_num</code></a>, <a href="#lexer.integer"><code>lexer.integer</code></a>,
- <a href="#lexer.float"><code>lexer.float</code></a>, <a href="#lexer.number"><code>lexer.number</code></a>, and <a href="#lexer.word"><code>lexer.word</code></a>. You may use your own token names if
- none of the above fit your language, but an advantage to using predefined
- token names is that your lexer's tokens will inherit the universal syntax
- highlighting color theme used by your text editor.</p>
+ <a href="#lexer.float"><code>lexer.float</code></a>, <a href="#lexer.number"><code>lexer.number</code></a>, and <a href="#lexer.word"><code>lexer.word</code></a>. You may use your
+ own token names if none of the above fit your language, but an advantage to
+ using predefined token names is that your lexer&rsquo;s tokens will inherit the
+ universal syntax highlighting color theme used by your text editor.</p>
<p><a id="lexer.Example.Tokens"></a></p>
@@ -747,19 +748,19 @@ operator 30
local c_line_comment = token(lexer.COMMENT, lexer.to_eol('//', true))
</code></pre>
- <p>The comments above start with a '#' or "//" and go to the end of the line.
+ <p>The comments above start with a &lsquo;#&rsquo; or &ldquo;//&rdquo; and go to the end of the line.
The second comment recognizes the next line also as a comment if the current
- line ends with a '\' escape character.</p>
+ line ends with a &lsquo;\&rsquo; escape character.</p>
- <p>C-style "block" comments with a start and end delimiter are also easy to
+ <p>C-style &ldquo;block&rdquo; comments with a start and end delimiter are also easy to
express:</p>
<pre><code>
local c_comment = token(lexer.COMMENT, lexer.range('/*', '*/'))
</code></pre>
- <p>This comment starts with a "/*" sequence and contains anything up to and
- including an ending "*/" sequence. The ending "*/" is optional so the lexer
+ <p>This comment starts with a &ldquo;/*&rdquo; sequence and contains anything up to and
+ including an ending &ldquo;*/&rdquo; sequence. The ending &ldquo;*/&rdquo; is optional so the lexer
can recognize unfinished comments as comments and highlight them properly.</p>
<p><strong>Strings</strong></p>
@@ -775,7 +776,7 @@ operator 30
local string = token(lexer.STRING, dq_str + sq_str)
</code></pre>
- <p>In this case, the lexer treats '\' as an escape character in a string
+ <p>In this case, the lexer treats &lsquo;\&rsquo; as an escape character in a string
sequence.</p>
<p><strong>Numbers</strong></p>
@@ -805,7 +806,7 @@ operator 30
<p>Programming languages have grammars, which specify valid token structure. For
example, comments usually cannot appear within a string. Grammars consist of
rules, which are simply combinations of tokens. Recall from the lexer
- template the <a href="#lexer.add_rule"><code>lexer.add_rule()</code></a> call, which adds a rule to the lexer's
+ template the <a href="#lexer.add_rule"><code>lexer.add_rule()</code></a> call, which adds a rule to the lexer&rsquo;s
grammar:</p>
<pre><code>
@@ -816,7 +817,7 @@ operator 30
serve only to identify and distinguish between different rules. Rule order is
important: if text does not match the first rule added to the grammar, the
lexer tries to match the second rule added, and so on. Right now this lexer
- simply matches whitespace tokens under a rule named "whitespace".</p>
+ simply matches whitespace tokens under a rule named &ldquo;whitespace&rdquo;.</p>
<p>To illustrate the importance of rule order, here is an example of a
simplified Lua lexer:</p>
@@ -834,15 +835,15 @@ operator 30
<p>Note how identifiers come after keywords. In Lua, as with most programming
languages, the characters allowed in keywords and identifiers are in the same
- set (alphanumerics plus underscores). If the lexer added the "identifier"
- rule before the "keyword" rule, all keywords would match identifiers and thus
+ set (alphanumerics plus underscores). If the lexer added the &ldquo;identifier&rdquo;
+ rule before the &ldquo;keyword&rdquo; rule, all keywords would match identifiers and thus
incorrectly highlight as identifiers instead of keywords. The same idea
applies to function, constant, etc. tokens that you may want to distinguish
between: their rules should come before identifiers.</p>
- <p>So what about text that does not match any rules? For example in Lua, the '!'
+ <p>So what about text that does not match any rules? For example in Lua, the &lsquo;!&rsquo;
character is meaningless outside a string or comment. Normally the lexer
- skips over such text. If instead you want to highlight these "syntax errors",
+ skips over such text. If instead you want to highlight these &ldquo;syntax errors&rdquo;,
add an additional end rule:</p>
<pre><code>
@@ -887,126 +888,48 @@ operator 30
<p>The most basic form of syntax highlighting is assigning different colors to
different tokens. Instead of highlighting with just colors, Scintilla allows
- for more rich highlighting, or "styling", with different fonts, font sizes,
+ for more rich highlighting, or &ldquo;styling&rdquo;, 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 <code>lexer.WHITESPACE</code>, <code>lexer.COMMENT</code>,
- <code>lexer.STRING</code>, etc. with particular styles as part of a universal color
- theme. These predefined styles include <a href="#lexer.STYLE_CLASS"><code>lexer.STYLE_CLASS</code></a>,
- <a href="#lexer.STYLE_COMMENT"><code>lexer.STYLE_COMMENT</code></a>, <a href="#lexer.STYLE_CONSTANT"><code>lexer.STYLE_CONSTANT</code></a>,
- <a href="#lexer.STYLE_ERROR"><code>lexer.STYLE_ERROR</code></a>, <a href="#lexer.STYLE_EMBEDDED"><code>lexer.STYLE_EMBEDDED</code></a>,
- <a href="#lexer.STYLE_FUNCTION"><code>lexer.STYLE_FUNCTION</code></a>, <a href="#lexer.STYLE_IDENTIFIER"><code>lexer.STYLE_IDENTIFIER</code></a>,
- <a href="#lexer.STYLE_KEYWORD"><code>lexer.STYLE_KEYWORD</code></a>, <a href="#lexer.STYLE_LABEL"><code>lexer.STYLE_LABEL</code></a>, <a href="#lexer.STYLE_NUMBER"><code>lexer.STYLE_NUMBER</code></a>,
- <a href="#lexer.STYLE_OPERATOR"><code>lexer.STYLE_OPERATOR</code></a>, <a href="#lexer.STYLE_PREPROCESSOR"><code>lexer.STYLE_PREPROCESSOR</code></a>,
- <a href="#lexer.STYLE_REGEX"><code>lexer.STYLE_REGEX</code></a>, <a href="#lexer.STYLE_STRING"><code>lexer.STYLE_STRING</code></a>, <a href="#lexer.STYLE_TYPE"><code>lexer.STYLE_TYPE</code></a>,
- <a href="#lexer.STYLE_VARIABLE"><code>lexer.STYLE_VARIABLE</code></a>, and <a href="#lexer.STYLE_WHITESPACE"><code>lexer.STYLE_WHITESPACE</code></a>. 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:</p>
-
- <table class="standard">
- <thead>
- <tr>
- <th>Setting </th>
- <th> Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>font:<em>name</em> </td>
- <td> The name of the font the style uses.</td>
- </tr>
- <tr>
- <td>size:<em>int</em> </td>
- <td> The size of the font the style uses.</td>
- </tr>
- <tr>
- <td>[not]bold </td>
- <td> Whether or not the font face is bold.</td>
- </tr>
- <tr>
- <td>weight:<em>int</em> </td>
- <td> The weight or boldness of a font, between 1 and 999.</td>
- </tr>
- <tr>
- <td>[not]italics </td>
- <td> Whether or not the font face is italic.</td>
- </tr>
- <tr>
- <td>[not]underlined</td>
- <td> Whether or not the font face is underlined.</td>
- </tr>
- <tr>
- <td>fore:<em>color</em> </td>
- <td> The foreground color of the font face.</td>
- </tr>
- <tr>
- <td>back:<em>color</em> </td>
- <td> The background color of the font face.</td>
- </tr>
- <tr>
- <td>[not]eolfilled </td>
- <td> Does the background color extend to the end of the line?</td>
- </tr>
- <tr>
- <td>case:<em>char</em> </td>
- <td> The case of the font ('u': upper, 'l': lower, 'm': normal).</td>
- </tr>
- <tr>
- <td>[not]visible </td>
- <td> Whether or not the text is visible.</td>
- </tr>
- <tr>
- <td>[not]changeable</td>
- <td> Whether the text is changeable or read-only.</td>
- </tr>
- </tbody>
- </table>
-
-
- <p>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 <code>lexer.STYLE_STRING</code> style instead of defining a new one.</p>
+ The unit of this rich highlighting is called a &ldquo;style&rdquo;. Styles are simply Lua
+ tables of properties. By default, lexers associate predefined token names
+ like <code>lexer.WHITESPACE</code>, <code>lexer.COMMENT</code>, <code>lexer.STRING</code>, etc. with
+ particular styles as part of a universal color theme. These predefined styles
+ are contained in <a href="#lexer.styles"><code>lexer.styles</code></a>, and you may define your own styles. See
+ that table&rsquo;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&rsquo;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 &ldquo;longstring&rdquo;
+ tokens use the existing <code>lexer.styles.string</code> style instead of defining a new
+ one.</p>
<p><a id="lexer.Example.Styles"></a></p>
<h5>Example Styles</h5>
<p>Defining styles is pretty straightforward. An empty style that inherits the
- default theme settings is simply an empty string:</p>
+ default theme settings is simply an empty table:</p>
<pre><code>
- local style_nothing = ''
+ local style_nothing = {}
</code></pre>
<p>A similar style but with a bold font face looks like this:</p>
<pre><code>
- local style_bold = 'bold'
- </code></pre>
-
- <p>If you want the same style, but also with an italic font face, define the new
- style in terms of the old one:</p>
-
- <pre><code>
- local style_bold_italic = style_bold..',italics'
+ local style_bold = {bold = true}
</code></pre>
- <p>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
- <code>lexer.STYLE_VARIABLE</code>, it would probably look like:</p>
+ <p>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 &ldquo;static variable&rdquo; token whose style you wanted to base off of
+ <code>lexer.styles.variable</code>, it would probably look like:</p>
<pre><code>
- local style_static_var = lexer.STYLE_VARIABLE..',italics'
+ local style_static_var = lexer.styles.variable .. {italics = true}
</code></pre>
<p>The color theme files in the <em>lexlua/themes/</em> folder give more examples of
@@ -1036,24 +959,22 @@ operator 30
<p>Assigning a style to this token looks like:</p>
<pre><code>
- lex:add_style('custom_whitespace', lexer.STYLE_WHITESPACE)
+ lex:add_style('custom_whitespace', lexer.styles.whitespace)
</code></pre>
<p>Do not confuse token names with rule names. They are completely different
- entities. In the example above, the lexer associates the "custom_whitespace"
+ entities. In the example above, the lexer associates the &ldquo;custom_whitespace&rdquo;
token with the existing style for <code>lexer.WHITESPACE</code> tokens. If instead you
prefer to color the background of whitespace a shade of grey, it might look
like:</p>
<pre><code>
- 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})
</code></pre>
- <p>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.</p>
+ <p>Remember to refrain from assigning specific colors in styles, but in this
+ case, all user color themes probably define <code>colors.grey</code>.</p>
<p><a id="lexer.Line.Lexers"></a></p>
@@ -1062,8 +983,8 @@ operator 30
<p>By default, lexers match the arbitrary chunks of text passed to them by
Scintilla. These chunks may be a full document, only the visible part of a
document, or even just portions of lines. Some lexers need to match whole
- lines. For example, a lexer for the output of a file "diff" needs to know if
- the line started with a '+' or '-' and then style the entire line
+ lines. For example, a lexer for the output of a file &ldquo;diff&rdquo; needs to know if
+ the line started with a &lsquo;+&rsquo; or &lsquo;-&rsquo; and then style the entire line
accordingly. To indicate that your lexer matches by line, create the lexer
with an extra parameter:</p>
@@ -1079,12 +1000,12 @@ operator 30
<h4>Embedded Lexers</h4>
<p>Lexers embed within one another very easily, requiring minimal effort. In the
- following sections, the lexer being embedded is called the "child" lexer and
- the lexer a child is being embedded in is called the "parent". For example,
+ following sections, the lexer being embedded is called the &ldquo;child&rdquo; lexer and
+ the lexer a child is being embedded in is called the &ldquo;parent&rdquo;. For example,
consider an HTML lexer and a CSS lexer. Either lexer stands alone for styling
their respective HTML and CSS files. However, CSS can be embedded inside
- HTML. In this specific case, the CSS lexer is the "child" lexer with the HTML
- lexer being the "parent". Now consider an HTML lexer and a PHP lexer. This
+ HTML. In this specific case, the CSS lexer is the &ldquo;child&rdquo; lexer with the HTML
+ lexer being the &ldquo;parent&rdquo;. Now consider an HTML lexer and a PHP lexer. This
sounds a lot like the case with CSS, but there is a subtle difference: PHP
<em>embeds itself into</em> HTML while CSS is <em>embedded in</em> HTML. This fundamental
difference results in two types of embedded lexers: a parent lexer that
@@ -1105,10 +1026,10 @@ operator 30
<p>The next part of the embedding process is telling the parent lexer when to
switch over to the child lexer and when to switch back. The lexer refers to
- these indications as the "start rule" and "end rule", respectively, and are
+ these indications as the &ldquo;start rule&rdquo; and &ldquo;end rule&rdquo;, respectively, and are
just LPeg patterns. Continuing with the HTML/CSS example, the transition from
- HTML to CSS is when the lexer encounters a "style" tag with a "type"
- attribute whose value is "text/css":</p>
+ HTML to CSS is when the lexer encounters a &ldquo;style&rdquo; tag with a &ldquo;type&rdquo;
+ attribute whose value is &ldquo;text/css&rdquo;:</p>
<pre><code>
local css_tag = P('&lt;style') * P(function(input, index)
@@ -1118,12 +1039,12 @@ operator 30
end)
</code></pre>
- <p>This pattern looks for the beginning of a "style" tag and searches its
- attribute list for the text "<code>type="text/css"</code>". (In this simplified example,
- the Lua pattern does not consider whitespace between the '=' nor does it
+ <p>This pattern looks for the beginning of a &ldquo;style&rdquo; tag and searches its
+ attribute list for the text &ldquo;<code>type="text/css"</code>&rdquo;. (In this simplified example,
+ the Lua pattern does not consider whitespace between the &lsquo;=&rsquo; nor does it
consider that using single quotes is valid.) If there is a match, the
functional pattern returns a value instead of <code>nil</code>. In this case, the value
- returned does not matter because we ultimately want to style the "style" tag
+ returned does not matter because we ultimately want to style the &ldquo;style&rdquo; tag
as an HTML tag, so the actual start rule looks like this:</p>
<pre><code>
@@ -1132,14 +1053,14 @@ operator 30
<p>Now that the parent knows when to switch to the child, it needs to know when
to switch back. In the case of HTML/CSS, the switch back occurs when the
- lexer encounters an ending "style" tag, though the lexer should still style
+ lexer encounters an ending &ldquo;style&rdquo; tag, though the lexer should still style
the tag as an HTML tag:</p>
<pre><code>
local css_end_rule = #P('&lt;/style&gt;') * tag
</code></pre>
- <p>Once the parent loads the child lexer and defines the child's start and end
+ <p>Once the parent loads the child lexer and defines the child&rsquo;s start and end
rules, it embeds the child with the <a href="#lexer.embed"><code>lexer.embed()</code></a> function:</p>
<pre><code>
@@ -1160,7 +1081,7 @@ operator 30
local html = lexer.load('html')
local php_start_rule = token('php_tag', '&lt;?php ')
local php_end_rule = token('php_tag', '?&gt;')
- 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)
</code></pre>
@@ -1172,7 +1093,7 @@ operator 30
text in a document. However, there may be rare cases where a lexer does need
to keep track of some sort of persistent state. Rather than using <code>lpeg.P</code>
function patterns that set state variables, it is recommended to make use of
- Scintilla's built-in, per-line state integers via <a href="#lexer.line_state"><code>lexer.line_state</code></a>. It
+ Scintilla&rsquo;s built-in, per-line state integers via <a href="#lexer.line_state"><code>lexer.line_state</code></a>. It
was designed to accommodate up to 32 bit flags for tracking state.
<a href="#lexer.line_from_position"><code>lexer.line_from_position()</code></a> will return the line for any position given
to an <code>lpeg.P</code> function pattern. (Any positions derived from that position
@@ -1186,15 +1107,16 @@ operator 30
<p>When reading source code, it is occasionally helpful to temporarily hide
blocks of code like functions, classes, comments, etc. This is the concept of
- "folding". In many Scintilla-based editors, such as Textadept, little indicators
- in the editor margins appear next to code that can be folded at places called
- "fold points". When the user clicks an indicator, the editor hides the code
- associated with the indicator until the user clicks the indicator again. The
- lexer specifies these fold points and what code exactly to fold.</p>
+ &ldquo;folding&rdquo;. In many Scintilla-based editors, such as Textadept, little
+ indicators in the editor margins appear next to code that can be folded at
+ places called &ldquo;fold points&rdquo;. When the user clicks an indicator, the editor
+ hides the code associated with the indicator until the user clicks the
+ indicator again. The lexer specifies these fold points and what code exactly
+ to fold.</p>
<p>The fold points for most languages occur on keywords or character sequences.
- Examples of fold keywords are "if" and "end" in Lua and examples of fold
- character sequences are '{', '}', "/*", and "*/" in C for code block and
+ Examples of fold keywords are &ldquo;if&rdquo; and &ldquo;end&rdquo; in Lua and examples of fold
+ character sequences are &lsquo;{&rsquo;, &lsquo;}&rsquo;, &ldquo;/*&rdquo;, and &ldquo;*/&rdquo; in C for code block and
comment delimiters, respectively. However, these fold points cannot occur
just anywhere. For example, lexers should not recognize fold keywords that
appear within strings or comments. The <a href="#lexer.add_fold_point"><code>lexer.add_fold_point()</code></a> function
@@ -1206,9 +1128,9 @@ operator 30
lex:add_fold_point(lexer.COMMENT, '/*', '*/')
</code></pre>
- <p>The first assignment states that any '{' or '}' that the lexer recognized as
+ <p>The first assignment states that any &lsquo;{&rsquo; or &lsquo;}&rsquo; that the lexer recognized as
an <code>lexer.OPERATOR</code> token is a fold point. Likewise, the second assignment
- states that any "/*" or "*/" that the lexer recognizes as part of a
+ states that any &ldquo;/*&rdquo; or &ldquo;*/&rdquo; that the lexer recognizes as part of a
<code>lexer.COMMENT</code> token is a fold point. The lexer does not consider any
occurrences of these characters outside their defined tokens (such as in a
string) as fold points. How do you specify fold keywords? Here is an example
@@ -1244,11 +1166,11 @@ operator 30
lex:add_fold_point('strange_token', '|', fold_strange_token)
</code></pre>
- <p>Any time the lexer encounters a '|' that is a "strange_token", it calls the
- <code>fold_strange_token</code> function to determine if '|' is a fold point. The lexer
+ <p>Any time the lexer encounters a &lsquo;|&rsquo; that is a &ldquo;strange_token&rdquo;, it calls the
+ <code>fold_strange_token</code> function to determine if &lsquo;|&rsquo; is a fold point. The lexer
calls these functions with the following arguments: the text to identify fold
points in, the beginning position of the current line in the text to fold,
- the current line's text, the position in the current line the fold point text
+ the current line&rsquo;s text, the position in the current line the fold point text
starts at, and the fold point text itself.</p>
<p><a id="lexer.Fold.by.Indentation"></a></p>
@@ -1312,12 +1234,12 @@ operator 30
return M
</code></pre>
- <p>While such legacy lexers will be handled just fine without any
- changes, it is recommended that you migrate yours. The migration process is
- fairly straightforward:</p>
+ <p>While such legacy lexers will be handled just fine without any changes, it is
+ recommended that you migrate yours. The migration process is fairly
+ straightforward:</p>
<ol>
- <li>Replace all instances of <code>l</code> with <code>lexer</code>, as it's better practice and
+ <li>Replace all instances of <code>l</code> with <code>lexer</code>, as it&rsquo;s better practice and
results in less confusion.</li>
<li>Replace <code>local M = {_NAME = '?'}</code> with <code>local lex = lexer.new('?')</code>, where
<code>?</code> is the name of your legacy lexer. At the end of the lexer, change
@@ -1397,7 +1319,7 @@ operator 30
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('#')))
@@ -1419,14 +1341,14 @@ operator 30
<p>There might be some slight overhead when initializing a lexer, but loading a
file from disk into Scintilla is usually more expensive. On modern computer
- systems, I see no difference in speed between Lua lexers and Scintilla's C++
+ systems, I see no difference in speed between Lua lexers and Scintilla&rsquo;s C++
ones. Optimize lexers for speed by re-arranging <code>lexer.add_rule()</code> calls so
that the most common rules match first. Do keep in mind that order matters
for similar rules.</p>
<p>In some cases, folding may be far more expensive than lexing, particularly
in lexers with a lot of potential fold points. If your lexer is exhibiting
- signs of slowness, try disabling folding your text editor first. If that
+ signs of slowness, try disabling folding in your text editor first. If that
speeds things up, you can try reducing the number of fold points you added,
overriding <code>lexer.fold()</code> with your own implementation, or simply eliminating
folding support from your lexer.</p>
@@ -1436,7 +1358,7 @@ operator 30
<h4>Limitations</h4>
<p>Embedded preprocessor languages like PHP cannot completely embed in their
- parent languages in that the parent's tokens do not support start and end
+ parent languages in that the parent&rsquo;s tokens do not support start and end
rules. This mostly goes unnoticed, but code like</p>
<pre><code>
@@ -1575,158 +1497,6 @@ operator 30
<p>The token name for string tokens.</p>
- <p><a id="lexer.STYLE_BRACEBAD"></a></p>
-
- <h3><code>lexer.STYLE_BRACEBAD</code> (string)</h3>
-
- <p>The style used for unmatched brace characters.</p>
-
- <p><a id="lexer.STYLE_BRACELIGHT"></a></p>
-
- <h3><code>lexer.STYLE_BRACELIGHT</code> (string)</h3>
-
- <p>The style used for highlighted brace characters.</p>
-
- <p><a id="lexer.STYLE_CALLTIP"></a></p>
-
- <h3><code>lexer.STYLE_CALLTIP</code> (string)</h3>
-
- <p>The style used by call tips if <a href="#buffer.call_tip_use_style"><code>buffer.call_tip_use_style</code></a> is set.
- Only the font name, size, and color attributes are used.</p>
-
- <p><a id="lexer.STYLE_CLASS"></a></p>
-
- <h3><code>lexer.STYLE_CLASS</code> (string)</h3>
-
- <p>The style typically used for class definitions.</p>
-
- <p><a id="lexer.STYLE_COMMENT"></a></p>
-
- <h3><code>lexer.STYLE_COMMENT</code> (string)</h3>
-
- <p>The style typically used for code comments.</p>
-
- <p><a id="lexer.STYLE_CONSTANT"></a></p>
-
- <h3><code>lexer.STYLE_CONSTANT</code> (string)</h3>
-
- <p>The style typically used for constants.</p>
-
- <p><a id="lexer.STYLE_CONTROLCHAR"></a></p>
-
- <h3><code>lexer.STYLE_CONTROLCHAR</code> (string)</h3>
-
- <p>The style used for control characters.
- Color attributes are ignored.</p>
-
- <p><a id="lexer.STYLE_DEFAULT"></a></p>
-
- <h3><code>lexer.STYLE_DEFAULT</code> (string)</h3>
-
- <p>The style all styles are based off of.</p>
-
- <p><a id="lexer.STYLE_EMBEDDED"></a></p>
-
- <h3><code>lexer.STYLE_EMBEDDED</code> (string)</h3>
-
- <p>The style typically used for embedded code.</p>
-
- <p><a id="lexer.STYLE_ERROR"></a></p>
-
- <h3><code>lexer.STYLE_ERROR</code> (string)</h3>
-
- <p>The style typically used for erroneous syntax.</p>
-
- <p><a id="lexer.STYLE_FOLDDISPLAYTEXT"></a></p>
-
- <h3><code>lexer.STYLE_FOLDDISPLAYTEXT</code> (string)</h3>
-
- <p>The style used for fold display text.</p>
-
- <p><a id="lexer.STYLE_FUNCTION"></a></p>
-
- <h3><code>lexer.STYLE_FUNCTION</code> (string)</h3>
-
- <p>The style typically used for function definitions.</p>
-
- <p><a id="lexer.STYLE_IDENTIFIER"></a></p>
-
- <h3><code>lexer.STYLE_IDENTIFIER</code> (string)</h3>
-
- <p>The style typically used for identifier words.</p>
-
- <p><a id="lexer.STYLE_INDENTGUIDE"></a></p>
-
- <h3><code>lexer.STYLE_INDENTGUIDE</code> (string)</h3>
-
- <p>The style used for indentation guides.</p>
-
- <p><a id="lexer.STYLE_KEYWORD"></a></p>
-
- <h3><code>lexer.STYLE_KEYWORD</code> (string)</h3>
-
- <p>The style typically used for language keywords.</p>
-
- <p><a id="lexer.STYLE_LABEL"></a></p>
-
- <h3><code>lexer.STYLE_LABEL</code> (string)</h3>
-
- <p>The style typically used for labels.</p>
-
- <p><a id="lexer.STYLE_LINENUMBER"></a></p>
-
- <h3><code>lexer.STYLE_LINENUMBER</code> (string)</h3>
-
- <p>The style used for all margins except fold margins.</p>
-
- <p><a id="lexer.STYLE_NUMBER"></a></p>
-
- <h3><code>lexer.STYLE_NUMBER</code> (string)</h3>
-
- <p>The style typically used for numbers.</p>
-
- <p><a id="lexer.STYLE_OPERATOR"></a></p>
-
- <h3><code>lexer.STYLE_OPERATOR</code> (string)</h3>
-
- <p>The style typically used for operators.</p>
-
- <p><a id="lexer.STYLE_PREPROCESSOR"></a></p>
-
- <h3><code>lexer.STYLE_PREPROCESSOR</code> (string)</h3>
-
- <p>The style typically used for preprocessor statements.</p>
-
- <p><a id="lexer.STYLE_REGEX"></a></p>
-
- <h3><code>lexer.STYLE_REGEX</code> (string)</h3>
-
- <p>The style typically used for regular expression strings.</p>
-
- <p><a id="lexer.STYLE_STRING"></a></p>
-
- <h3><code>lexer.STYLE_STRING</code> (string)</h3>
-
- <p>The style typically used for strings.</p>
-
- <p><a id="lexer.STYLE_TYPE"></a></p>
-
- <h3><code>lexer.STYLE_TYPE</code> (string)</h3>
-
- <p>The style typically used for static types.</p>
-
- <p><a id="lexer.STYLE_VARIABLE"></a></p>
-
- <h3><code>lexer.STYLE_VARIABLE</code> (string)</h3>
-
- <p>The style typically used for variables.</p>
-
- <p><a id="lexer.STYLE_WHITESPACE"></a></p>
-
- <h3><code>lexer.STYLE_WHITESPACE</code> (string)</h3>
-
- <p>The style typically used for whitespace.</p>
-
<p><a id="lexer.TYPE"></a></p>
<h3><code>lexer.TYPE</code> (string)</h3>
@@ -1749,14 +1519,14 @@ operator 30
<h3><code>lexer.alnum</code> (pattern)</h3>
- <p>A pattern that matches any alphanumeric character ('A'-'Z', 'a'-'z',
- '0'-'9').</p>
+ <p>A pattern that matches any alphanumeric character (&lsquo;A&rsquo;-&lsquo;Z&rsquo;, &lsquo;a&rsquo;-&lsquo;z&rsquo;,
+ &lsquo;0&rsquo;-&lsquo;9&rsquo;).</p>
<p><a id="lexer.alpha"></a></p>
<h3><code>lexer.alpha</code> (pattern)</h3>
- <p>A pattern that matches any alphabetic character ('A'-'Z', 'a'-'z').</p>
+ <p>A pattern that matches any alphabetic character (&lsquo;A&rsquo;-&lsquo;Z&rsquo;, &lsquo;a&rsquo;-&lsquo;z&rsquo;).</p>
<p><a id="lexer.any"></a></p>
@@ -1786,7 +1556,7 @@ operator 30
<h3><code>lexer.digit</code> (pattern)</h3>
- <p>A pattern that matches any digit ('0'-'9').</p>
+ <p>A pattern that matches any digit (&lsquo;0&rsquo;-&lsquo;9&rsquo;).</p>
<p><a id="lexer.extend"></a></p>
@@ -1822,7 +1592,7 @@ operator 30
<h3><code>lexer.graph</code> (pattern)</h3>
- <p>A pattern that matches any graphical character ('!' to '~').</p>
+ <p>A pattern that matches any graphical character (&lsquo;!&rsquo; to &lsquo;~&rsquo;).</p>
<p><a id="lexer.hex_num"></a></p>
@@ -1854,13 +1624,13 @@ operator 30
<h3><code>lexer.lower</code> (pattern)</h3>
- <p>A pattern that matches any lower case character ('a'-'z').</p>
+ <p>A pattern that matches any lower case character (&lsquo;a&rsquo;-&lsquo;z&rsquo;).</p>
<p><a id="lexer.newline"></a></p>
<h3><code>lexer.newline</code> (pattern)</h3>
- <p>A pattern that matches any set of end of line characters.</p>
+ <p>A pattern that matches a sequence of end of line characters.</p>
<p><a id="lexer.nonnewline"></a></p>
@@ -1873,14 +1643,14 @@ operator 30
<h3><code>lexer.nonnewline_esc</code> (pattern)</h3>
<p>A pattern that matches any single, non-newline character or any set of end
- of line characters escaped with '\'.</p>
+ of line characters escaped with &lsquo;\&rsquo;.</p>
<p><a id="lexer.number"></a></p>
<h3><code>lexer.number</code> (pattern)</h3>
<p>A pattern that matches a typical number, either a floating point, decimal,
- hexadecimal, or octal number.</p>
+ hexadecimal, or octal number.</p>
<p><a id="lexer.oct_num"></a></p>
@@ -1888,19 +1658,11 @@ operator 30
<p>A pattern that matches an octal number.</p>
- <p><a id="lexer.path"></a></p>
-
- <h3><code>lexer.path</code> (string)</h3>
-
- <p>The path used to search for a lexer to load.
- Identical in format to Lua's <code>package.path</code> string.
- The default value is <code>package.path</code>.</p>
-
<p><a id="lexer.print"></a></p>
<h3><code>lexer.print</code> (pattern)</h3>
- <p>A pattern that matches any printable character (' ' to '~').</p>
+ <p>A pattern that matches any printable character (&lsquo; &rsquo; to &lsquo;~&rsquo;).</p>
<p><a id="lexer.property"></a></p>
@@ -1926,15 +1688,15 @@ operator 30
<h3><code>lexer.punct</code> (pattern)</h3>
- <p>A pattern that matches any punctuation character ('!' to '/', ':' to '@',
- '[' to ''', '{' to '~').</p>
+ <p>A pattern that matches any punctuation character (&lsquo;!&rsquo; to &lsquo;/&rsquo;, &lsquo;:&rsquo; to &lsquo;@&rsquo;,
+ &lsquo;[&rsquo; to &lsquo;&rsquo;&lsquo;, &rsquo;{&lsquo; to &rsquo;~&lsquo;).</p>
<p><a id="lexer.space"></a></p>
<h3><code>lexer.space</code> (pattern)</h3>
- <p>A pattern that matches any whitespace character ('\t', '\v', '\f', '\n',
- '\r', space).</p>
+ <p>A pattern that matches any whitespace character (&lsquo;\t&rsquo;, &lsquo;\v&rsquo;, &lsquo;\f&rsquo;, &lsquo;\n&rsquo;,
+ &lsquo;\r&rsquo;, space).</p>
<p><a id="lexer.style_at"></a></p>
@@ -1946,7 +1708,7 @@ operator 30
<h3><code>lexer.upper</code> (pattern)</h3>
- <p>A pattern that matches any upper case character ('A'-'Z').</p>
+ <p>A pattern that matches any upper case character (&lsquo;A&rsquo;-&lsquo;Z&rsquo;).</p>
<p><a id="lexer.word"></a></p>
@@ -1959,13 +1721,13 @@ operator 30
<h3><code>lexer.xdigit</code> (pattern)</h3>
- <p>A pattern that matches any hexadecimal digit ('0'-'9', 'A'-'F', 'a'-'f').</p>
+ <p>A pattern that matches any hexadecimal digit (&lsquo;0&rsquo;-&lsquo;9&rsquo;, &lsquo;A&rsquo;-&lsquo;F&rsquo;, &lsquo;a&rsquo;-&lsquo;f&rsquo;).</p>
<h2>Lua <code>lexer</code> module API functions</h2>
<p><a id="lexer.add_fold_point"></a></p>
- <h3><code>lexer.add_fold_point</code> (lexer, token_name, start_symbol, end_symbol)</h3>
+ <h3><code>lexer.add_fold_point</code>(lexer, token_name, start_symbol, end_symbol)</h3>
<p>Adds to lexer <em>lexer</em> a fold point whose beginning and end tokens are string
<em>token_name</em> tokens with string content <em>start_symbol</em> and <em>end_symbol</em>,
@@ -1986,7 +1748,7 @@ operator 30
</ul>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The lexer to add a fold point to.</li>
@@ -2011,12 +1773,12 @@ operator 30
<p><a id="lexer.add_rule"></a></p>
- <h3><code>lexer.add_rule</code> (lexer, id, rule)</h3>
+ <h3><code>lexer.add_rule</code>(lexer, id, rule)</h3>
<p>Adds pattern <em>rule</em> identified by string <em>id</em> to the ordered list of rules
for lexer <em>lexer</em>.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The lexer to add the given rule to.</li>
@@ -2037,50 +1799,32 @@ operator 30
<h3><code>lexer.add_style</code> (lexer, token_name, style)</h3>
- <p>Associates string <em>token_name</em> in lexer <em>lexer</em> with Scintilla style string
- <em>style</em>.
- Style strings are comma-separated property settings. Available property
- settings are:</p>
+ <p>Associates string <em>token_name</em> in lexer <em>lexer</em> with style table <em>style</em>.</p>
+
+ <p>Parameters:</p>
<ul>
- <li><code>font:name</code>: Font name.</li>
- <li><code>size:int</code>: Font size.</li>
- <li><code>bold</code> or <code>notbold</code>: Whether or not the font face is bold.</li>
- <li><code>weight:int</code>: Font weight (between 1 and 999).</li>
- <li><code>italics</code> or <code>notitalics</code>: Whether or not the font face is italic.</li>
- <li><code>underlined</code> or <code>notunderlined</code>: Whether or not the font face is
- underlined.</li>
- <li><code>fore:color</code>: Font face foreground color in "#RRGGBB" or 0xBBGGRR format.</li>
- <li><code>back:color</code>: Font face background color in "#RRGGBB" or 0xBBGGRR format.</li>
- <li><code>eolfilled</code> or <code>noteolfilled</code>: Whether or not the background color
- extends to the end of the line.</li>
- <li><code>case:char</code>: Font case ('u' for uppercase, 'l' for lowercase, and 'm' for
- mixed case).</li>
- <li><code>visible</code> or <code>notvisible</code>: Whether or not the text is visible.</li>
- <li><code>changeable</code> or <code>notchangeable</code>: Whether or not the text is changeable or
- read-only.</li>
+ <li><code>lexer</code>: The lexer to add a style to.</li>
+ <li><code>token_name</code>: The name of the token to associated with the style.</li>
+ <li><code>style</code>: A style table.</li>
</ul>
- <p>Property settings may also contain "$(property.name)" expansions for
- properties defined in Scintilla, theme files, etc.</p>
-
- <p>Fields:</p>
+ <p>Usage:</p>
<ul>
- <li><code>lexer</code>: The lexer to add a style to.</li>
- <li><code>token_name</code>: The name of the token to associated with the style.</li>
- <li><code>style</code>: A style string for Scintilla.</li>
+ <li><code>lex:add_style('longstring', lexer.styles.string)</code></li>
+ <li><code>lex:add_style('deprecated_func', lexer.styles['function'] ..
+ {italics = true}</code></li>
+ <li><code>lex:add_style('visible_ws', lexer.styles.whitespace ..
+ {back = lexer.colors.grey}</code></li>
</ul>
- <p>Usage:</p>
+ <p>See also:</p>
<ul>
- <li><code>lex:add_style('longstring', lexer.STYLE_STRING)</code></li>
- <li><code>lex:add_style('deprecated_function', lexer.STYLE_FUNCTION..',italics')</code></li>
- <li><code>lex:add_style('visible_ws',
- lexer.STYLE_WHITESPACE..',back:$(color.grey)')</code></li>
+ <li><a href="#lexer.styles"><code>lexer.styles</code></a></li>
</ul>
@@ -2092,7 +1836,7 @@ operator 30
<em>start_rule</em> and <em>end_rule</em>, which signal the beginning and end of the
embedded lexer, respectively.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The parent lexer.</li>
@@ -2120,7 +1864,7 @@ operator 30
<em>text</em> starts at position <em>start_pos</em> on line number <em>start_line</em> with a
beginning fold level of <em>start_level</em> in the buffer.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The lexer to fold text with.</li>
@@ -2146,7 +1890,7 @@ operator 30
<p>Returns a fold function (to be passed to <code>lexer.add_fold_point()</code>) that folds
consecutive line comments that start with string <em>prefix</em>.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>prefix</code>: The prefix string defining a line comment.</li>
@@ -2169,7 +1913,7 @@ operator 30
<p>Returns the rule identified by string <em>id</em>.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The lexer to fetch a rule from.</li>
@@ -2191,7 +1935,7 @@ operator 30
<p>Creates and returns a pattern that verifies that string set <em>s</em> contains the
first non-whitespace character behind the current match position.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>s</code>: String character set like one passed to <code>lpeg.S()</code>.</li>
@@ -2221,7 +1965,7 @@ operator 30
<em>init_style</em>) using lexer <em>lexer</em>, returning a table of token names and
positions.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The lexer to lex text with.</li>
@@ -2242,10 +1986,10 @@ operator 30
<h3><code>lexer.line_from_position</code> (pos)</h3>
- <p>Returns the line number of the line that contains position <em>pos</em>, which
- starts from 1.</p>
+ <p>Returns the line number (starting from 1) of the line that contains position
+ <em>pos</em>, which starts from 1.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>pos</code>: The position to get the line number of.</li>
@@ -2269,7 +2013,7 @@ operator 30
calls this function in order to load a lexer when using this module as a Lua
library.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>name</code>: The name of the lexing language.</li>
@@ -2296,7 +2040,7 @@ operator 30
<p>Replaces in lexer <em>lexer</em> the existing rule identified by string <em>id</em> with
pattern <em>rule</em>.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>lexer</code>: The lexer to modify.</li>
@@ -2311,10 +2055,10 @@ operator 30
<p>Creates a returns a new lexer with the given name.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
- <li><code>name</code>: The lexer's name.</li>
+ <li><code>name</code>: The lexer&rsquo;s name.</li>
<li><code>opts</code>: Table of lexer options. Options currently supported:
<ul>
@@ -2366,8 +2110,8 @@ operator 30
on a single line.</li>
<li><em><code>escapes</code></em>: Optional flag indicating whether or not the range end may
be escaped by a &lsquo;\&rsquo; character.
- The default value is <code>false</code> unless <em>s</em> and <em>e</em> are identical, single-character strings.
- In that case, the default value is <code>true</code>.</li>
+ The default value is <code>false</code> unless <em>s</em> and <em>e</em> are identical,
+ single-character strings. In that case, the default value is <code>true</code>.</li>
<li><em><code>balanced</code></em>: Optional flag indicating whether or not to match a balanced
range, like the &ldquo;%b&rdquo; Lua pattern. This flag only applies if <em>s</em> and <em>e</em> are
different.</li>
@@ -2398,7 +2142,7 @@ operator 30
<p>Creates and returns a pattern that matches pattern <em>patt</em> only at the
beginning of a line.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>patt</code>: The LPeg pattern to match on the beginning of a line.</li>
@@ -2462,7 +2206,7 @@ operator 30
If <em>name</em> is not a predefined token name, its style must be defined via
<code>lexer.add_style()</code>.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>name</code>: The name of token. If this name is not a predefined token name,
@@ -2498,7 +2242,7 @@ operator 30
If <em>words</em> is a multi-line string, it may contain Lua line comments (<code>--</code>)
that will ultimately be ignored.</p>
- <p>Fields:</p>
+ <p>Parameters:</p>
<ul>
<li><code>words</code>: A string list of words separated by spaces.</li>
@@ -2523,6 +2267,63 @@ operator 30
<li>pattern</li>
</ul>
+
+ <h2>Lua <code>lexer</code> module API tables</h2>
+
+ <p><a id="lexer.colors"></a></p>
+
+ <h3><code>lexer.colors</code></h3>
+
+ <p>Map of color names strings to color values in <code>0xBBGGRR</code> or <code>"#RRGGBB"</code>
+ format.</p>
+
+ <p><a id="lexer.styles"></a></p>
+
+ <h3><code>lexer.styles</code></h3>
+
+ <p>Map of style names to style definition tables.</p>
+
+ <p>Style names consist of the following default names as well as the token names
+ defined by lexers.</p>
+
+ <ul>
+ <li><code>default</code>: The default style all others are based on.</li>
+ <li><code>line_number</code>: The line number margin style.</li>
+ <li><code>control_char</code>: The style of control character blocks.</li>
+ <li><code>indent_guide</code>: The style of indentation guides.</li>
+ <li><code>call_tip</code>: The style of call tip text. Only the <code>font</code>, <code>size</code>, <code>fore</code>,
+ and <code>back</code> style definition fields are supported.</li>
+ <li><code>fold_display_text</code>: The style of text displayed next to folded lines.</li>
+ <li><code>class</code>, <code>comment</code>, <code>constant</code>, <code>embedded</code>, <code>error</code>, <code>function</code>,
+ <code>identifier</code>, <code>keyword</code>, <code>label</code>, <code>number</code>, <code>operator</code>, <code>preprocessor</code>,
+ <code>regex</code>, <code>string</code>, <code>type</code>, <code>variable</code>, <code>whitespace</code>: Some token names used
+ by lexers. Some lexers may define more token names, so this list is not
+ exhaustive.</li>
+ </ul>
+
+
+ <p>Style definition tables may contain the following fields:</p>
+
+ <ul>
+ <li><code>font</code>: String font name.</li>
+ <li><code>size</code>: Integer font size.</li>
+ <li><code>bold</code>: Whether or not the font face is bold. The default value is <code>false</code>.</li>
+ <li><code>weight</code>: Integer weight or boldness of a font, between 1 and 999.</li>
+ <li><code>italics</code>: Whether or not the font face is italic. The default value is
+ <code>false</code>.</li>
+ <li><code>underlined</code>: Whether or not the font face is underlined. The default value
+ is <code>false</code>.</li>
+ <li><code>fore</code>: Font face foreground color in <code>0xBBGGRR</code> or <code>"#RRGGBB"</code> format.</li>
+ <li><code>back</code>: Font face background color in <code>0xBBGGRR</code> or <code>"#RRGGBB"</code> format.</li>
+ <li><code>eolfilled</code>: Whether or not the background color extends to the end of the
+ line. The default value is <code>false</code>.</li>
+ <li><code>case</code>: Font case, <code>'u'</code> for upper, <code>'l'</code> for lower, <code>'m'</code> for normal,
+ mixed case, and <code>'c'</code> for camel case. The default value is <code>'m'</code>.</li>
+ <li><code>visible</code>: Whether or not the text is visible. The default value is <code>true</code>.</li>
+ <li><code>changeable</code>: Whether the text is changeable instead of read-only. The
+ default value is <code>true</code>.</li>
+ </ul>
+
<h2 id="LexerList">Supported Languages</h2>
<p>Scintilla has Lua lexers for all of the languages below. Languages
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
diff --git a/test/test_lexlua.lua b/test/test_lexlua.lua
index cd27f4bed..602f480c7 100644
--- a/test/test_lexlua.lua
+++ b/test/test_lexlua.lua
@@ -30,8 +30,8 @@ function assert_default_styles(lex)
assert(lex._TOKENSTYLES[style] == i, 'default styles out of order')
end
local predefined_styles = {
- '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 i = 1, #predefined_styles do
local style = predefined_styles[i]
@@ -48,6 +48,7 @@ end
function assert_style(lex, style_name, style)
assert(lex._TOKENSTYLES[style_name],
string.format("style '%s' does not exist", style_name))
+ style = tostring(style)
assert(lex._EXTRASTYLES[style_name] == style,
string.format("'%s' ~= '%s'", lex._EXTRASTYLES[style_name], style))
end
@@ -276,6 +277,17 @@ function test_add_style()
assert_lex(lex, code, tokens)
end
+-- Tests adding different kinds of lexer styles.
+function test_add_styles()
+ local lex = lexer.new('test')
+ lex:add_style('foo', lexer.STYLE_KEYWORD)
+ assert_style(lex, 'foo', lexer.STYLE_KEYWORD)
+ lex:add_style('bar', lexer.STYLE_KEYWORD .. {italics = true})
+ assert_style(lex, 'bar', '$(style.keyword),italics')
+ lex:add_style('baz', 'fore:$(color.red)') -- legacy string
+ assert_style(lex, 'baz', 'fore:$(color.red)')
+end
+
-- Tests a simple parent lexer embedding a simple child lexer.
-- Ensures the child's custom styles are also copied over.
function test_embed()
@@ -606,8 +618,8 @@ function test_legacy()
'function', 'class', 'type', 'label', 'regex', 'embedded'
}
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'
}
local token_styles = {}
for i = 1, #default do token_styles[default[i]] = i end
@@ -1161,6 +1173,65 @@ function test_rhtml()
assert_lex(rhtml, code, rhtml_tokens, initial_style)
end
+-- Tests that the `lexer.colors` table reads and writes properties with a
+-- 'color.' prefix and supports 0xBBGGRR and '#RRGGBB' color formats.
+function test_colors()
+ if not lexer.property then lexer.load('text') end -- creates lexer.property
+
+ assert(lexer.colors.red == '')
+ assert(lexer.property['color.red'] == '')
+ lexer.colors.red = 0x0000FF
+ assert(lexer.colors.red == tostring(0x0000FF))
+ assert(lexer.property['color.red'] == tostring(0x0000FF))
+ lexer.colors.blue = '#0000FF'
+ assert(lexer.colors.blue == '#0000FF')
+ assert(lexer.property['color.blue'] == '#0000FF')
+ -- Verify legacy themes can set color properties directly.
+ lexer.property['color.green'] = '#00FF00'
+ assert(lexer.colors.green == '#00FF00')
+ assert(lexer.property['color.green'] == '#00FF00')
+end
+
+-- Tests that the `lexer.styles` table reads and writes properties with a
+-- 'style.' prefix and supports creating styles from existing styles and
+-- property tables.
+function test_styles()
+ if not lexer.property then lexer.load('text') end -- creates lexer.property
+
+ assert(tostring(lexer.styles.default) == '$(style.default)')
+ assert(tostring(lexer.STYLE_DEFAULT) == '$(style.default)') -- legacy constant
+ assert(lexer.property['style.default'] == '')
+
+ assert(tostring(lexer.styles.keyword) == '$(style.keyword)')
+ assert(lexer.property['style.keyword'] == '')
+ lexer.styles.keyword = {}
+ assert(tostring(lexer.styles.keyword) == '$(style.keyword)')
+ assert(lexer.property['style.keyword'] == '')
+ lexer.styles.keyword = lexer.styles.default
+ assert(tostring(lexer.styles.keyword) == '$(style.keyword)')
+ assert(lexer.property['style.keyword'] == '$(style.default)')
+ lexer.styles.keyword = {bold = true}
+ assert(tostring(lexer.styles.keyword) == '$(style.keyword)')
+ assert(lexer.property['style.keyword'] == 'bold')
+ lexer.colors.yellow = '#FFFF00'
+ lexer.styles.keyword = {fore = lexer.colors.yellow}
+ assert(lexer.property['style.keyword'] == 'fore:#FFFF00')
+
+ lexer.styles.embedded = lexer.styles.keyword .. {italics = true}
+ assert(lexer.property['style.embedded'] == '$(style.keyword),italics')
+ assert(lexer.property['style.keyword'] == 'fore:#FFFF00') -- not modified
+
+ -- Verify legacy styles work.
+ lexer.property['style.macro'] = lexer.STYLE_PREPROCESSOR
+ assert(lexer.property['style.macro'] == '$(style.preprocessor)')
+ lexer.property['style.addition'] = 'fore:$(color.green)'
+ assert(lexer.property['style.addition'] == 'fore:$(color.green)')
+ lexer.property['style.unknown'] = lexer.STYLE_IDENTIFIER .. ',italics'
+ assert(lexer.property['style.unknown'] == '$(style.identifier),,italics')
+ lexer.styles.unknown = lexer.STYLE_IDENTIFIER .. ',italics'
+ assert(lexer.property['style.unknown'] == '$(style.identifier),,italics')
+end
+
-- Run tests.
print('Starting test suite.')
local tests = {}