diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-02-02 17:58:20 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-02-15 01:43:17 +0300 |
commit | 583eddc3bf4c84f1ff7a88d4e3575835264208fa (patch) | |
tree | a9565db5b8a67d5f7bc4ec1a55a5b9e2ed4e717b /src/goto-commands.c | |
parent | 2843ca269cb59bdf9c544fc5dec343bc7430cf3d (diff) | |
download | sciteco-583eddc3bf4c84f1ff7a88d4e3575835264208fa.tar.gz |
redefining labels is a warning now
* Allowing label redefinitions might have been useful when used as comments,
since you will want to be able to define arbitrary comments.
However as flow control constructs, this introduced a certain ambiguity since
gotos might jump to different locations, depending on the progression
of the parser.
* On the other hand, making label redefinition an error might disqualify labels as
comments when writing or porting classic TECO code.
Therefore, it has been made a warning as a compromise.
* Added test case
Diffstat (limited to 'src/goto-commands.c')
-rw-r--r-- | src/goto-commands.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/goto-commands.c b/src/goto-commands.c index ad802e0..b87fc32 100644 --- a/src/goto-commands.c +++ b/src/goto-commands.c @@ -30,6 +30,7 @@ #include "lexer.h" #include "core-commands.h" #include "undo.h" +#include "interface.h" #include "goto.h" #include "goto-commands.h" @@ -62,15 +63,20 @@ teco_state_label_input(teco_machine_main_t *ctx, gunichar chr, GError **error) } if (chr == '!') { - /* - * NOTE: If the label already existed, its PC will be restored - * on rubout. - * Otherwise, the label will be removed (PC == -1). - */ gssize existing_pc = teco_goto_table_set(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len, ctx->macro_pc); + if (existing_pc == ctx->macro_pc) + /* encountered the same label again */ + return &teco_state_start; + if (existing_pc >= 0) { + g_autofree gchar *label_printable = teco_string_echo(ctx->goto_label.data, + ctx->goto_label.len); + teco_interface_msg(TECO_MSG_WARNING, "Ignoring goto label \"%s\" redefinition", + label_printable); + return &teco_state_start; + } if (ctx->parent.must_undo) - teco_goto_table_undo_set(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len, existing_pc); + teco_goto_table_undo_remove(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len); if (teco_goto_skip_label.len > 0 && !teco_string_cmp(&ctx->goto_label, teco_goto_skip_label.data, teco_goto_skip_label.len)) { |