aboutsummaryrefslogtreecommitdiff
path: root/grammars
diff options
context:
space:
mode:
Diffstat (limited to 'grammars')
-rw-r--r--grammars/builtins.bpeg25
1 files changed, 13 insertions, 12 deletions
diff --git a/grammars/builtins.bpeg b/grammars/builtins.bpeg
index 4b8c07b..8abb550 100644
--- a/grammars/builtins.bpeg
+++ b/grammars/builtins.bpeg
@@ -1,24 +1,25 @@
yes = (/);
no = !(/);
-# Meta-rules for acting on everything
+# Configurable options:
+is-tty = no; # Defined as either always-match or always-fail, depending on stdout
+print-line-numbers = is-tty;
+print-filenames = is-tty;
+highlight = is-tty;
+
+# Meta-rules for acting on everything:
pattern = !(/); # Not defined by default
replacement = !(/); # Not defined by default
-replace-all = add-filename 1+(...@hl-replacement) ...;
-find-all = add-filename 1+find-next%\n 0-1{!<\n => "\n"};
+replace-all = define-highlights add-filename 1+(...@hl-replacement) ...;
+find-all = define-highlights add-filename 1+find-next%\n 0-1{!<\n => "\n"};
find-next = matching-line / {..\n =>} find-next;
-only-matches = 1+{...@hl-pattern=>'@1\n'};
+only-matches = define-highlights 1+{...@hl-pattern=>'@1\n'};
matching-line = add-line-number 1+(..hl-pattern) ..$;
-
-is-tty = no; # Defined as either always-match or always-fail, depending on stdout
-print-line-numbers = is-tty;
-print-filenames = is-tty;
add-filename = 0-1(print-filenames (is-tty {=>"\033[33;1;4m@&:\033[0m\n"} / {=>"@&:\n"}));
add-line-number = 0-1(print-line-numbers (is-tty {=>"\033[2m@#\033[5G|\033[0m "} / {=>"@#| "}));
-highlight-matches = is-tty;
-hl-pattern = {@[match]pattern (highlight-matches @{=>"\033[1;31m"} @{=>"\033[0m"} / @"" @"") => "@2@1@3"};
-highlight-replacements = is-tty;
-hl-replacement = { @replacement (highlight-replacements @{=>"\033[1;35m"} @{=>"\033[0m"} / @"" @"") => "@2@1@3" };
+hl-pattern = {@[match]pattern define-highlights => "@[hl-start]@[match]@[hl-end]"};
+hl-replacement = {@[match]replacement define-highlights => "@[hl-start]@[match]@[hl-end]" };
+define-highlights = highlight @[hl-start]{=>"\033[31;1m"} @[hl-end]{=>"\033[0m"} / @[hl-start]"" @[hl-end]"";
# Helper definitions (commonly used)
indent = \n|1+(\t/' ');