summaryrefslogtreecommitdiff
path: root/test/multiregion2.lm
blob: d69b8d4c562815fcd55eaa9a71c0b08222dc6b3f (plain)
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
##### LM #####
#
# Character classes
#
rl CTL /0..31 | 127/
rl CR /13/
rl LF /10/
rl SP /32/
rl HT /9/
rl CHAR /0..127/

rl separators / '(' | ')' | '<' | '>' 
		| '@' | ',' | ';' | ':' | '\\' 
		| '"' | '/' | '[' | ']' | '?' 
		| '=' | '{' | '}' | SP | HT /

rl token_char /CHAR - CTL - separators/

#
# Literal tokens
#

literal `HTTP/ `:
token SPT /' '/
token CRLF /CR LF/

#
# Request Line
#

token method /token_char+/

token request_uri /(^SP)+/

token http_number /digit+ '.' digit+/

def http_version 
	[ `HTTP/ http_number ]

def request_line 
	[method SPT request_uri 
	 SPT http_version CRLF]

#
# Header
#

token field_name /token_char+/

lex
	token fv_plain /(^(CR|LF))*/
	token fv_ext /CR LF (SP|HT)/
	token fv_term /CR LF/
end

def fv 
	[fv_plain]
|	[fv_ext]

def field_value 
	[fv* fv_term]

def header 
	[field_name `: field_value]

#
# Request
#

def request
	[request_line header* CRLF]

parse R: request*[ stdin ]

if !R {
	print( error )
	exit( 1 )
}

for FV: fv in R {
	if match FV [fv_ext]
		FV = cons fv " "
}

print( R )

##### IN #####
GET /hi/there/ HTTP/1.1

GET /hithere/ HTTP/1.1
Host: localhost:3535
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control: max-age=0

GET foo HTTP/1.1
hello: foo
hi: there
	my
 friend

##### EXP #####
GET /hi/there/ HTTP/1.1

GET /hithere/ HTTP/1.1
Host: localhost:3535
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control: max-age=0

GET foo HTTP/1.1
hello: foo
hi: there my friend