From 3a728b28df662af9ad588a9a95c94ce030a3f4dd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 27 Nov 2023 14:20:43 -0500 Subject: Fix "-w" flag and fix optimization for skipping to match --- bp.c | 2 +- match.c | 2 +- pattern.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bp.c b/bp.c index 3b7a843..dce1d4a 100644 --- a/bp.c +++ b/bp.c @@ -599,7 +599,7 @@ int main(int argc, char *argv[]) errx(EXIT_FAILURE, "Couldn't find grammar: %s", flag); defs = load_grammar(defs, f); // Keep in memory for debug output } else if (FLAG("-w") || FLAG("--word")) { - require(asprintf(&flag, "\\|%s\\|", flag), "Could not allocate memory"); + require(asprintf(&flag, "{|}%s{|}", flag), "Could not allocate memory"); file_t *arg_file = spoof_file(&loaded_files, "", flag, -1); delete(&flag); pat_t *p = assert_pat(arg_file->start, arg_file->end, bp_stringpattern(arg_file->start, arg_file->end)); diff --git a/match.c b/match.c index 9a784b3..d821f20 100644 --- a/match.c +++ b/match.c @@ -295,7 +295,7 @@ static pat_t *get_prerequisite(match_ctx_t *ctx, pat_t *pat) case BP_CHAIN: { auto chain = Match(p, BP_CHAIN); // If pattern is something like (|"foo"|), then use "foo" as the first thing to scan for - p = (chain->first->type == BP_WORD_BOUNDARY || chain->first->type == BP_START_OF_LINE) ? chain->second : chain->first; + p = chain->first->max_matchlen == 0 ? chain->second : chain->first; break; } case BP_MATCH: diff --git a/pattern.c b/pattern.c index 150b638..3be5a94 100644 --- a/pattern.c +++ b/pattern.c @@ -504,7 +504,7 @@ maybe_pat_t bp_stringpattern(const char *str, const char *end) while (str < end && *str != '{') str = next_char(str, end); size_t len = (size_t)(str - start); - pat_t *pat = Pattern(BP_STRING, start, str, len, (ssize_t)len, .string=start); + pat_t *pat = len > 0 ? Pattern(BP_STRING, start, str, len, (ssize_t)len, .string=start) : NULL; str += 1; if (str < end) { pat_t *interp = bp_pattern_nl(str, end, true); -- cgit v1.2.3