diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-12-12 16:31:53 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-12-12 16:31:53 -0800 |
| commit | eb329bdac9fe56d67cb130fb6cdbb28743c6504b (patch) | |
| tree | 8ba8bded07820519de06728618e4e32e80da3af4 /grammars/builtins.bp | |
| parent | 6e1fd928148cc7e46015e06c27f824d4111f96ee (diff) | |
Bunch of changes, including some bpeg->bp renaming, and adding
visualizations
Diffstat (limited to 'grammars/builtins.bp')
| -rw-r--r-- | grammars/builtins.bp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/grammars/builtins.bp b/grammars/builtins.bp new file mode 100644 index 0000000..7de936f --- /dev/null +++ b/grammars/builtins.bp @@ -0,0 +1,84 @@ +yes: '' +no: !'' + +# Configurable options: +is-tty: no # Defined as either always-match or always-fail, depending on stdout +include-binary-files: no; +is-text-file: ^^ >32(\t/\n/\r/\x20-x7e/!\x00-x7f utf8-codepoint/$$) + +# Meta-rules for acting on everything: +pattern: !'' # Not defined by default +replacement: !'' # Not defined by default +replace-all: ( + (include-binary-files / is-text-file) + +(...(>pattern replacement)) ... +) +find-all: ( + (include-binary-files / is-text-file) + *(!..pattern ~(..\n)) + +(+(..@pattern) ..(\n/$$) / ~(..\n)) + [{!<\n => "\n"}] +) +only-matches: ( + (include-binary-files / is-text-file) + +{...@pattern =>'@1\n'} +) + +# Helper definitions (commonly used) +url: ( + "file://" +(`/ *url-char) + / "mailto:" email + / ("https"/"http"/"ftp") "://" [>..`@ +url-char [`: +url-char] `@] + (ipv4/ipv6/domain) [`: int] [url-path] +) +url-path: +(`/ *url-char) [`? +(+url-char`=+url-char)%`&] +ipv4: 4 int % `. +ipv6: 8 (4 Hex) % `: +domain: +(+(Abc/digit/`-))%`. +url-char: Abc/digit/`$/`-/`_/`./`+/`!/`*/`'/`(/`)/`,/`% +email: +(Abc/digit/`./`-/`+) `@ domain + +nodent: | !(\t/` ) +indent: | (` /\t) +dedent: $ !(nodent/indent) +utf8-codepoint: ( + \x00-x7f + / \xc0-xdf 1\x80-xbf + / \xe0-xef 2\x80-xbf + / \xf0-xf7 3\x80-xbf +) +crlf: \r\n +cr: \r +anglebraces: `< *(anglebraces / $. != `>) `> +brackets: `[ *(brackets / $. != `]) `] +braces: `{ *(braces / $. != `}) `} +parens: `( *(parens / $. != `)) `) +id: !<(`a-z/`A-Z/`_/`0-9) (`a-z/`A-Z/`_) *(`a-z/`A-Z/`_/`0-9) +id-char: `a-z/`A-Z/`_/`0-9 +word: !<(`a-z/`A-Z/`_/`0-9) +(`a-z/`A-Z) !>(`0-9/`_) +edge: !<(`a-z/`A-Z/`_/`0-9) / !>(`0-9/`_) +HEX: `0-9/`A-F +Hex: `0-9/`a-f/`A-F +hex: `0-9/`a-f +number: +`0-9 [`. *`0-9] / `. +`0-9 +int: +`0-9 +digit: `0-9 +Abc: `a-z/`A-Z +ABC: `A-Z +abc: `a-z +esc: \e +tab: \t +nl: \n; lf: \n +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 +$$: !$. +$: !. +^^: !<$. +^: !<. +__: *(` /\t/\n/\r/comment) +_: *(` /\t) |
