aboutsummaryrefslogtreecommitdiff
path: root/grammars/builtins.bp
blob: fcc1f206e5ef34843571403bed60840448c471a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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

# 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: \N !(\t/` )
indent: \N (` /\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: `<..`> % (\n/anglebraces/string)
brackets: `[..`] % (\n/brackets/string)
braces: `{..`} % (\n/braces/string)
parens: `(..`) % (\n/parens/string)
string: `"..`" % (`\.) / `'..`' % (`\.)
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,_
|: !<`a-z,A-Z,_,0-9 / !>`a-z,A-Z,_,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: '/*'..'*/'%\n
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
$$: !(./\n)
$:  !.
^^: !<(./\n)
^:  !<.
__: *(` /\t/\n/\r/comment)
_:  *(` /\t)