diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-09-16 20:38:58 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-09-16 20:38:58 -0700 |
| commit | f35d3c98b22ac3c708672493d27267de071989cd (patch) | |
| tree | 6f49833558ec448768f5c90193d35b7d40c81664 /grammars | |
| parent | 6c237850e90dce317ede7b0d4e53125df15ab62b (diff) | |
Added tons of file and line number stuff
Diffstat (limited to 'grammars')
| -rw-r--r-- | grammars/builtins.bpeg | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/grammars/builtins.bpeg b/grammars/builtins.bpeg index 6ba31df..1191bb4 100644 --- a/grammars/builtins.bpeg +++ b/grammars/builtins.bpeg @@ -1,11 +1,17 @@ # Meta-rules for acting on everything pattern = !(/); # Not defined by default replacement = !(/); # Not defined by default -replace-all = 1+(...@replacement) ...; -find-all = 1+find-next%\n 0-1{!<\n => "\n"}; +replace-all = add-filename 1+(...@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 = 1+(..@pattern) ..$; +matching-line = add-linenum 1+(..@pattern) ..$; + +is-tty = !(/); # Defined as either always-match or always-fail, depending on stdout +print-linenums = 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-linenums (is-tty {=>"\033[2m@#\033[5G|\033[0m "} / {=>"@#| "})); # Helper definitions (commonly used) indent = \n|1+(\t/' '); |
