diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-12-09 12:58:25 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-12-13 00:58:14 +0300 |
commit | 244a54a18b7db6af177c9d10f3224772f08d7484 (patch) | |
tree | 188f5a2f1b2e3311efb65299b639021a231540af /src/lexer.h | |
parent | 7cc78b82e19816220dac5ddf83e51f1140894b42 (diff) | |
download | sciteco-244a54a18b7db6af177c9d10f3224772f08d7484.tar.gz |
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.
Diffstat (limited to 'src/lexer.h')
-rw-r--r-- | src/lexer.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lexer.h b/src/lexer.h new file mode 100644 index 0000000..87b0d0f --- /dev/null +++ b/src/lexer.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2012-2024 Robin Haberkorn + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#pragma once + +#include <glib.h> + +#include "view.h" + +/** Scintilla style ids for lexing SciTECO code */ +typedef enum { + SCE_SCITECO_DEFAULT = 0, + SCE_SCITECO_COMMAND = 1, + SCE_SCITECO_OPERATOR = 2, + SCE_SCITECO_QREG = 3, + SCE_SCITECO_STRING = 4, + SCE_SCITECO_NUMBER = 5, + SCE_SCITECO_LABEL = 6, + SCE_SCITECO_COMMENT = 7, + SCE_SCITECO_INVALID = 8 +} teco_style_t; + +void teco_lexer_style(teco_view_t *view, gsize end); |