/
URI.pm
96 lines (73 loc) · 2.94 KB
/
URI.pm
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
use v6;
# Taken/Copied with relatively minor translation to Perl6
# from RFC 3986 (http://www.ietf.org/rfc/rfc3986.txt)
# Rule names moved from snake case with _ to kebab case with -
# 9/2015. The rfc grammar is specified in kebab case.
use IETF::RFC_Grammar::IPv6;
unit grammar IETF::RFC_Grammar::URI:ver<0.02> is IETF::RFC_Grammar::IPv6;
token TOP { <URI-reference> };
token TOP-non-empty { <URI> | <relative-ref-non-empty> };
token URI-reference { <URI> | <relative-ref> };
token absolute-URI { <scheme> ':' <.hier-part> [ '?' query ]? };
token relative-ref {
<relative-part> [ '?' <query> ]? [ '#' <fragment> ]?
};
token relative-part {
| <?[/]> '//' <authority> <path-abempty>
| <path-absolute>
| <path-noscheme>
| <path-empty>
};
token relative-ref-non-empty {
<relative-part-non-empty> [ '?' <query> ]? [ '#' <fragment> ]?
};
token relative-part-non-empty {
| <?[/]> '//' <authority> <path-abempty>
| <path-absolute>
| <path-noscheme>
};
token URI {
<scheme> ':' <hier-part> ['?' <query> ]? [ '#' <fragment> ]?
};
token hier-part {
| '//' <authority> <path-abempty>
| <path-absolute>
| <path-rootless>
| <path-empty>
};
token scheme { <.uri-alpha> <[\-+.] +uri-alpha +digit>* };
token authority { [ <userinfo> '@' ]? <host> [ ':' <port> ]? };
token userinfo {
[ ':' | <likely-userinfo-component> ]*
};
# the rfc refers to username:password as deprecated
token likely-userinfo-component {
<+unreserved +sub-delims>+ | <.pct-encoded>+
};
token host { <IPv4address> | <IP-literal> | <reg-name> };
token port { <.digit>* };
token IP-literal { '[' [ <IPv6address> | <IPvFuture> ] ']' };
token IPvFuture {
'v' <.xdigit>+ '.' <[:] +unreserved +sub-delims>+
};
token reg-name { [ <+unreserved +sub-delims> | <.pct-encoded> ]* };
token path-abempty { [ '/' <segment> ]* };
token path-absolute { '/' [ <segment-nz> [ '/' <segment> ]* ]? };
token path-noscheme { <segment-nz-nc> [ '/' <segment> ]* };
token path-rootless { <segment-nz> [ '/' <segment> ]* };
token path-empty { <.pchar> ** 0 }; # yes - zero characters
token segment { <.pchar>* };
token segment-nz { <.pchar>+ };
token segment-nz-nc { [ <+unenc-pchar - [:]> | <.pct-encoded> ] + };
token query { <.fragment> };
token fragment { [ <[/?] +unenc-pchar> | <.pct-encoded> ]* };
token pchar { <.unenc-pchar> | <.pct-encoded> };
token unenc-pchar { <[:@] +unreserved +sub-delims> };
token pct-encoded { '%' <.xdigit> <.xdigit> };
token unreserved { <[\-._~] +uri-alphanum> };
token reserved { <+gen-delims +sub-delims> };
token gen-delims { <[:/?\#\[\]@]> };
token sub-delims { <[;!$&'()*+,=]> };
token uri-alphanum { <+uri-alpha +digit> };
token uri-alpha { <[A..Za..z]> };
# vim:ft=perl6