From 744a92756200052837e25f4f7758175241528536 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 23 Sep 2021 13:42:23 -0700 Subject: [PATCH] Deprecated (!)-errors --- bp.1 | 8 -------- bp.1.md | 7 ------- bp.c | 3 --- grammars/bp.bp | 37 ++++++++++++++++++------------------- match.c | 4 ---- pattern.c | 10 ---------- print.c | 20 -------------------- print.h | 2 -- 8 files changed, 18 insertions(+), 73 deletions(-) diff --git a/bp.1 b/bp.1 index 403a952..ab58915 100644 --- a/bp.1 +++ b/bp.1 @@ -329,14 +329,6 @@ not contain the word \f[B]\[lq]IGNORE\[rq]\f[R]) \f[I]name\f[R]\f[B]:\f[R] \f[I]pat\f[R] Define \f[I]name\f[R] to mean \f[I]pat\f[R] (pattern definition) .TP -\f[B](!)\f[R] \f[I]error-pat\f[R] -If \f[I]error-pat\f[R] matches, \f[B]bp\f[R] will not print any results -in this file and instead print an error message to \f[B]STDERR\f[R] -highlighting the matching position of \f[I]error-pat\f[R] in the file -and printing the text of \f[I]error-pat\f[R] as an error message. -Then, \f[B]bp\f[R] will exit with a failure status and not process any -further files. -.TP \f[B]#\f[R] \f[I]comment\f[R] A line comment .SH GRAMMAR FILES diff --git a/bp.1.md b/bp.1.md index 87892c9..782c84f 100644 --- a/bp.1.md +++ b/bp.1.md @@ -280,13 +280,6 @@ contain the word **"IGNORE"**) *name*`:` *pat* : Define *name* to mean *pat* (pattern definition) -`(!)` *error-pat* -: If *error-pat* matches, **bp** will not print any results in this file and -instead print an error message to **STDERR** highlighting the matching position -of *error-pat* in the file and printing the text of *error-pat* as an error -message. Then, **bp** will exit with a failure status and not process any -further files. - `#` *comment* : A line comment diff --git a/bp.c b/bp.c index 08cde5c..8937cf7 100644 --- a/bp.c +++ b/bp.c @@ -240,9 +240,6 @@ static int print_matches(FILE *out, def_t *defs, file_t *f, pat_t *pattern) }; for (match_t *m = NULL; next_match(&m, defs, f, pattern, options.skip, options.ignorecase); ) { - if (print_errors(f, m) > 0) - exit(EXIT_FAILURE); - if (++matches == 1 && options.print_filenames) { if (printed_filenames++ > 0) printf("\n"); fprint_filename(out, f->filename); diff --git a/grammars/bp.bp b/grammars/bp.bp index 2b0f4f9..d0a9474 100644 --- a/grammars/bp.bp +++ b/grammars/bp.bp @@ -5,11 +5,11 @@ # The grammar files provided with BP are not otherwise intended to be full # language grammars. -Grammar: __ *(Def [__`;])%__ __ [(!)(+(./\n) => "Could not parse this code")] +Grammar: __ *(Def [__`;])%__ __ [@error=(+(./\n) => "Could not parse this code")] Def: @name=id __ `: __ ( @definition=extended-pat - / $$ (!)=>"No definition for rule" - / (!)(..%\n>(`;/id_`:/$) => "Invalid definition: @0")) + / $$ @error=(=>"No definition for rule") + / @error=(..%\n>(`;/id_`:/$) => "Invalid definition: @0")) # This is used for command line arguments: String-pattern: ..%(\n / Nodent / Identifier-char / Identifier-start / Escape / `\ pat [`;])$$ @@ -17,7 +17,7 @@ String-pattern: ..%(\n / Nodent / Identifier-char / Identifier-start / Escape / pat: simple-pat !(__("!~"/"~")) / suffixed-pat simple-pat: (Upto-and / Dot / Word-boundary/ String / Chars / Nodent / Identifier-char / Identifier-start / Escape-range - / Escape / Repeat / Optional / No / After / Before / Capture / Error / Empty-replacement + / Escape / Repeat / Optional / No / After / Before / Capture / Empty-replacement / Start-of-File / Start-of-Line / End-of-File / End-of-Line / Ref / parens) suffixed-pat: ( @@ -25,28 +25,28 @@ suffixed-pat: ( / Not-match-pat ) -Match-pat: @first=(suffixed-pat / simple-pat)__"~"__@second=(pat / (!)=>"Expected pattern after '~'") -Not-match-pat: @first=(suffixed-pat / simple-pat)__"!~"__@second=(pat / (!)=>"Expected pattern after '!~'") +Match-pat: @first=(suffixed-pat / simple-pat)__"~"__@second=(pat / @error=(=>"Expected pattern after '~'")) +Not-match-pat: @first=(suffixed-pat / simple-pat)__"!~"__@second=(pat / @error=(=>"Expected pattern after '!~'")) Dot: `. !`. String: ( - `" @s=.. (`" / $ (!)=>"Expected closing quote here") - / `' @s=.. (`' / $ (!)=>"Expected closing quote here") + `" @s=.. (`" / $ @error=(=>"Expected closing quote here")) + / `' @s=.. (`' / $ @error=(=>"Expected closing quote here")) ) Chars: `` @+(Char-range/Char) % `, -Char-range: @low=. `- (@high=. / (!)=>"Expected a second character to form a character range") -Char: (@s=. / (!)=>"Expected a character following the '`'") +Char-range: @low=. `- (@high=. / @error=(=>"Expected a second character to form a character range")) +Char: (@s=. / @error=(=>"Expected a character following the '`'")) Escape-range: `\ @low=escape-sequence `- @high=escape-sequence Escape: `\ (@s=escape-sequence - / $ (!)=>"Backslashes are used for escape sequences, not splitting lines" - / (!)(. *(Abc/`0-9) => "Invalid escape sequence: '@0'") + / $ @error=(=>"Backslashes are used for escape sequences, not splitting lines") + / @error=(. *(Abc/`0-9) => "Invalid escape sequence: '@0'") ) escape-sequence: ( `n,t,r,e,b,a,v / 1-3 `0-7 / `x 2 `0-9,a-f,A-F ) -No: `! (__@pat / (!)=>"Expected a pattern after the exclamation mark") +No: `! (__@pat / @error=(=>"Expected a pattern after the exclamation mark")) Nodent: "\N" Word-boundary: `| / "\b" Identifier-char: "\i" @@ -58,16 +58,15 @@ Repeat: ( / @min=(int / =>'1') __ (`+=>"-") @max=(=>'∞') / @min=@max=int ) __ @repeat-pat=pat [__`%__@sep=pat] -Optional: `[ __ extended-pat (__`] / (!)=>"Expected closing square bracket here") +Optional: `[ __ extended-pat (__`] / @error=(=>"Expected closing square bracket here")) After: `< __ pat Before: `> __ pat -Capture: `@ [__ @capture-name=(id/`!) __ !"=>" `=] __ (@capture=pat / (!)=>"Expected pattern to capture") -Error: "(!)" @pat=[__ (Replace / Chain / pat)] +Capture: `@ [__ @capture-name=(id/`!) __ !"=>" `=] __ (@capture=pat / @error=(=>"Expected pattern to capture")) Replace: ( - @replace-pat=(Replace / Chain / pat) __ "=>" (__ @replacement=String / (!)=>"Expected replacement string") + @replace-pat=(Replace / Chain / pat) __ "=>" (__ @replacement=String / @error=(=>"Expected replacement string")) ) Empty-replacement: ( - @replace-pat=(=>"''") "=>" (__ @replacement=String / (!)=>"Expected replacement string") + @replace-pat=(=>"''") "=>" (__ @replacement=String / @error=(=>"Expected replacement string")) ) Ref: @name=id !(__`:) Start-of-File: "^^" @@ -75,7 +74,7 @@ Start-of-Line: "^" End-of-File: "$$" End-of-Line: "$" -parens: `( __ extended-pat (__ `) / (!)=>"Expected closing parenthesis here") +parens: `( __ extended-pat (__ `) / @error=(=>"Expected closing parenthesis here")) Chain: 2+@(pat !(__"=>") / Replace)%__ Otherwise: 2+@(Replace / Chain / pat)%(__`/__) diff --git a/match.c b/match.c index da0f787..9644dc0 100644 --- a/match.c +++ b/match.c @@ -661,10 +661,6 @@ static match_t *match(def_t *defs, cache_t *cache, file_t *f, const char *str, p return new_match(defs, pat, start, &str[dents], NULL); } - case BP_ERROR: { - match_t *p = pat->args.pat ? match(defs, cache, f, str, pat->args.pat, ignorecase) : NULL; - return p ? new_match(defs, pat, str, p->end, MATCHES(p)) : NULL; - } default: { errx(EXIT_FAILURE, "Unknown pattern type: %u", pat->type); return NULL; diff --git a/pattern.c b/pattern.c index 28a4ecf..50759d0 100644 --- a/pattern.c +++ b/pattern.c @@ -379,16 +379,6 @@ static pat_t *_bp_simplepattern(file_t *f, const char *str) } // Parentheses case '(': { - if (start + 2 < f->end && strncmp(start, "(!)", 3) == 0) { // (!) errors - str = start + 3; - pat_t *pat = bp_simplepattern(f, str); - if (!pat) pat = new_pat(f, str, str, 0, 0, BP_STRING); - pat = expand_replacements(f, pat, false); - pat_t *error = new_pat(f, start, pat->end, pat->min_matchlen, pat->max_matchlen, BP_ERROR); - error->args.pat = pat; - return error; - } - pat_t *pat = bp_pattern_nl(f, str, true); if (!pat) file_err(f, str, str, "There should be a valid pattern after this parenthesis."); diff --git a/print.c b/print.c index dcebce9..dfe099f 100644 --- a/print.c +++ b/print.c @@ -266,24 +266,4 @@ void print_match(FILE *out, printer_t *pr, match_t *m) if (pr->use_color) fprintf(out, "%s", color_normal); } -// -// Print any errors that are present in the given match object to stderr and -// return the number of errors found. -// -int print_errors(file_t *f, match_t *m) -{ - int ret = 0; - if (m->pat->type == BP_ERROR) { - fprintf(stderr, "\033[31;1m"); - printer_t tmp = {.file = f, .context_before=NO_CONTEXT, .context_after=NO_CONTEXT}; // No bells and whistles - print_match(stderr, &tmp, m); // Error message - fprintf(stderr, "\033[m\n"); - fprint_line(stderr, f, m->start, m->end, " "); - return 1; - } - for (int i = 0; m->children && m->children[i]; i++) - ret += print_errors(f, m->children[i]); - return ret; -} - // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/print.h b/print.h index 2d5cc5c..70427a4 100644 --- a/print.h +++ b/print.h @@ -24,8 +24,6 @@ typedef struct { __attribute__((nonnull(1,2))) void print_match(FILE *out, printer_t *pr, match_t *m); -__attribute__((nonnull)) -int print_errors(file_t *f, match_t *m); #endif // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0