diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-09-16 20:57:59 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-09-16 20:57:59 -0700 |
| commit | 38ed25ce9bf87039a6180e386674d737484c4e39 (patch) | |
| tree | eb3192921eebecd1413708298406c7b7e115e18b /grammars | |
| parent | ae76deaeb2c25a41a71b9e3e1dd92e25abd2677f (diff) | |
Moving more behavior over to definitions
Diffstat (limited to 'grammars')
| -rw-r--r-- | grammars/builtins.bpeg | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/grammars/builtins.bpeg b/grammars/builtins.bpeg index 68a7791..4b200a9 100644 --- a/grammars/builtins.bpeg +++ b/grammars/builtins.bpeg @@ -4,17 +4,21 @@ no = !(/); # Meta-rules for acting on everything pattern = !(/); # Not defined by default replacement = !(/); # Not defined by default -replace-all = add-filename 1+(...@replacement) ...; +replace-all = add-filename 1+(...@hl-replacement) ...; find-all = add-filename 1+find-next%\n 0-1{!<\n => "\n"}; find-next = matching-line / {..\n =>} find-next; -only-matches = 1+{...@pattern=>'@1\n'}; -matching-line = add-linenum 1+(..@pattern) ..$; +only-matches = 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-linenum = 0-1(print-line-numbers (is-tty {=>"\033[2m@#\033[5G|\033[0m "} / {=>"@#| "})); +add-line-number = 0-1(print-line-numbers (is-tty {=>"\033[2m@#\033[5G|\033[0m "} / {=>"@#| "})); +highlight-matches = is-tty; +hl-pattern = { @pattern @0-1{highlight-matches => "\033[1;31m"} @0-1{highlight-matches => "\033[0m"} => "@2@1@3" }; +highlight-replacements = is-tty; +hl-replacement = { @replacement @0-1{highlight-replacements => "\033[1;35m"} @0-1{highlight-replacements => "\033[0m"} => "@2@1@3" }; # Helper definitions (commonly used) indent = \n|1+(\t/' '); |
