summaryrefslogtreecommitdiff
path: root/test/multiregion2.lm
blob: f86d931c032fca7dfac08fc34a0138f7cb8a8d13 (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
#
# 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 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 ' ' request_uri 
	 ' ' http_version CRLF]

#
# Header
#

token field_name /token_char+/

lex field_value
{
	token fv_plain /(^(CR|LF))*/
	token fv_ext /CR LF (SP|HT)/
	token fv_term /CR LF/
}

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 )