From 21ace5e5c7c98271d78ff9cdf2b61e3ac70704d8 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 5 Oct 2022 21:34:59 +0200 Subject: lexer: fixes for regex literal parsing - Ensure that regexp extension escapes are consistently handled; substitute `\d`, `\D`, `\s`, `\S`, `\w` and `\W` with `[[:digit:]]`, `[^[:digit:]]`, `[[:space:]]`, `[^[:space:]]`, `[[:alnum:]_]` and `[^[:alnum:]_]` character classes respectively since not all POSIX regexp implementations implement all of those extensions - Preserve `\b`, `\B`, `\<` and `\>` boundary matches Fixes: a45f2a3 ("lexer: improve regex literal handling") Signed-off-by: Jo-Philipp Wich --- tests/custom/00_syntax/21_regex_literals | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tests/custom/00_syntax') diff --git a/tests/custom/00_syntax/21_regex_literals b/tests/custom/00_syntax/21_regex_literals index 7466a2e..44f0079 100644 --- a/tests/custom/00_syntax/21_regex_literals +++ b/tests/custom/00_syntax/21_regex_literals @@ -4,7 +4,7 @@ within regular expression literals is subject of the underlying regular expression engine. -- Expect stdout -- -[ "/Hello world/", "/test/gis", "/test/g", "/test1 / test2/", "/1\n\\.\u0007\bc☀\\\\/" ] +[ "/Hello world/", "/test/gis", "/test/g", "/test1 / test2/", "/1\n\\.\u0007\\bc☀\\\\/" ] -- End -- -- Testcase -- @@ -117,3 +117,30 @@ literal delimitters. ]); %} -- End -- + + +Testing that regex extension macros are substituted only outside of +bracket set expressions. + +-- Expect stdout -- +[ + "/ \\b \\B [\b B] /", + "/ \\< \\> [< >] /", + "/ [[:digit:]] [^[:digit:]] [d D] /", + "/ [[:space:]] [^[:space:]] [s S] /", + "/ [[:alnum:]_] [^[:alnum:]_] [w W] /" +] +-- End -- + +-- Testcase -- +{% + printf("%.J\n", [ + / \b \B [\b \B] /, // \b outside brackets is a word boundary, + // \b within brackets is backspace + / \< \> [\< \>] /, + / \d \D [\d \D] /, + / \s \S [\s \S] /, + / \w \W [\w \W] / + ]); +%} +-- End -- -- cgit v1.2.3