Branch: refs/heads/master Author: Antonio Cebrián ancebfer@gmail.com Committer: GitHub noreply@github.com Date: Sat, 12 Feb 2022 14:14:59 UTC Commit: a3031e96bda15f77c9b132dcf138cf791c085e2d https://github.com/geany/geany/commit/a3031e96bda15f77c9b132dcf138cf791c085e...
Log Message: ----------- Imports and enables Asciidoc lexer from Lexilla 5.1.4 (#3097)
Modified Paths: -------------- data/filedefs/filetypes.asciidoc scintilla/Makefile.am scintilla/lexilla/lexers/LexAsciidoc.cxx scintilla/lexilla/src/Lexilla.cxx src/highlighting.c src/highlightingmappings.h
Modified: data/filedefs/filetypes.asciidoc 50 lines changed, 24 insertions(+), 26 deletions(-) =================================================================== @@ -1,35 +1,33 @@ # For complete documentation of this file, please see Geany's main documentation [styling] -# no syntax highlighting yet +# Edit these in the colorscheme .conf file instead +default=default +strong=default,bold +emphasis=default,italic +header1=keyword_1 +header2=keyword_1 +header3=keyword_1 +header4=keyword_1 +header5=keyword_1 +header6=keyword_1 +ulist_item=tag_unknown +olist_item=tag_unknown +blockquote=tag_unknown +link=keyword_1 +code=attribute_unknown +passthrough=default +comment=comment +literal=default +attrib=default +attribval=string +macro=preprocessor
[settings] # default extension used when saving files -extension=asciidoc +extension=adoc
-# the following characters are these which a "word" can contains, see documentation -#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 - -# single comments, like # in this file -comment_single=// -# multiline comments -#comment_open=//// -#comment_close=//// - -# set to false if a comment character/string should start at column 0 of a line, true uses any -# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d - #command_example(); -# setting to false would generate this -# command_example(); -# This setting works only for single line comments -comment_use_indent=false - -# context action command (please see Geany's main documentation for details) -context_action_cmd= +# MIME type +mime_type=text/x-asciidoc
# sort tags by appearance symbol_list_sort_mode=1 - -[indentation] -#width=4 -# 0 is spaces, 1 is tabs, 2 is tab & spaces -#type=1
Modified: scintilla/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -14,6 +14,7 @@ lexilla/include/SciLexer.h LEXER_SRCS = \ lexilla/lexers/LexAbaqus.cxx \ lexilla/lexers/LexAda.cxx \ +lexilla/lexers/LexAsciidoc.cxx \ lexilla/lexers/LexAsm.cxx \ lexilla/lexers/LexBash.cxx \ lexilla/lexers/LexBasic.cxx \
Modified: scintilla/lexilla/lexers/LexAsciidoc.cxx 393 lines changed, 393 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,393 @@ +/****************************************************************** + * LexAsciidoc.cxx + * + * A simple Asciidoc lexer for scintilla. + * + * Based on the LexMarkdown.cxx by Jon Strait - jstrait@moonloop.net + * + * The License.txt file describes the conditions under which this + * software may be distributed. + * + *****************************************************************/ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <stdarg.h> +#include <assert.h> + +#include <string> +#include <string_view> + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "LexerModule.h" + +using namespace Lexilla; + +namespace { + +typedef struct { + bool start; + int len1; + int len2; + const char *name; +} MacroItem; + +static const MacroItem MacroList[] = { + // Directives + {true, 5, 2, "ifdef::"}, + {true, 6, 2, "ifeval::"}, + {true, 6, 2, "ifndef::"}, + {true, 5, 2, "endif::"}, + // Macros + {true, 5, 2, "audio::"}, + {true, 7, 2, "include::"}, + {true, 5, 2, "image::"}, + {true, 5, 2, "video::"}, + {false, 8, 1, "asciimath:"}, + {false, 3, 1, "btn:"}, + {false, 5, 1, "image:"}, + {false, 3, 1, "kbd:"}, + {false, 9, 1, "latexmath:"}, + {false, 4, 1, "link:"}, + {false, 6, 1, "mailto:"}, + {false, 4, 1, "menu:"}, + {false, 4, 1, "pass:"}, + {false, 4, 1, "stem:"}, + {false, 4, 1, "xref:"}, + // Admonitions + {true, 7, 1, "CAUTION:"}, + {true, 9, 1, "IMPORTANT:"}, + {true, 4, 1, "NOTE:"}, + {true, 3, 1, "TIP:"}, + {true, 7, 1, "WARNING:"}, + {false, 0, 0, NULL} +}; + +constexpr bool IsNewline(const int ch) { + // sc.GetRelative(i) returns '\0' if out of range + return (ch == '\n' || ch == '\r' || ch == '\0'); +} + +} + +static bool AtTermStart(StyleContext &sc) { + return sc.currentPos == 0 || sc.chPrev == 0 || isspacechar(sc.chPrev); +} + +static void ColorizeAsciidocDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, + WordList **, Accessor &styler) { + bool freezeCursor = false; + + StyleContext sc(startPos, static_cast<Sci_PositionU>(length), initStyle, styler); + + while (sc.More()) { + // Skip past escaped characters + if (sc.ch == '\') { + sc.Forward(); + continue; + } + + // Skip newline. + if (IsNewline(sc.ch)) { + // Newline doesn't end blocks + if (sc.state != SCE_ASCIIDOC_CODEBK && \ + sc.state != SCE_ASCIIDOC_PASSBK && \ + sc.state != SCE_ASCIIDOC_COMMENTBK && \ + sc.state != SCE_ASCIIDOC_LITERALBK) { + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + sc.Forward(); + continue; + } + + // Conditional state-based actions + switch (sc.state) { + + // Strong + case SCE_ASCIIDOC_STRONG1: + if (sc.ch == '*' && sc.chPrev != ' ') { + sc.Forward(); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + freezeCursor = true; + } + break; + case SCE_ASCIIDOC_STRONG2: + if (sc.Match("**") && sc.chPrev != ' ') { + sc.Forward(2); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + freezeCursor = true; + } + break; + + // Emphasis + case SCE_ASCIIDOC_EM1: + if (sc.ch == '_' && sc.chPrev != ' ') { + sc.Forward(); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + freezeCursor = true; + } + break; + case SCE_ASCIIDOC_EM2: + if (sc.Match("__") && sc.chPrev != ' ') { + sc.Forward(2); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + freezeCursor = true; + } + break; + + // Link + case SCE_ASCIIDOC_LINK: + if (sc.ch == ']' && sc.chPrev != '\') { + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Code block + case SCE_ASCIIDOC_CODEBK: + if (sc.atLineStart && sc.Match("----") && IsNewline(sc.GetRelative(4))) { + sc.Forward(4); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Passthrough block + case SCE_ASCIIDOC_PASSBK: + if (sc.atLineStart && sc.Match("++++") && IsNewline(sc.GetRelative(4))) { + sc.Forward(4); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Comment block + case SCE_ASCIIDOC_COMMENTBK: + if (sc.atLineStart && sc.Match("////") && IsNewline(sc.GetRelative(4))) { + sc.Forward(4); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Literal + case SCE_ASCIIDOC_LITERAL: + if (sc.ch == '+' && sc.chPrev != '\') { + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Literal block + case SCE_ASCIIDOC_LITERALBK: + if (sc.atLineStart && sc.Match("....") && IsNewline(sc.GetRelative(4))) { + sc.Forward(4); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Attribute + case SCE_ASCIIDOC_ATTRIB: + if (sc.ch == ':' && sc.chPrev != ' ' && sc.chNext == ' ') { + sc.Forward(); + sc.SetState(SCE_ASCIIDOC_ATTRIBVAL); + } + break; + + // Macro + case SCE_ASCIIDOC_MACRO: + if (sc.ch == ']' && sc.chPrev != '\') { + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + break; + + // Default + case SCE_ASCIIDOC_DEFAULT: + // Headers + if (sc.atLineStart && sc.Match("====== ")) { + sc.SetState(SCE_ASCIIDOC_HEADER6); + sc.Forward(6); + } + else if (sc.atLineStart && sc.Match("===== ")) { + sc.SetState(SCE_ASCIIDOC_HEADER5); + sc.Forward(5); + } + else if (sc.atLineStart && sc.Match("==== ")) { + sc.SetState(SCE_ASCIIDOC_HEADER4); + sc.Forward(4); + } + else if (sc.atLineStart && sc.Match("=== ")) { + sc.SetState(SCE_ASCIIDOC_HEADER3); + sc.Forward(3); + } + else if (sc.atLineStart && sc.Match("== ")) { + sc.SetState(SCE_ASCIIDOC_HEADER2); + sc.Forward(2); + } + else if (sc.atLineStart && sc.Match("= ")) { + sc.SetState(SCE_ASCIIDOC_HEADER1); + sc.Forward(1); + } + // Unordered list item + else if (sc.atLineStart && sc.Match("****** ")) { + sc.SetState(SCE_ASCIIDOC_ULIST_ITEM); + sc.Forward(6); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("***** ")) { + sc.SetState(SCE_ASCIIDOC_ULIST_ITEM); + sc.Forward(5); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("**** ")) { + sc.SetState(SCE_ASCIIDOC_ULIST_ITEM); + sc.Forward(4); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("*** ")) { + sc.SetState(SCE_ASCIIDOC_ULIST_ITEM); + sc.Forward(3); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("** ")) { + sc.SetState(SCE_ASCIIDOC_ULIST_ITEM); + sc.Forward(2); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("* ")) { + sc.SetState(SCE_ASCIIDOC_ULIST_ITEM); + sc.Forward(1); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + // Ordered list item + else if (sc.atLineStart && sc.Match("...... ")) { + sc.SetState(SCE_ASCIIDOC_OLIST_ITEM); + sc.Forward(6); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("..... ")) { + sc.SetState(SCE_ASCIIDOC_OLIST_ITEM); + sc.Forward(5); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match(".... ")) { + sc.SetState(SCE_ASCIIDOC_OLIST_ITEM); + sc.Forward(4); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match("... ")) { + sc.SetState(SCE_ASCIIDOC_OLIST_ITEM); + sc.Forward(3); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match(".. ")) { + sc.SetState(SCE_ASCIIDOC_OLIST_ITEM); + sc.Forward(2); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + else if (sc.atLineStart && sc.Match(". ")) { + sc.SetState(SCE_ASCIIDOC_OLIST_ITEM); + sc.Forward(1); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + } + // Blockquote + else if (sc.atLineStart && sc.Match("> ")) { + sc.SetState(SCE_ASCIIDOC_BLOCKQUOTE); + sc.Forward(); + } + // Link + else if (!sc.atLineStart && sc.ch == '[' && sc.chPrev != '\' && sc.chNext != ' ') { + sc.Forward(); + sc.SetState(SCE_ASCIIDOC_LINK); + freezeCursor = true; + } + // Code block + else if (sc.atLineStart && sc.Match("----") && IsNewline(sc.GetRelative(4))) { + sc.SetState(SCE_ASCIIDOC_CODEBK); + sc.Forward(4); + } + // Passthrough block + else if (sc.atLineStart && sc.Match("++++") && IsNewline(sc.GetRelative(4))) { + sc.SetState(SCE_ASCIIDOC_PASSBK); + sc.Forward(4); + } + // Comment block + else if (sc.atLineStart && sc.Match("////") && IsNewline(sc.GetRelative(4))) { + sc.SetState(SCE_ASCIIDOC_COMMENTBK); + sc.Forward(4); + } + // Comment + else if (sc.atLineStart && sc.Match("//")) { + sc.SetState(SCE_ASCIIDOC_COMMENT); + sc.Forward(); + } + // Literal + else if (sc.ch == '+' && sc.chPrev != '\' && sc.chNext != ' ' && AtTermStart(sc)) { + sc.Forward(); + sc.SetState(SCE_ASCIIDOC_LITERAL); + freezeCursor = true; + } + // Literal block + else if (sc.atLineStart && sc.Match("....") && IsNewline(sc.GetRelative(4))) { + sc.SetState(SCE_ASCIIDOC_LITERALBK); + sc.Forward(4); + } + // Attribute + else if (sc.atLineStart && sc.ch == ':' && sc.chNext != ' ') { + sc.SetState(SCE_ASCIIDOC_ATTRIB); + } + // Strong + else if (sc.Match("**") && sc.GetRelative(2) != ' ') { + sc.SetState(SCE_ASCIIDOC_STRONG2); + sc.Forward(); + } + else if (sc.ch == '*' && sc.chNext != ' ' && AtTermStart(sc)) { + sc.SetState(SCE_ASCIIDOC_STRONG1); + } + // Emphasis + else if (sc.Match("__") && sc.GetRelative(2) != ' ') { + sc.SetState(SCE_ASCIIDOC_EM2); + sc.Forward(); + } + else if (sc.ch == '_' && sc.chNext != ' ' && AtTermStart(sc)) { + sc.SetState(SCE_ASCIIDOC_EM1); + } + // Macro + else if (sc.atLineStart && sc.ch == '[' && sc.chNext != ' ') { + sc.Forward(); + sc.SetState(SCE_ASCIIDOC_MACRO); + freezeCursor = true; + } + else { + int i = 0; + bool found = false; + while (!found && MacroList[i].name != NULL) { + if (MacroList[i].start) + found = sc.atLineStart && sc.Match(MacroList[i].name); + else + found = sc.Match(MacroList[i].name); + if (found) { + sc.SetState(SCE_ASCIIDOC_MACRO); + sc.Forward(MacroList[i].len1); + sc.SetState(SCE_ASCIIDOC_DEFAULT); + if (MacroList[i].len2 > 1) + sc.Forward(MacroList[i].len2 - 1); + } + i++; + } + } + break; + } + // Advance if not holding back the cursor for this iteration. + if (!freezeCursor) + sc.Forward(); + freezeCursor = false; + } + sc.Complete(); +} + +LexerModule lmAsciidoc(SCLEX_ASCIIDOC, ColorizeAsciidocDoc, "asciidoc");
Modified: scintilla/lexilla/src/Lexilla.cxx 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -173,6 +173,7 @@ static void AddGeanyLexers() &lmAbaqus, &lmAda, &lmAsm, + &lmAsciidoc, &lmBash, &lmBatch, &lmCaml,
Modified: src/highlighting.c 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -1000,6 +1000,7 @@ void highlighting_init_styles(guint filetype_idx, GKeyFile *config, GKeyFile *co { init_styleset_case(ABAQUS); init_styleset_case(ADA); + init_styleset_case(ASCIIDOC); init_styleset_case(ASM); init_styleset_case(BASIC); init_styleset_case(BATCH); @@ -1091,6 +1092,7 @@ void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft) { styleset_case(ABAQUS); styleset_case(ADA); + styleset_case(ASCIIDOC); styleset_case(ASM); styleset_case(BASIC); styleset_case(BATCH);
Modified: src/highlightingmappings.h 33 lines changed, 33 insertions(+), 0 deletions(-) =================================================================== @@ -133,6 +133,39 @@ static const HLKeyword highlighting_keywords_AS[] = #define highlighting_properties_AS highlighting_properties_C
+/* Asccidoc */ +#define highlighting_lexer_ASCIIDOC SCLEX_ASCIIDOC +static const HLStyle highlighting_styles_ASCIIDOC[] = +{ + { SCE_ASCIIDOC_DEFAULT, "default", FALSE }, + { SCE_ASCIIDOC_STRONG1, "strong", FALSE }, + { SCE_ASCIIDOC_STRONG2, "strong", FALSE }, + { SCE_ASCIIDOC_EM1, "emphasis", FALSE }, + { SCE_ASCIIDOC_EM2, "emphasis", FALSE }, + { SCE_ASCIIDOC_HEADER1, "header1", FALSE }, + { SCE_ASCIIDOC_HEADER2, "header2", FALSE }, + { SCE_ASCIIDOC_HEADER3, "header3", FALSE }, + { SCE_ASCIIDOC_HEADER4, "header4", FALSE }, + { SCE_ASCIIDOC_HEADER5, "header5", FALSE }, + { SCE_ASCIIDOC_HEADER6, "header6", FALSE }, + { SCE_ASCIIDOC_ULIST_ITEM, "ulist_item", FALSE }, + { SCE_ASCIIDOC_OLIST_ITEM, "olist_item", FALSE }, + { SCE_ASCIIDOC_BLOCKQUOTE, "blockquote", FALSE }, + { SCE_ASCIIDOC_LINK, "link", FALSE }, + { SCE_ASCIIDOC_CODEBK, "code", FALSE }, + { SCE_ASCIIDOC_PASSBK, "passthrough", FALSE }, + { SCE_ASCIIDOC_COMMENT, "comment", FALSE }, + { SCE_ASCIIDOC_COMMENTBK, "comment", FALSE }, + { SCE_ASCIIDOC_LITERAL, "literal", FALSE }, + { SCE_ASCIIDOC_LITERALBK, "literal", FALSE }, + { SCE_ASCIIDOC_ATTRIB, "attrib", FALSE }, + { SCE_ASCIIDOC_ATTRIBVAL, "attribval", FALSE }, + { SCE_ASCIIDOC_MACRO, "macro", FALSE } +}; +#define highlighting_keywords_ASCIIDOC EMPTY_KEYWORDS +#define highlighting_properties_ASCIIDOC EMPTY_PROPERTIES + + /* ASM */ #define highlighting_lexer_ASM SCLEX_ASM static const HLStyle highlighting_styles_ASM[] =
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).