From 244a54a18b7db6af177c9d10f3224772f08d7484 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 9 Dec 2024 12:58:25 +0300 Subject: implemented Scintilla lexer for SciTECO code, i.e. TECO syntax highlighting * this works by embedding the SciTECO parser and driving it always (exclusively) in parse-only mode. * A new teco_state_t::style determines the Scintilla style for any character accepted in the given state. * Therefore, the SciTECO lexer is always 100% exact and corresponds to the current SciTECO grammer - it does not have to be maintained separately. There are a few exceptions and tweaks, though. * The contents of curly-brace escapes (`@^Uq{...}`) are rendered as ordinary code using a separate parser instance. This can be disabled with the lexer.sciteco.macrodef property. Unfortunately, SciTECO does not currently allow setting lexer properties (FIXME). * Labels and comments are currently styled the same. This could change in the future once we introduce real comments. * Lexers are usually implemented in C++, but I did not want to draw in C++. Especially not since we'd have to include parser.h and other SciTECO headers, that really do not want to keep C++-compatible. Instead, the lexer is implemented "in the container". @ES/SCI_SETILEXER/sciteco/ is internally translated to SCI_SETILEXER(NULL) and we get Scintilla notifications when styling the view becomes necessary. This is then centrally forwarded to the teco_lexer_style() which uses the ordinary teco_view_ssm() API for styling. * Once the command line becomes a Scintilla view even on Curses, we can enabled syntax highlighting of the command line macro. --- lib/Makefile.am | 3 ++- lib/lexers/sciteco.tes | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 lib/lexers/sciteco.tes (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index ac45c76..8bf80be 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -101,6 +101,7 @@ dist_lexer_DATA += lexers/verilog.tes \ lexers/markdown.tes \ lexers/asciidoc.tes \ lexers/troff.tes \ - lexers/git.tes + lexers/git.tes \ + lexers/sciteco.tes endif diff --git a/lib/lexers/sciteco.tes b/lib/lexers/sciteco.tes new file mode 100644 index 0000000..058e79d --- /dev/null +++ b/lib/lexers/sciteco.tes @@ -0,0 +1,20 @@ +!* SciTECO syntax highlighting *! + +@[lexer.test.sciteco]{ + _#!Msciteco:M[lexer.checkheader]"S -1 ' + :EN*.tesQ*"S -1 ' + :EN*.tecQ*"S -1 ' + :EN*.teco_iniQ* +} + +@[lexer.set.sciteco]{ + ESSETILEXERsciteco + !*:M[color.keyword],1M[color.set]*! + :M[color.operator],2M[color.set] + :M[color.variable],3M[color.set] + :M[color.string],4M[color.set] + :M[color.number],5M[color.set] + :M[color.comment],6M[color.set] !* labels *! + :M[color.comment],7M[color.set] + :M[color.error],8M[color.set] +} -- cgit v1.2.3