-
Notifications
You must be signed in to change notification settings - Fork 6
/
grammar.ne
170 lines (119 loc) · 4.8 KB
/
grammar.ne
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
main -> Mailbox | Path
@{%
// from https://github.com/jonathantneal/array-flat-polyfill
if (!Array.prototype.flat) {
Object.defineProperty(Array.prototype, 'flat', {
configurable: true,
value: function flat () {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]);
return depth ? Array.prototype.reduce.call(this, function (acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1));
} else {
acc.push(cur);
}
return acc;
}, []) : Array.prototype.slice.call(this);
},
writable: true
});
}
function flat_string(d) {
if (d) {
if (Array.isArray(d))
return d.flat(Infinity).join("");
return d;
}
return "";
}
%}
# Some macros
times_3[X] -> $X $X $X
times_5[X] -> $X $X $X $X $X
times_7[X] -> $X $X $X $X $X $X $X
## https://tools.ietf.org/html/rfc5321#section-4.1.2
Reverse_path -> Path | "<>"
Forward_path -> Path
Path -> "<" ( A_d_l ":" ):? Mailbox ">"
{% function(d) { return d[2]; } %}
A_d_l -> At_domain ( "," At_domain ):*
# Note that this form, the so-called "source
# route", MUST BE accepted, SHOULD NOT be
# generated, and SHOULD be ignored.
At_domain -> "@" Domain
Domain -> sub_domain ("." sub_domain):*
#A_label -> Let_dig (Ldh_str):?
sub_domain -> U_label
Let_dig -> ALPHA_DIGIT {% id %}
Ldh_str -> ALPHA_DIG_DASH:* Let_dig
U_Let_dig -> ALPHA_DIGIT_U {% id %}
U_Ldh_str -> ALPHA_DIG_DASH_U:* U_Let_dig
U_label -> U_Let_dig (U_Ldh_str):?
address_literal -> "[" ( IPv4_address_literal |
IPv6_address_literal |
General_address_literal ) "]"
# See Section 4.1.3
non_local_part -> Domain | address_literal
Mailbox -> Local_part "@" non_local_part {%
function(d) {
return { local_part: flat_string(d[0]), domain: flat_string(d[2]), };
}
%}
Local_part -> Dot_string | Quoted_string
# MAY be case-sensitive
Dot_string -> Atom ("." Atom):*
# 1*atext
Atom -> [0-9A-Za-z!#$%&'*+\-/=?^_`{|}~\u0080-\uFFFF/]:+
Quoted_string -> DQUOTE QcontentSMTP:* DQUOTE
QcontentSMTP -> qtextSMTP | quoted_pairSMTP
quoted_pairSMTP -> "\\" [\x20-\x7e]
# i.e., backslash followed by any ASCII
# graphic (including itself) or SPace
qtextSMTP -> [\x20-\x21\x23-\x5b\x5d-\x7e\u0080-\uFFFF] {% id %}
# i.e., within a quoted string, any
# ASCII graphic or space is permitted
# without blackslash-quoting except
# double-quote and the backslash itself.
## https://tools.ietf.org/html/rfc5321#section-4.1.3
IPv4_address_literal -> Snum times_3["." Snum]
IPv6_address_literal -> "IPv6:"i IPv6_addr
General_address_literal -> Standardized_tag ":" dcontent:+
Standardized_tag -> Ldh_str
# Standardized_tag MUST be specified in a
# Standards_Track RFC and registered with IANA
dcontent -> [\x21-\x5a\x5e-\x7e] {% id %}
# Printable US_ASCII
# excl. "[", "\", "]"
Snum -> DIGIT |
( [1-9] DIGIT ) |
( "1" DIGIT DIGIT ) |
( "2" [0-4] DIGIT ) |
( "2" "5" [0-5] )
# representing a decimal integer
# value in the range 0 through 255
IPv6_addr -> IPv6_full | IPv6_comp | IPv6v4_full | IPv6v4_comp
# HEXDIG:? HEXDIG:? HEXDIG:? HEXDIG
IPv6_hex -> HEXDIG |
( HEXDIG HEXDIG ) |
( HEXDIG HEXDIG HEXDIG ) |
( HEXDIG HEXDIG HEXDIG HEXDIG )
IPv6_full -> IPv6_hex times_7[":" IPv6_hex]
IPv6_comp -> (IPv6_hex times_5[":" IPv6_hex]):? "::"
(IPv6_hex times_5[":" IPv6_hex]):?
# The "::" represents at least 2 16_bit groups of
# zeros. No more than 6 groups in addition to the
# "::" may be present.
IPv6v4_full -> IPv6_hex times_5[":" IPv6_hex] ":" IPv4_address_literal
IPv6v4_comp -> (IPv6_hex times_3[":" IPv6_hex]):? "::"
(IPv6_hex times_3[":" IPv6_hex] ":"):?
IPv4_address_literal
# The "::" represents at least 2 16_bit groups of
# zeros. No more than 4 groups in addition to the
# "::" and IPv4_address_literal may be present.
DIGIT -> [0-9] {% id %}
ALPHA_DIGIT_U -> [0-9A-Za-z\u0080-\uFFFF] {% id %}
ALPHA_DIGIT -> [0-9A-Za-z] {% id %}
ALPHA_DIG_DASH -> [-0-9A-Za-z] {% id %}
ALPHA_DIG_DASH_U -> [-0-9A-Za-z\u0080-\uFFFF] {% id %}
HEXDIG -> [0-9A-Fa-f] {% id %}
DQUOTE -> "\"" {% id %}