aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-11-06 23:50:09 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-11-06 23:50:09 +0300
commit5f141848b88237959bd01603b427b792828d73ad (patch)
tree00234fbf9cc14ae55ee34650001d7623f8a67a71 /src/parser.h
parent9242405c8fc31b869fecfe096f29eb1a2ca75bda (diff)
downloadsciteco-5f141848b88237959bd01603b427b792828d73ad.tar.gz
fixed the Q-Reg spec machine used for implementing S^EGq$ (match one of characters in Q-Register)
* It was initialized only once, so it could inherit the wrong local Q-Register table. A test case has been added for this particular bug. * Also, if starting from the profile (batch mode), the state machine could be initialized without undo, which then later cause problems on rubout in interactive mode. For instance, if S^EG[a] fails and you would repeatedly type `]`, the Q-Reg name could grow indefinitely. There were probably other issues as well. Even crashes should have been possible, although I couldn't reproduce them. * Since the state machine is required only for the pattern to regexp translation and is performed anew for every character in interactive mode, we now create a fresh state machine for every call and don't attempt any undo. There might be more efficient ways, like reusing the string building's Q-Reg parser state machine.
Diffstat (limited to 'src/parser.h')
-rw-r--r--src/parser.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/parser.h b/src/parser.h
index 659e9f9..53eb76b 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -301,8 +301,9 @@ teco_machine_init(teco_machine_t *ctx, teco_state_t *initial, gboolean must_undo
static inline void
teco_machine_reset(teco_machine_t *ctx, teco_state_t *initial)
{
- if (ctx->current != initial)
- teco_undo_ptr(ctx->current) = initial;
+ if (ctx->must_undo && ctx->current != initial)
+ teco_undo_ptr(ctx->current);
+ ctx->current = initial;
}
gboolean teco_machine_input(teco_machine_t *ctx, gunichar chr, GError **error);