+2022-05-23 Paul Eggert <eggert@cs.ucla.edu>
+
+ dfa: new option DFA_CONFUSING_BRACKETS_ERROR
+ This is for grep, which wants [:alpha:] to be an error
+ at the top level.
+ * lib/dfa.c (struct regex_syntax): New member dfaopts,
+ replacing anchor. All uses changed.
+ (parse_bracket_exp): Error, not warn, if DFA_CONFUSING_BRACKETS_ERROR.
+ * lib/dfa.h (DFA_CONFUSING_BRACKETS_ERROR): New constant.
+
2022-05-21 Paul Eggert <eggert@cs.ucla.edu>
strstr-simple: pacify GCC 12.1
{
/* Syntax bits controlling the behavior of the lexical analyzer. */
reg_syntax_t syntax_bits;
+ int dfaopts;
bool syntax_bits_set;
/* Flag for case-folding letters into sets. */
bool case_fold;
- /* True if ^ and $ match only the start and end of data, and do not match
- end-of-line within data. */
- bool anchor;
-
/* End-of-line byte in data. */
unsigned char eolbyte;
static int
char_context (struct dfa const *dfa, unsigned char c)
{
- if (c == dfa->syntax.eolbyte && !dfa->syntax.anchor)
+ if (c == dfa->syntax.eolbyte && !(dfa->syntax.dfaopts & DFA_ANCHOR))
return CTX_NEWLINE;
if (unibyte_word_constituent (dfa, c))
return CTX_LETTER;
while ((wc = wc1, (c = c1) != ']'));
if (colon_warning_state == 7)
- dfawarn (_("character class syntax is [[:space:]], not [:space:]"));
+ ((dfa->syntax.dfaopts & DFA_CONFUSING_BRACKETS_ERROR
+ ? dfaerror : dfawarn)
+ (_("character class syntax is [[:space:]], not [:space:]")));
if (! known_bracket_exp)
return BACKREF;
dfa->canychar = -1;
dfa->syntax.syntax_bits_set = true;
dfa->syntax.case_fold = (bits & RE_ICASE) != 0;
- dfa->syntax.anchor = (dfaopts & DFA_ANCHOR) != 0;
dfa->syntax.eolbyte = dfaopts & DFA_EOL_NUL ? '\0' : '\n';
dfa->syntax.syntax_bits = bits;
+ dfa->syntax.dfaopts = dfaopts;
for (int i = CHAR_MIN; i <= CHAR_MAX; ++i)
{
DFA_ANCHOR = 1 << 0,
/* '\0' in data is end-of-line, instead of the traditional '\n'. */
- DFA_EOL_NUL = 1 << 1
+ DFA_EOL_NUL = 1 << 1,
+
+ /* Treat [:alpha:] etc. as an error at the top level, instead of
+ merely a warning. */
+ DFA_CONFUSING_BRACKETS_ERROR = 1 << 2,
};
/* Initialize or reinitialize a DFA. The arguments are: