aboutsummaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-09-19 17:48:00 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-09-19 17:48:00 -0700
commitae7f21b53149b52512dc4cb84aa20847c78526eb (patch)
tree15fc805fb4ebd7c411cd1466c58b411d31177aac /match.c
parent5fa09eb636892a36c4396308d4925077cf94ee3a (diff)
Moved capture retrieval logic into print.c
Diffstat (limited to 'match.c')
-rw-r--r--match.c60
1 files changed, 0 insertions, 60 deletions
diff --git a/match.c b/match.c
index 6471a75..99ef145 100644
--- a/match.c
+++ b/match.c
@@ -2,7 +2,6 @@
// match.c - Code for the BP virtual machine that performs the matching.
//
-#include <ctype.h>
#include <err.h>
#include <limits.h>
#include <stdbool.h>
@@ -30,10 +29,6 @@ static match_t *in_use_matches = NULL;
__attribute__((nonnull(1)))
static inline pat_t *deref(def_t *defs, pat_t *pat);
-__attribute__((nonnull))
-static match_t *get_capture_by_num(match_t *m, int *n);
-__attribute__((nonnull, pure))
-static match_t *get_capture_by_name(match_t *m, const char *name);
__attribute__((hot, nonnull(2,3,4)))
static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool ignorecase);
@@ -562,61 +557,6 @@ static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool
}
//
-// Get a specific numbered pattern capture.
-//
-static match_t *get_capture_by_num(match_t *m, int *n)
-{
- if (*n == 0) return m;
- if (m->pat->type == BP_CAPTURE && *n == 1) return m;
- if (m->pat->type == BP_CAPTURE) --(*n);
- if (m->children) {
- for (int i = 0; m->children[i]; i++) {
- match_t *cap = get_capture_by_num(m->children[i], n);
- if (cap) return cap;
- }
- }
- return NULL;
-}
-
-//
-// Get a capture with a specific name.
-//
-static match_t *get_capture_by_name(match_t *m, const char *name)
-{
- if (m->pat->type == BP_CAPTURE && m->pat->args.capture.name
- && strncmp(m->pat->args.capture.name, name, m->pat->args.capture.namelen) == 0)
- return m;
- if (m->children) {
- for (int i = 0; m->children[i]; i++) {
- match_t *cap = get_capture_by_name(m->children[i], name);
- if (cap) return cap;
- }
- }
- return NULL;
-}
-
-//
-// Get a capture by identifier (name or number).
-// Update *id to point to after the identifier (if found).
-//
-match_t *get_capture(match_t *m, const char **id)
-{
- if (isdigit(**id)) {
- int n = (int)strtol(*id, (char**)id, 10);
- return get_capture_by_num(m, &n);
- } else {
- const char *end = after_name(*id);
- if (end == *id) return NULL;
- char *name = strndup(*id, (size_t)(end-*id));
- match_t *cap = get_capture_by_name(m, name);
- delete(&name);
- *id = end;
- if (**id == ';') ++(*id);
- return cap;
- }
-}
-
-//
// Return a match object which can be used (may be allocated or recycled).
//
match_t *new_match(def_t *defs, pat_t *pat, const char *start, const char *end, match_t *children[])