aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/pegtl/contrib/uri.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/pegtl/contrib/uri.hpp')
-rw-r--r--MoonParser/pegtl/contrib/uri.hpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/MoonParser/pegtl/contrib/uri.hpp b/MoonParser/pegtl/contrib/uri.hpp
new file mode 100644
index 0000000..1401a7d
--- /dev/null
+++ b/MoonParser/pegtl/contrib/uri.hpp
@@ -0,0 +1,116 @@
1// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey
2// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3
4#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_URI_HPP
5#define TAOCPP_PEGTL_INCLUDE_CONTRIB_URI_HPP
6
7#include "../ascii.hpp"
8#include "../config.hpp"
9#include "../rules.hpp"
10#include "../utf8.hpp"
11
12#include "abnf.hpp"
13
14namespace tao
15{
16 namespace TAOCPP_PEGTL_NAMESPACE
17 {
18 namespace uri
19 {
20 // URI grammar according to RFC 3986.
21
22 // This grammar is a direct PEG translation of the original URI grammar.
23 // It should be considered experimental -- in case of any issues, in particular
24 // missing rules for attached actions, please contact the developers.
25
26 // Note that this grammar has multiple top-level rules.
27
28 using namespace abnf;
29
30 using dot = one< '.' >;
31 using colon = one< ':' >;
32
33 // clang-format off
34 struct dec_octet : sor< one< '0' >,
35 rep_min_max< 1, 2, DIGIT >,
36 seq< one< '1' >, DIGIT, DIGIT >,
37 seq< one< '2' >, range< '0', '4' >, DIGIT >,
38 seq< string< '2', '5' >, range< '0', '5' > > > {};
39
40 struct IPv4address : seq< dec_octet, dot, dec_octet, dot, dec_octet, dot, dec_octet > {};
41
42 struct h16 : rep_min_max< 1, 4, HEXDIG > {};
43 struct ls32 : sor< seq< h16, colon, h16 >, IPv4address > {};
44
45 struct dcolon : two< ':' > {};
46
47 struct IPv6address : sor< seq< rep< 6, h16, colon >, ls32 >,
48 seq< dcolon, rep< 5, h16, colon >, ls32 >,
49 seq< opt< h16 >, dcolon, rep< 4, h16, colon >, ls32 >,
50 seq< opt< h16, opt< colon, h16 > >, dcolon, rep< 3, h16, colon >, ls32 >,
51 seq< opt< h16, rep_opt< 2, colon, h16 > >, dcolon, rep< 2, h16, colon >, ls32 >,
52 seq< opt< h16, rep_opt< 3, colon, h16 > >, dcolon, h16, colon, ls32 >,
53 seq< opt< h16, rep_opt< 4, colon, h16 > >, dcolon, ls32 >,
54 seq< opt< h16, rep_opt< 5, colon, h16 > >, dcolon, h16 >,
55 seq< opt< h16, rep_opt< 6, colon, h16 > >, dcolon > > {};
56
57 struct gen_delims : one< ':', '/', '?', '#', '[', ']', '@' > {};
58 struct sub_delims : one< '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' > {};
59
60 struct unreserved : sor< ALPHA, DIGIT, one< '-', '.', '_', '~' > > {};
61 struct reserved : sor< gen_delims, sub_delims > {};
62
63 struct IPvFuture : if_must< one< 'v' >, plus< HEXDIG >, dot, plus< sor< unreserved, sub_delims, colon > > > {};
64
65 struct IP_literal : if_must< one< '[' >, sor< IPvFuture, IPv6address >, one< ']' > > {};
66
67 struct pct_encoded : if_must< one< '%' >, HEXDIG, HEXDIG > {};
68 struct pchar : sor< unreserved, pct_encoded, sub_delims, one< ':', '@' > > {};
69
70 struct query : star< sor< pchar, one< '/', '?' > > > {};
71 struct fragment : star< sor< pchar, one< '/', '?' > > > {};
72
73 struct segment : star< pchar > {};
74 struct segment_nz : plus< pchar > {};
75 struct segment_nz_nc : plus< sor< unreserved, pct_encoded, sub_delims, one< '@' > > > {}; // non-zero-length segment without any colon ":"
76
77 struct path_abempty : star< one< '/' >, segment > {};
78 struct path_absolute : seq< one< '/' >, opt< segment_nz, star< one< '/' >, segment > > > {};
79 struct path_noscheme : seq< segment_nz_nc, star< one< '/' >, segment > > {};
80 struct path_rootless : seq< segment_nz, star< one< '/' >, segment > > {};
81 struct path_empty : success {};
82
83 struct path : sor< path_noscheme, // begins with a non-colon segment
84 path_rootless, // begins with a segment
85 path_absolute, // begins with "/" but not "//"
86 path_abempty > {}; // begins with "/" or is empty
87
88 struct reg_name : star< sor< unreserved, pct_encoded, sub_delims > > {};
89
90 struct port : star< DIGIT > {};
91 struct host : sor< IP_literal, IPv4address, reg_name > {};
92 struct userinfo : star< sor< unreserved, pct_encoded, sub_delims, colon > > {};
93 struct authority : seq< opt< userinfo, one< '@' > >, host, opt< colon, port > > {};
94
95 struct scheme : seq< ALPHA, star< sor< ALPHA, DIGIT, one< '+', '-', '.' > > > > {};
96
97 using dslash = two< '/' >;
98 using opt_query = opt< if_must< one< '?' >, query > >;
99 using opt_fragment = opt< if_must< one< '#' >, fragment > >;
100
101 struct hier_part : sor< if_must< dslash, authority, path_abempty >, path_rootless, path_absolute, path_empty > {};
102 struct relative_part : sor< if_must< dslash, authority, path_abempty >, path_noscheme, path_absolute, path_empty > {};
103 struct relative_ref : seq< relative_part, opt_query, opt_fragment > {};
104
105 struct URI : seq< scheme, one< ':' >, hier_part, opt_query, opt_fragment > {};
106 struct URI_reference : sor< URI, relative_ref > {};
107 struct absolute_URI : seq< scheme, one< ':' >, hier_part, opt_query > {};
108 // clang-format on
109
110 } // namespace uri
111
112 } // namespace TAOCPP_PEGTL_NAMESPACE
113
114} // namespace tao
115
116#endif