2020-09-16 22:36:38 -07:00
|
|
|
yes: ''
|
|
|
|
no: !''
|
2020-09-16 20:41:38 -07:00
|
|
|
|
2020-09-16 21:43:12 -07:00
|
|
|
# Configurable options:
|
2020-09-16 22:36:38 -07:00
|
|
|
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
|
2020-09-18 22:32:36 -07:00
|
|
|
include-binary-files: no;
|
|
|
|
is-text-file: ^^ >32(\t/\n/\r/\x20-x7e/!\x00-x7f utf8-codepoint/$$)
|
2020-09-16 21:43:12 -07:00
|
|
|
|
|
|
|
# Meta-rules for acting on everything:
|
2020-09-16 22:36:38 -07:00
|
|
|
pattern: !'' # Not defined by default
|
|
|
|
replacement: !'' # Not defined by default
|
2020-09-18 22:32:36 -07:00
|
|
|
replace-all: (
|
|
|
|
(include-binary-files / is-text-file)
|
|
|
|
define-highlights
|
|
|
|
add-filename
|
2020-09-24 22:09:07 -07:00
|
|
|
0+(...(>pattern hl-replacement)) ...
|
2020-09-18 22:32:36 -07:00
|
|
|
)
|
|
|
|
find-all: (
|
|
|
|
(include-binary-files / is-text-file)
|
|
|
|
define-highlights
|
|
|
|
add-filename
|
2020-09-24 22:06:17 -07:00
|
|
|
0+ (!..pattern {..\n=>})
|
|
|
|
1+ (>..pattern add-line-number 1+(..hl-pattern) ..\n / {..\n=>})
|
|
|
|
0-1{!<\n => "\n"}
|
2020-09-18 22:32:36 -07:00
|
|
|
)
|
|
|
|
only-matches: (
|
|
|
|
(include-binary-files / is-text-file)
|
|
|
|
define-highlights
|
|
|
|
add-filename
|
|
|
|
1+{...@hl-pattern=>'@1\n'}
|
|
|
|
)
|
2020-09-16 22:36:38 -07:00
|
|
|
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 "} / {=>"@#| "}))
|
|
|
|
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]""
|
2020-09-12 18:20:13 -07:00
|
|
|
|
|
|
|
# Helper definitions (commonly used)
|
2020-09-16 22:36:38 -07:00
|
|
|
indent: \n|1+(\t/' ')
|
|
|
|
dedent: $ !(\n|)
|
|
|
|
indented-block: |` ..$ 0+(\n|..$)
|
2020-09-18 22:32:36 -07:00
|
|
|
utf8-codepoint: (
|
|
|
|
\x00-x7f
|
|
|
|
/ \xc0-xdf 1\x80-xbf
|
|
|
|
/ \xe0-xef 2\x80-xbf
|
|
|
|
/ \xf0-xf7 3\x80-xbf
|
|
|
|
)
|
2020-09-16 22:36:38 -07:00
|
|
|
crlf: \r\n
|
2020-09-28 15:13:54 -07:00
|
|
|
cr: \r
|
2020-09-24 22:12:14 -07:00
|
|
|
anglebraces: `< 0+(anglebraces / !`>$.) `>
|
|
|
|
brackets: `[ 0+(brackets / !`]$.) `]
|
|
|
|
braces: `{ 0+(braces / !`}$.) `}
|
|
|
|
parens: `( 0+(parens / !`)$.) `)
|
2020-09-16 22:36:38 -07:00
|
|
|
id: !<(`a-z/`A-Z/`_/`0-9) (`a-z/`A-Z/`_) 0+(`a-z/`A-Z/`_/`0-9)
|
|
|
|
id-char: `a-z/`A-Z/`_/`0-9
|
|
|
|
word: !<(`a-z/`A-Z/`_/`0-9) 1+(`a-z/`A-Z) !>(`0-9/`_)
|
|
|
|
HEX: `0-9/`A-F
|
|
|
|
Hex: `0-9/`a-f/`A-F
|
|
|
|
hex: `0-9/`a-f
|
|
|
|
number: 1+`0-9 0-1(`. 0+`0-9) / `. 1+`0-9
|
|
|
|
int: 1+`0-9
|
|
|
|
digit: `0-9
|
|
|
|
Abc: `a-z/`A-Z
|
|
|
|
ABC: `A-Z
|
|
|
|
abc: `a-z
|
2020-09-28 15:13:54 -07:00
|
|
|
esc: \e
|
|
|
|
tab: \t
|
|
|
|
nl: \n; lf: \n
|
2020-09-16 22:36:38 -07:00
|
|
|
c-block-comment: '/*' ... '*/'
|
|
|
|
c-line-comment: '//' ..$
|
|
|
|
c-comment: c-line-comment / c-block-comment
|
|
|
|
hash-comment: `# ..$
|
|
|
|
comment: !''; # No default definition, can be overridden
|
|
|
|
WS: ` /\t/\n/\r/comment
|
|
|
|
ws: ` /\t
|
|
|
|
$$: !$.
|
|
|
|
$: !.
|
|
|
|
^^: !<$.
|
|
|
|
^: !<.
|
|
|
|
__: 0+(` /\t/\n/\r/comment)
|
|
|
|
_: 0+(` /\t)
|