-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlencode.tt
52 lines (45 loc) · 935 Bytes
/
urlencode.tt
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
# Simple parser for url-encoded data.
#
# This software is licensed under the Creative
# Commons CC0 1.0 Universal License.
# To view a copy of this license, visit
# http://creativecommons.org/publicdomain/zero/1.0/legalcode
#
# @author Patrick Hof
grammar UrlEncode
rule urlencoded
param:param+ delimiter?
{
def content
body = {}
param.elements.each do |el_node|
el = el_node.content
if body.has_key?(el[0])
body[el[0]] << el[1]
else
body[el[0]] = [el[1]]
end
end
return body
end
}
end
rule param
key:param_key '=' val:(param_val / '') '&'?
{
def content
[key.text_value, val.text_value]
end
}
end
rule param_val
param_key
end
# FIXME This list seems to be incomplete
rule param_key
[a-zA-Z0-9\-%+]+
end
rule delimiter
"\n" / "\r\n"
end
end