git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/2] grep: extract grep_binexp() from grep_or_expr()

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 6, 2022, 22:42 UTC
Message-ID
<dae476d1bd14608358b6c103e2b5dda76d294687.1641508884.git.me@ttaylorr.com>
In-Reply-To
<cover.1641508884.git.me@ttaylorr.com>

When constructing an OR node, the grep.c code uses `grep_or_expr()` to make a node, assign its kind, and set its left and right children. The same is not done for AND nodes.

Prepare to introduce a new `grep_and_expr()` function which will share code with the existing implementation of `grep_or_expr()` by introducing a new function which compiles either kind of binary expression, and reimplement `grep_or_expr()` in terms of it.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 grep.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/grep.c b/grep.c
index bdbd06d437..d772fe6cc5 100644
--- a/grep.c
+++ b/grep.c
@@ -603,15 +603,22 @@ static struct grep_expr *grep_not_expr(struct grep_expr *expr)
 	return z;
 }
 
-static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+static struct grep_expr *grep_binexp(enum grep_expr_node kind,
+				     struct grep_expr *left,
+				     struct grep_expr *right)
 {
 	struct grep_expr *z = xcalloc(1, sizeof(*z));
-	z->node = GREP_NODE_OR;
+	z->node = kind;
 	z->u.binary.left = left;
 	z->u.binary.right = right;
 	return z;
 }
 
+static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+{
+	return grep_binexp(GREP_NODE_OR, left, right);
+}
+
 static struct grep_expr *compile_pattern_or(struct grep_pat **);
 static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
 {
-- 
2.34.1.455.gd6eb6fd089
Previous: Taylor BlauNext: Taylor Blau
Message 9 of 13 in “grep: use grep_or_expr() in compile_pattern_or()”
  1. 1/2 grep: use grep_or_expr() in compile_pattern_or()René Scharfe, Jan 6, 2022
  2. 2/2 grep: use grep_not_expr() in compile_pattern_not()René Scharfe, Jan 6, 2022
  3. 0/2 grep: introduce and use grep_and_expr()Taylor Blau, Jan 6, 2022
  4. 1/2 grep: extract grep_binexp() from grep_or_expr()Taylor Blau, Jan 6, 2022
  5. 2/2 grep: use grep_and_expr() in compile_pattern_and()Taylor Blau, Jan 6, 2022
  6. Junio C HamanoJan 6, 2022
  7. Taylor BlauJan 6, 2022
  8. 0/2 grep: introduce and use grep_and_expr()Taylor Blau, Jan 6, 2022
  9. 1/2 grep: extract grep_binexp() from grep_or_expr()Taylor Blau, Jan 6, 2022
  10. 2/2 grep: use grep_and_expr() in compile_pattern_and()Taylor Blau, Jan 6, 2022
  11. René ScharfeJan 7, 2022
  12. Taylor BlauJan 7, 2022
  13. René ScharfeJan 7, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.