bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3] dfa: new option DFA_CONFUSING_BRACKETS_ERROR


From: Paul Eggert
Subject: [PATCH 1/3] dfa: new option DFA_CONFUSING_BRACKETS_ERROR
Date: Mon, 23 May 2022 12:19:10 -0700

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.
---
 ChangeLog | 10 ++++++++++
 lib/dfa.c | 13 ++++++-------
 lib/dfa.h |  6 +++++-
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 327100aaf1..407baca335 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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
diff --git a/lib/dfa.c b/lib/dfa.c
index 5f290ec58e..ba21639521 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -399,15 +399,12 @@ struct regex_syntax
 {
   /* 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;
 
@@ -836,7 +833,7 @@ unibyte_word_constituent (struct dfa const *dfa, unsigned 
char c)
 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;
@@ -1140,7 +1137,9 @@ parse_bracket_exp (struct dfa *dfa)
   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;
@@ -4327,9 +4326,9 @@ dfasyntax (struct dfa *dfa, struct localeinfo const 
*linfo,
   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)
     {
diff --git a/lib/dfa.h b/lib/dfa.h
index e94e43546d..327b9c7cdf 100644
--- a/lib/dfa.h
+++ b/lib/dfa.h
@@ -73,7 +73,11 @@ enum
     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:
-- 
2.36.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]