From 329559b74b483576a74d5f87eebf951bd12b9200 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 7 Jul 2020 20:14:11 -0400 Subject: lexlua: Added `lexer.colors` and `lexer.styles` tables for themes and lexers. This allows for a more Lua table-oriented approach to defining and using colors and styles, instead of manually manipulating Scintilla property strings. Themes and lexers are still backwards compatible, as the underlying mechanisms are still in place. --- doc/LPegLexer.html | 609 ++++++++++++++++++----------------------------------- 1 file changed, 205 insertions(+), 404 deletions(-) (limited to 'doc') 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 @@ SCI_PROPERTYNAMES

SCI_PRIVATELEXERCALL(SCI_GETNAMEDSTYLES, const char *styleName)
- Returns the style number associated with styleName.

+ Returns the style number associated with styleName, or STYLE_DEFAULT + if styleName is not in use.

Usage:

@@ -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 “foldable” (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.

@@ -597,16 +598,16 @@ operator 30 language in lower case followed by a .lua extension. For example, a new Lua lexer has the name lua.lua.

-

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.

+

Note: Try to refrain from using one-character language names like “c”, “d”, + or “r”. For example, Lua lexers for those language names are named “ansi_c”, + “dmd”, and “rstats”, respectively.

New Lexer Template

There is a lexlua/template.txt 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 ‘?’s with the name of your lexer. Consider this snippet from the template:


@@ -630,23 +631,23 @@ operator    30
     

The first 3 lines of code simply define often used convenience variables. The fourth and last lines define 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 “token”, 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 local 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’s global environment. All in all, this is a minimal, working lexer that you can build on.

Tokens

-

Take a moment to think about your programming language's structure. What kind +

Take a moment to think about your programming language’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 “tokens”. Tokens are the fundamental “building blocks” 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

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 lexer.token() function. Let us examine the "whitespace" token + using the lexer.token() function. Let us examine the “whitespace” token defined in the template shown earlier:


@@ -690,10 +691,10 @@ operator    30
     lexer.punct, lexer.space, lexer.newline,
     lexer.nonnewline, lexer.nonnewline_esc, lexer.dec_num,
     lexer.hex_num, lexer.oct_num, lexer.integer,
-    lexer.float, lexer.number, and lexer.word. 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.

+ lexer.float, lexer.number, and lexer.word. 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.

@@ -747,19 +748,19 @@ operator 30 local c_line_comment = token(lexer.COMMENT, lexer.to_eol('//', true))
-

The comments above start with a '#' or "//" and go to the end of the line. +

The comments above start with a ‘#’ or “//” 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.

+ line ends with a ‘\’ escape character.

-

C-style "block" comments with a start and end delimiter are also easy to +

C-style “block” comments with a start and end delimiter are also easy to express:


     local c_comment = token(lexer.COMMENT, lexer.range('/*', '*/'))
     
-

This comment starts with a "/*" sequence and contains anything up to and - including an ending "*/" sequence. The ending "*/" is optional so the lexer +

This comment starts with a “/*” sequence and contains anything up to and + including an ending “*/” sequence. The ending “*/” is optional so the lexer can recognize unfinished comments as comments and highlight them properly.

Strings

@@ -775,7 +776,7 @@ operator 30 local string = token(lexer.STRING, dq_str + sq_str)
-

In this case, the lexer treats '\' as an escape character in a string +

In this case, the lexer treats ‘\’ as an escape character in a string sequence.

Numbers

@@ -805,7 +806,7 @@ operator 30

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 lexer.add_rule() call, which adds a rule to the lexer's + template the lexer.add_rule() call, which adds a rule to the lexer’s grammar:


@@ -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".

+ simply matches whitespace tokens under a rule named “whitespace”.

To illustrate the importance of rule order, here is an example of a simplified Lua lexer:

@@ -834,15 +835,15 @@ operator 30

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 “identifier” + rule before the “keyword” 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.

-

So what about text that does not match any rules? For example in Lua, the '!' +

So what about text that does not match any rules? For example in Lua, the ‘!’ 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 “syntax errors”, add an additional end rule:


@@ -887,126 +888,48 @@ operator    30
 
     

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 “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'
-    
- -

If you want the same style, but also with an italic font face, define the new - style in terms of the old one:

- -

-    local style_bold_italic = style_bold..',italics'
+    local style_bold = {bold = true}
     
-

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:

+

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_static_var = lexer.STYLE_VARIABLE..',italics'
+    local style_static_var = lexer.styles.variable .. {italics = true}
     

The color theme files in the lexlua/themes/ folder give more examples of @@ -1036,24 +959,22 @@ operator 30

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" + entities. In the example above, the lexer associates the “custom_whitespace” token with the existing style for lexer.WHITESPACE tokens. If instead you 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.

@@ -1062,8 +983,8 @@ operator 30

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 “diff” needs to know if + the line started with a ‘+’ or ‘-’ and then style the entire line accordingly. To indicate that your lexer matches by line, create the lexer with an extra parameter:

@@ -1079,12 +1000,12 @@ operator 30

Embedded Lexers

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 “child” lexer and + the lexer a child is being embedded in is called the “parent”. 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 “child” lexer with the HTML + lexer being the “parent”. 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 embeds itself into HTML while CSS is embedded in HTML. This fundamental difference results in two types of embedded lexers: a parent lexer that @@ -1105,10 +1026,10 @@ operator 30

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 “start rule” and “end rule”, 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":

+ HTML to CSS is when the lexer encounters a “style” tag with a “type” + attribute whose value is “text/css”:


     local css_tag = P('<style') * P(function(input, index)
@@ -1118,12 +1039,12 @@ operator    30
     end)
     
-

This pattern looks for the beginning of a "style" tag and searches its - attribute list for the text "type="text/css"". (In this simplified example, - the Lua pattern does not consider whitespace between the '=' nor does it +

This pattern looks for the beginning of a “style” tag and searches its + attribute list for the text “type="text/css"”. (In this simplified example, + the Lua pattern does not consider whitespace between the ‘=’ nor does it consider that using single quotes is valid.) If there is a match, the functional pattern returns a value instead of nil. 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 “style” tag as an HTML tag, so the actual start rule looks like this:


@@ -1132,14 +1053,14 @@ operator    30
 
     

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 “style” tag, though the lexer should still style the tag as an HTML tag:


     local css_end_rule = #P('</style>') * tag
     
-

Once the parent loads the child lexer and defines the child's start and end +

Once the parent loads the child lexer and defines the child’s start and end rules, it embeds the child with the lexer.embed() function:


@@ -1160,7 +1081,7 @@ operator    30
     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)
     
@@ -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 lpeg.P function patterns that set state variables, it is recommended to make use of - Scintilla's built-in, per-line state integers via lexer.line_state. It + Scintilla’s built-in, per-line state integers via lexer.line_state. It was designed to accommodate up to 32 bit flags for tracking state. lexer.line_from_position() will return the line for any position given to an lpeg.P function pattern. (Any positions derived from that position @@ -1186,15 +1107,16 @@ operator 30

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.

+ “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.

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 “if” and “end” in Lua and examples of fold + character sequences are ‘{’, ‘}’, “/*”, and “*/” 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 lexer.add_fold_point() function @@ -1206,9 +1128,9 @@ operator 30 lex:add_fold_point(lexer.COMMENT, '/*', '*/')

-

The first assignment states that any '{' or '}' that the lexer recognized as +

The first assignment states that any ‘{’ or ‘}’ that the lexer recognized as an lexer.OPERATOR token is a fold point. Likewise, the second assignment - states that any "/*" or "*/" that the lexer recognizes as part of a + states that any “/*” or “*/” that the lexer recognizes as part of a lexer.COMMENT 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)

-

Any time the lexer encounters a '|' that is a "strange_token", it calls the - fold_strange_token function to determine if '|' is a fold point. The lexer +

Any time the lexer encounters a ‘|’ that is a “strange_token”, it calls the + fold_strange_token function to determine if ‘|’ 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’s text, the position in the current line the fold point text starts at, and the fold point text itself.

@@ -1312,12 +1234,12 @@ operator 30 return M
-

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:

+

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:

    -
  1. Replace all instances of l with lexer, as it's better practice and +
  2. Replace all instances of l with lexer, as it’s better practice and results in less confusion.
  3. Replace local M = {_NAME = '?'} with local lex = lexer.new('?'), where ? 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

    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’s C++ ones. Optimize lexers for speed by re-arranging lexer.add_rule() calls so that the most common rules match first. Do keep in mind that order matters for similar rules.

    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 lexer.fold() with your own implementation, or simply eliminating folding support from your lexer.

    @@ -1436,7 +1358,7 @@ operator 30

    Limitations

    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’s tokens do not support start and end rules. This mostly goes unnoticed, but code like

    
    @@ -1575,158 +1497,6 @@ operator    30
     
         

    The token name for string tokens.

    -

    - -

    lexer.STYLE_BRACEBAD (string)

    - -

    The style used for unmatched brace characters.

    - -

    - -

    lexer.STYLE_BRACELIGHT (string)

    - -

    The style used for highlighted brace characters.

    - -

    - -

    lexer.STYLE_CALLTIP (string)

    - -

    The style used by call tips if buffer.call_tip_use_style is set. - Only the font name, size, and color attributes are used.

    - -

    - -

    lexer.STYLE_CLASS (string)

    - -

    The style typically used for class definitions.

    - -

    - -

    lexer.STYLE_COMMENT (string)

    - -

    The style typically used for code comments.

    - -

    - -

    lexer.STYLE_CONSTANT (string)

    - -

    The style typically used for constants.

    - -

    - -

    lexer.STYLE_CONTROLCHAR (string)

    - -

    The style used for control characters. - Color attributes are ignored.

    - -

    - -

    lexer.STYLE_DEFAULT (string)

    - -

    The style all styles are based off of.

    - -

    - -

    lexer.STYLE_EMBEDDED (string)

    - -

    The style typically used for embedded code.

    - -

    - -

    lexer.STYLE_ERROR (string)

    - -

    The style typically used for erroneous syntax.

    - -

    - -

    lexer.STYLE_FOLDDISPLAYTEXT (string)

    - -

    The style used for fold display text.

    - -

    - -

    lexer.STYLE_FUNCTION (string)

    - -

    The style typically used for function definitions.

    - -

    - -

    lexer.STYLE_IDENTIFIER (string)

    - -

    The style typically used for identifier words.

    - -

    - -

    lexer.STYLE_INDENTGUIDE (string)

    - -

    The style used for indentation guides.

    - -

    - -

    lexer.STYLE_KEYWORD (string)

    - -

    The style typically used for language keywords.

    - -

    - -

    lexer.STYLE_LABEL (string)

    - -

    The style typically used for labels.

    - -

    - -

    lexer.STYLE_LINENUMBER (string)

    - -

    The style used for all margins except fold margins.

    - -

    - -

    lexer.STYLE_NUMBER (string)

    - -

    The style typically used for numbers.

    - -

    - -

    lexer.STYLE_OPERATOR (string)

    - -

    The style typically used for operators.

    - -

    - -

    lexer.STYLE_PREPROCESSOR (string)

    - -

    The style typically used for preprocessor statements.

    - -

    - -

    lexer.STYLE_REGEX (string)

    - -

    The style typically used for regular expression strings.

    - -

    - -

    lexer.STYLE_STRING (string)

    - -

    The style typically used for strings.

    - -

    - -

    lexer.STYLE_TYPE (string)

    - -

    The style typically used for static types.

    - -

    - -

    lexer.STYLE_VARIABLE (string)

    - -

    The style typically used for variables.

    - -

    - -

    lexer.STYLE_WHITESPACE (string)

    - -

    The style typically used for whitespace.

    -

    lexer.TYPE (string)

    @@ -1749,14 +1519,14 @@ operator 30

    lexer.alnum (pattern)

    -

    A pattern that matches any alphanumeric character ('A'-'Z', 'a'-'z', - '0'-'9').

    +

    A pattern that matches any alphanumeric character (‘A’-‘Z’, ‘a’-‘z’, + ‘0’-‘9’).

    lexer.alpha (pattern)

    -

    A pattern that matches any alphabetic character ('A'-'Z', 'a'-'z').

    +

    A pattern that matches any alphabetic character (‘A’-‘Z’, ‘a’-‘z’).

    @@ -1786,7 +1556,7 @@ operator 30

    lexer.digit (pattern)

    -

    A pattern that matches any digit ('0'-'9').

    +

    A pattern that matches any digit (‘0’-‘9’).

    @@ -1822,7 +1592,7 @@ operator 30

    lexer.graph (pattern)

    -

    A pattern that matches any graphical character ('!' to '~').

    +

    A pattern that matches any graphical character (‘!’ to ‘~’).

    @@ -1854,13 +1624,13 @@ operator 30

    lexer.lower (pattern)

    -

    A pattern that matches any lower case character ('a'-'z').

    +

    A pattern that matches any lower case character (‘a’-‘z’).

    lexer.newline (pattern)

    -

    A pattern that matches any set of end of line characters.

    +

    A pattern that matches a sequence of end of line characters.

    @@ -1873,14 +1643,14 @@ operator 30

    lexer.nonnewline_esc (pattern)

    A pattern that matches any single, non-newline character or any set of end - of line characters escaped with '\'.

    + of line characters escaped with ‘\’.

    lexer.number (pattern)

    A pattern that matches a typical number, either a floating point, decimal, - hexadecimal, or octal number.

    + hexadecimal, or octal number.

    @@ -1888,19 +1658,11 @@ operator 30

    A pattern that matches an octal number.

    -

    - -

    lexer.path (string)

    - -

    The path used to search for a lexer to load. - Identical in format to Lua's package.path string. - The default value is package.path.

    -

    lexer.print (pattern)

    -

    A pattern that matches any printable character (' ' to '~').

    +

    A pattern that matches any printable character (‘ ’ to ‘~’).

    @@ -1926,15 +1688,15 @@ operator 30

    lexer.punct (pattern)

    -

    A pattern that matches any punctuation character ('!' to '/', ':' to '@', - '[' to ''', '{' to '~').

    +

    A pattern that matches any punctuation character (‘!’ to ‘/’, ‘:’ to ‘@’, + ‘[’ to ‘’‘, ’{‘ to ’~‘).

    lexer.space (pattern)

    -

    A pattern that matches any whitespace character ('\t', '\v', '\f', '\n', - '\r', space).

    +

    A pattern that matches any whitespace character (‘\t’, ‘\v’, ‘\f’, ‘\n’, + ‘\r’, space).

    @@ -1946,7 +1708,7 @@ operator 30

    lexer.upper (pattern)

    -

    A pattern that matches any upper case character ('A'-'Z').

    +

    A pattern that matches any upper case character (‘A’-‘Z’).

    @@ -1959,13 +1721,13 @@ operator 30

    lexer.xdigit (pattern)

    -

    A pattern that matches any hexadecimal digit ('0'-'9', 'A'-'F', 'a'-'f').

    +

    A pattern that matches any hexadecimal digit (‘0’-‘9’, ‘A’-‘F’, ‘a’-‘f’).

    Lua lexer module API functions

    -

    lexer.add_fold_point (lexer, token_name, start_symbol, end_symbol)

    +

    lexer.add_fold_point(lexer, token_name, start_symbol, end_symbol)

    Adds to lexer lexer a fold point whose beginning and end tokens are string token_name tokens with string content start_symbol and end_symbol, @@ -1986,7 +1748,7 @@ operator 30 -

    Fields:

    +

    Parameters:

    • lexer: The lexer to add a fold point to.
    • @@ -2011,12 +1773,12 @@ operator 30

      -

      lexer.add_rule (lexer, id, rule)

      +

      lexer.add_rule(lexer, id, rule)

      Adds pattern rule identified by string id to the ordered list of rules for lexer lexer.

      -

      Fields:

      +

      Parameters:

      • lexer: The lexer to add the given rule to.
      • @@ -2037,50 +1799,32 @@ operator 30

        lexer.add_style (lexer, token_name, style)

        -

        Associates string token_name in lexer lexer with Scintilla style string - style. - Style strings are comma-separated property settings. Available property - settings are:

        +

        Associates string token_name in lexer lexer with style table style.

        + +

        Parameters:

          -
        • 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.
        • +
        • lexer: The lexer to add a style to.
        • +
        • token_name: The name of the token to associated with the style.
        • +
        • style: A style table.
        -

        Property settings may also contain "$(property.name)" expansions for - properties defined in Scintilla, theme files, etc.

        - -

        Fields:

        +

        Usage:

          -
        • lexer: The lexer to add a style to.
        • -
        • token_name: The name of the token to associated with the style.
        • -
        • style: A style string for Scintilla.
        • +
        • lex:add_style('longstring', lexer.styles.string)
        • +
        • lex:add_style('deprecated_func', lexer.styles['function'] .. + {italics = true}
        • +
        • lex:add_style('visible_ws', lexer.styles.whitespace .. + {back = lexer.colors.grey}
        -

        Usage:

        +

        See also:

          -
        • lex:add_style('longstring', lexer.STYLE_STRING)
        • -
        • lex:add_style('deprecated_function', lexer.STYLE_FUNCTION..',italics')
        • -
        • lex:add_style('visible_ws', - lexer.STYLE_WHITESPACE..',back:$(color.grey)')
        • +
        • lexer.styles
        @@ -2092,7 +1836,7 @@ operator 30 start_rule and end_rule, which signal the beginning and end of the embedded lexer, respectively.

        -

        Fields:

        +

        Parameters:

        • lexer: The parent lexer.
        • @@ -2120,7 +1864,7 @@ operator 30 text starts at position start_pos on line number start_line with a beginning fold level of start_level in the buffer.

          -

          Fields:

          +

          Parameters:

          • lexer: The lexer to fold text with.
          • @@ -2146,7 +1890,7 @@ operator 30

            Returns a fold function (to be passed to lexer.add_fold_point()) that folds consecutive line comments that start with string prefix.

            -

            Fields:

            +

            Parameters:

            • prefix: The prefix string defining a line comment.
            • @@ -2169,7 +1913,7 @@ operator 30

              Returns the rule identified by string id.

              -

              Fields:

              +

              Parameters:

              • lexer: The lexer to fetch a rule from.
              • @@ -2191,7 +1935,7 @@ operator 30

                Creates and returns a pattern that verifies that string set s contains the first non-whitespace character behind the current match position.

                -

                Fields:

                +

                Parameters:

                • s: String character set like one passed to lpeg.S().
                • @@ -2221,7 +1965,7 @@ operator 30 init_style) using lexer lexer, returning a table of token names and positions.

                  -

                  Fields:

                  +

                  Parameters:

                  • lexer: The lexer to lex text with.
                  • @@ -2242,10 +1986,10 @@ operator 30

                    lexer.line_from_position (pos)

                    -

                    Returns the line number of the line that contains position pos, which - starts from 1.

                    +

                    Returns the line number (starting from 1) of the line that contains position + pos, which starts from 1.

                    -

                    Fields:

                    +

                    Parameters:

                    • pos: The position to get the line number of.
                    • @@ -2269,7 +2013,7 @@ operator 30 calls this function in order to load a lexer when using this module as a Lua library.

                      -

                      Fields:

                      +

                      Parameters:

                      • name: The name of the lexing language.
                      • @@ -2296,7 +2040,7 @@ operator 30

                        Replaces in lexer lexer the existing rule identified by string id with pattern rule.

                        -

                        Fields:

                        +

                        Parameters:

                        • lexer: The lexer to modify.
                        • @@ -2311,10 +2055,10 @@ operator 30

                          Creates a returns a new lexer with the given name.

                          -

                          Fields:

                          +

                          Parameters:

                            -
                          • name: The lexer's name.
                          • +
                          • name: The lexer’s name.
                          • opts: Table of lexer options. Options currently supported:
                              @@ -2366,8 +2110,8 @@ operator 30 on a single line.
                            • escapes: Optional flag indicating whether or not the range end may be escaped by a ‘\’ character. - The default value is false unless s and e are identical, single-character strings. - In that case, the default value is true.
                            • + The default value is false unless s and e are identical, + single-character strings. In that case, the default value is true.
                            • balanced: Optional flag indicating whether or not to match a balanced range, like the “%b” Lua pattern. This flag only applies if s and e are different.
                            • @@ -2398,7 +2142,7 @@ operator 30

                              Creates and returns a pattern that matches pattern patt only at the beginning of a line.

                              -

                              Fields:

                              +

                              Parameters:

                              • patt: The LPeg pattern to match on the beginning of a line.
                              • @@ -2462,7 +2206,7 @@ operator 30 If name is not a predefined token name, its style must be defined via lexer.add_style().

                                -

                                Fields:

                                +

                                Parameters:

                                • name: The name of token. If this name is not a predefined token name, @@ -2498,7 +2242,7 @@ operator 30 If words is a multi-line string, it may contain Lua line comments (--) that will ultimately be ignored.

                                  -

                                  Fields:

                                  +

                                  Parameters:

                                  • words: A string list of words separated by spaces.
                                  • @@ -2523,6 +2267,63 @@ operator 30
                                  • pattern
                                  + +

                                  Lua lexer module API tables

                                  + +

                                  + +

                                  lexer.colors

                                  + +

                                  Map of color names strings to color values in 0xBBGGRR or "#RRGGBB" + format.

                                  + +

                                  + +

                                  lexer.styles

                                  + +

                                  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, 'm' for normal, + mixed case, and 'c' for camel 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.
                                  • +
                                  +

                                  Supported Languages

                                  Scintilla has Lua lexers for all of the languages below. Languages -- cgit v1.2.3