summaryrefslogtreecommitdiff
path: root/support/regcomp.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2022-04-21 11:00:36 +0300
committerArnold D. Robbins <arnold@skeeve.com>2022-04-21 11:00:36 +0300
commit2b4d1c796f24d1fc2fb09bd1570f859caabda419 (patch)
tree28058720b3f7747065980166d81e7859c731950f /support/regcomp.c
parent1048bef9a1fe499c4f864425b3c75995333a474a (diff)
downloadgawk-2b4d1c796f24d1fc2fb09bd1570f859caabda419.tar.gz
Allow --- in a range to be a single minus.
Diffstat (limited to 'support/regcomp.c')
-rw-r--r--support/regcomp.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/support/regcomp.c b/support/regcomp.c
index b607c853..adfe28e2 100644
--- a/support/regcomp.c
+++ b/support/regcomp.c
@@ -2039,7 +2039,21 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
switch (c)
{
case '-':
- token->type = OP_CHARSET_RANGE;
+ // Special case. V7 Unix grep and Unix awk and mawk allow
+ // [...---...] (3 minus signs in a bracket expression) to represent
+ // a single minus sign. Let's try to support that without breaking
+ // anything else.
+ if (re_string_peek_byte (input, 1) == '-' && re_string_peek_byte (input, 2) == '-')
+ {
+ // advance past the minus signs
+ (void) re_string_fetch_byte (input);
+ (void) re_string_fetch_byte (input);
+
+ token->type = CHARACTER;
+ token->opr.c = '-';
+ }
+ else
+ token->type = OP_CHARSET_RANGE;
break;
case ']':
token->type = OP_CLOSE_BRACKET;