-
Notifications
You must be signed in to change notification settings - Fork 125
/
url.trx
57 lines (44 loc) · 1.85 KB
/
url.trx
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
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
types:{{
open Base.Char
type url = { secure : bool
; host : string (* FIXME : en fait, plus précis que string *)
; port : int
; abs_path : string
; query : string }
(* FIXME: il faudrait mettre query : string stringmap !
afin d'avoir une vraie égalité quel que soit l'ordre des arguments *)
}}
+url : {url} <- ("http:" {{ false }} / "https:" {{ true }}) "//" host ([:] port {{__2}})? abspath? ([?] query {{__2}})?
{{ { secure = __1
; host = __3
; port = (match __4 with None -> (if __1 then 443 else 80) | Some p -> p)
; abs_path = (match __5 with None -> "/" | Some p -> p)
; query = (match __6 with None -> "" | Some q -> q) } }}
path <- char+ {{ Tgrammar.string_of_chars __1 }}
# FIXME: préciser nom.nom.nom
host <- hostchar+ {{ Tgrammar.string_of_chars __1 }}
port <- [0-9]+ {{ Tgrammar.int_of_chars __1 }}
# FIXME: préciser
abspath <- [/] char* {{ Tgrammar.string_of_chars __2 }}
# FIXME: préciser
query <- char+ {{ Tgrammar.string_of_chars __1 }}
hexa <- [0-9A-Fa-f]
hostchar <- [0-9a-z.\-] {{__1}}
/ [A-Z] {{ char_of_int (int_of_char __1 + 32) }}
# Vérifier...
char <- [+] {{ ' ' }}
/ [%] hexa hexa {{ char_of_int (16 * hexa_value __2 + hexa_value __1) }}
/ ![%?] . {{ __2 }}