From fdf662b46eb68aff65d9803c6f421d2e2776be13 Mon Sep 17 00:00:00 2001 From: Oldes Huhuman Date: Wed, 10 Apr 2024 15:33:24 +0200 Subject: [PATCH] FIX: does not allow refinement ending with a colon char resolves: https://github.com/Oldes/Rebol-issues/issues/2281 --- src/boot/strings.reb | 1 + src/core/l-scan.c | 10 +++++++--- src/tests/units/lexer-test.r3 | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/boot/strings.reb b/src/boot/strings.reb index 906f7a1da7..3cf09e00bb 100644 --- a/src/boot/strings.reb +++ b/src/boot/strings.reb @@ -50,6 +50,7 @@ scan: ; Used by scanner. Keep in sync with Value_Types in scan.h file! "issue" "tag" "path" + "ref" "refine" "construct" "map" diff --git a/src/core/l-scan.c b/src/core/l-scan.c index 9fcfa80348..013f02960d 100644 --- a/src/core/l-scan.c +++ b/src/core/l-scan.c @@ -997,7 +997,10 @@ scan_state->begin--; type = TOKEN_REFINE; // Fast easy case: - if (ONLY_LEX_FLAG(flags, LEX_SPECIAL_WORD)) return type; + if (ONLY_LEX_FLAG(flags, LEX_SPECIAL_WORD)) + return type; + if (*(scan_state->end - 1) == ':') + return -type; goto scanword; } if (*cp == '<' || *cp == '>') { @@ -1414,14 +1417,15 @@ np = Skip_Left_Arrow(cp); if (!np) return -type; scan_state->end = np; - return type; } else { np = Skip_Right_Arrow(cp); if (!np) return -type; scan_state->end = np; - return type; } + if (type == TOKEN_REFINE && (*(scan_state->end - 1)) == ':') + type = -type; + return type; } diff --git a/src/tests/units/lexer-test.r3 b/src/tests/units/lexer-test.r3 index d1083a4a64..52e0359754 100644 --- a/src/tests/units/lexer-test.r3 +++ b/src/tests/units/lexer-test.r3 @@ -153,6 +153,10 @@ Rebol [ --assert all [error? e: try [load {%a^^b}] e/id = 'invalid] --assert all [error? e: try [load {%a^^ }] e/id = 'invalid] + --test-- "Invalid refine" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2281 + --assert all [error? e: try [load {/a:}] e/id = 'invalid] + ===end-group===