From f1bc6bfc98190bf5c0c5ee208140a116cb0231fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 31 Mar 2025 01:14:09 -0300 Subject: [PATCH] Add Common Lisp syntax highlighting. --- src/eepp/ui/doc/syntaxtokenizer.cpp | 6 +- .../src/eepp/ui/doc/languages/lisp.cpp | 133 ++++++++++++++++++ .../src/eepp/ui/doc/languages/lisp.hpp | 10 ++ .../ui/doc/languagessyntaxhighlighting.cpp | 2 + src/tools/ecode/ecode.cpp | 2 +- 5 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.cpp create mode 100644 src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.hpp diff --git a/src/eepp/ui/doc/syntaxtokenizer.cpp b/src/eepp/ui/doc/syntaxtokenizer.cpp index 444ac0756..e17822420 100644 --- a/src/eepp/ui/doc/syntaxtokenizer.cpp +++ b/src/eepp/ui/doc/syntaxtokenizer.cpp @@ -397,7 +397,8 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax patternText = textv.substr( start, end - start ); SyntaxStyleType type = curMatch < pattern.types.size() && - pattern.types[curMatch] == SyntaxStyleTypes::Symbol + ( pattern.types[curMatch] == SyntaxStyleTypes::Symbol || + pattern.types[curMatch] == SyntaxStyleTypes::Normal ) ? curState.currentSyntax->getSymbol( ( patternTextStr = patternText ) ) : SyntaxStyleEmpty(); @@ -454,7 +455,8 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax patternText = textv.substr( start, end - start ); SyntaxStyleType type = curMatch < pattern.types.size() && - pattern.types[curMatch] == SyntaxStyleTypes::Symbol + ( pattern.types[curMatch] == SyntaxStyleTypes::Symbol || + pattern.types[curMatch] == SyntaxStyleTypes::Normal ) ? curState.currentSyntax->getSymbol( ( patternTextStr = patternText ) ) : SyntaxStyleEmpty(); diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.cpp new file mode 100644 index 000000000..84dc857fa --- /dev/null +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.cpp @@ -0,0 +1,133 @@ +#include +#include + +namespace EE { namespace UI { namespace Doc { namespace Language { + +void addLisp() { + + auto& sd = SyntaxDefinitionManager::instance()->add( + + { "Lisp", + { "%.lisp$", "%.cl$", "%.el$" }, + { + { { ";.-\n" }, "comment" }, + { { "#|", "|#", "\\" }, "comment" }, + { { "\"", "\"", "\\" }, "string" }, + { { "#x[%da-fA-F]+" }, "number" }, + { { "#o[0-7]+" }, "number" }, + { { "#b[01]+" }, "number" }, + { { "-?%d+[%d%.eE]*f?" }, "number" }, + { { "%(%s*([%a_][%w_-]*)%s+([%a_][%w_-]*)" }, { "operator", "symbol", "keyword2" } }, + { { "'([%a_][%w_-]*)" }, { "operator", "keyword2", "symbol" } }, + { { ":([%a_][%w_-]*)" }, { "operator", "keyword3", "symbol" } }, + { { "[%<%>%=%*%/%+%-%`%@%%%(%)]" }, "operator" }, + + }, + { + + { "defclass", "keyword" }, + { "defconstant", "keyword" }, + { "defgeneric", "keyword" }, + { "define-compiler-macro", "keyword" }, + { "define-condition", "keyword" }, + { "define-method-combination", "keyword" }, + { "define-modify-macro", "keyword" }, + { "define-setf-expander", "keyword" }, + { "define-symbol-macro", "keyword" }, + { "defmacro", "keyword" }, + { "defmethod", "keyword" }, + { "defpackage", "keyword" }, + { "defparameter", "keyword" }, + { "defsetf", "keyword" }, + { "defstruct", "keyword" }, + { "deftype", "keyword" }, + { "defun", "keyword" }, + { "defvar", "keyword" }, + { "abort", "keyword" }, + { "assert", "keyword" }, + { "block", "keyword" }, + { "break", "keyword" }, + { "case", "keyword" }, + { "catch", "keyword" }, + { "ccase", "keyword" }, + { "cerror", "keyword" }, + { "cond", "keyword" }, + { "ctypecase", "keyword" }, + { "declaim", "keyword" }, + { "declare", "keyword" }, + { "do", "keyword" }, + { "do*", "keyword" }, + { "do-all-symbols", "keyword" }, + { "do-external-symbols", "keyword" }, + { "do-symbols", "keyword" }, + { "dolist", "keyword" }, + { "dotimes", "keyword" }, + { "ecase", "keyword" }, + { "error", "keyword" }, + { "etypecase", "keyword" }, + { "eval-when", "keyword" }, + { "flet", "keyword" }, + { "handler-bind", "keyword" }, + { "handler-case", "keyword" }, + { "if", "keyword" }, + { "ignore-errors", "keyword" }, + { "in-package", "keyword" }, + { "labels", "keyword" }, + { "lambda", "keyword" }, + { "let", "keyword" }, + { "let*", "keyword" }, + { "locally", "keyword" }, + { "loop", "keyword" }, + { "map", "keyword" }, + { "macrolet", "keyword" }, + { "make-instance", "keyword" }, + { "multiple-value-bind", "keyword" }, + { "proclaim", "keyword" }, + { "prog", "keyword" }, + { "prog*", "keyword" }, + { "prog1", "keyword" }, + { "prog2", "keyword" }, + { "progn", "keyword" }, + { "progv", "keyword" }, + { "provide", "keyword" }, + { "require", "keyword" }, + { "restart-bind", "keyword" }, + { "restart-case", "keyword" }, + { "restart-name", "keyword" }, + { "return", "keyword" }, + { "return-from", "keyword" }, + { "signal", "keyword" }, + { "symbol-macrolet", "keyword" }, + { "tagbody", "keyword" }, + { "the", "keyword" }, + { "throw", "keyword" }, + { "typecase", "keyword" }, + { "unless", "keyword" }, + { "unwind-protect", "keyword" }, + { "when", "keyword" }, + { "with-accessors", "keyword" }, + { "with-compilation-unit", "keyword" }, + { "with-condition-restarts", "keyword" }, + { "with-hash-table-iterator", "keyword" }, + { "with-input-from-string", "keyword" }, + { "with-open-file", "keyword" }, + { "with-open-stream", "keyword" }, + { "with-output-to-string", "keyword" }, + { "with-package-iterator", "keyword" }, + { "with-simple-restart", "keyword" }, + { "with-slots", "keyword" }, + { "with-standard-io-syntax", "keyword" }, + { "t", "keyword" }, + { "nil", "literal" }, + + }, + ";", + {} + + } ); + + sd.setFoldRangeType( FoldRangeType::Braces ) + .setFoldBraces( { { '(', ')' }, { '{', '}' }, { '[', ']' } } ); +} + +}}}} // namespace EE::UI::Doc::Language diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.hpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.hpp new file mode 100644 index 000000000..49c347062 --- /dev/null +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/lisp.hpp @@ -0,0 +1,10 @@ +#ifndef EE_UI_DOC_Lisp +#define EE_UI_DOC_Lisp + +namespace EE { namespace UI { namespace Doc { namespace Language { + +extern void addLisp(); + +}}}} // namespace EE::UI::Doc::Language + +#endif diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp index 7db47d2fe..3a1772f65 100644 --- a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -151,6 +152,7 @@ void LanguagesSyntaxHighlighting::load() { addJSX(); addKotlin(); addLatex(); + addLisp(); addLobster(); addMakefile(); addMeson(); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 8fd7aefba..af2c5be4a 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3549,7 +3549,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mThreadPool->run( [this] { // Load language definitions Clock defClock; - SyntaxDefinitionManager::createSingleton( 117 ); + SyntaxDefinitionManager::createSingleton( 118 ); Language::LanguagesSyntaxHighlighting::load(); SyntaxDefinitionManager::instance()->setLanguageExtensionsPriority( mConfig.languagesExtensions.priorities );