From 7c0e4fbb1d1f0d19d11c7417c55a305654ab1c83 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 8 Apr 2025 23:26:38 +0300 Subject: tightened rules for specifying modifiers * Instead of separate stand-alone commands, they are now allowed only immediately in front of the commands that accept them. * The order is still insignificant if both `@` and `:` are accepted. * The number of colon modifiers is now also checked. We basically get this for free. * `@` has syntactic significance, so it could not be set conditionally anyway. Still, it was possible to provoke bugs were `@` was interpreted conditionally as in `@ 2`. * Even when not causing bugs, a mistyped `@` would often influence the __next__ command, causing unexpected behavior, for instance when typing `@(233C)W`. * While it was theoretically possible to set `:` conditionally, it could also be "passed through" accidentally to some command where it wasn't expected as in `:Ifoo$ C`. I do not know of any real useful application or idiom of a conditionally set `:`. If there would happen to be some kind of useful application, `:'` and `:|` could be re-allowed easily, though. * I was condidering introducing a common parser state for modified commands, but that would have been tricky and introduce a lot of redundant command lists. So instead, we now simply everywhere check for excess modifiers. To simplify this task, teco_machine_main_transition_t now contains flags signaling whether the transition is allowed with `@` or `:` modifiers set. It currently only has to be checked in the start state, after `E` and `F`. --- src/parser.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/parser.h') diff --git a/src/parser.h b/src/parser.h index fe8e764..050467c 100644 --- a/src/parser.h +++ b/src/parser.h @@ -544,8 +544,27 @@ gboolean teco_execute_macro(const gchar *macro, gsize macro_len, gboolean teco_execute_file(const gchar *filename, teco_qreg_table_t *qreg_table_locals, GError **error); typedef const struct { + /** next state after receiving the input character */ teco_state_t *next; + /** + * Optional function to call during the state transition. + * + * It is called only in normal execution mode. + */ void (*transition_cb)(teco_machine_main_t *ctx, GError **error); + /** + * Maximum number of `:` modifiers, that \b can be set on the input character. + * + * Colon modifiers are completely ignored in parse-only modes. + */ + guint modifier_colon : 2; + /** + * TRUE if `@`-modifier \b can be set on the input character. + * + * Since `@` has syntactic significance, + * it is checked even in parse-only mode. + */ + bool modifier_at : 1; } teco_machine_main_transition_t; /* -- cgit v1.2.3