Skip to content
This repository
Newer
Older
100644 44 lines (36 sloc) 1.542 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* The lexer definition *)
19 open RequestParse
20 open Printf
21
22 type lexical_error = Illegal_character
23
24 exception Lexical_error of lexical_error * int * int
25
26 let parse = lexer
27 | [' ' '\t']+ -> SPACE (Ulexing.utf8_lexeme lexbuf)
28 | '\r' '\n' -> EOL
29 | '\r' -> EOL
30 | '\n' -> EOL
31 | ([^':' ' ' '\t' '\n' '\r'])+ -> WORD (Ulexing.utf8_lexeme lexbuf)
32 | ":" -> COLON
33 | eof -> EOF
34
35 let parse_request str =
36 (* The following line cost 1/4 of the time: *)
37 let buffer = Ulexing.from_utf8_string str in
38 let res() =
39 (* Trick from Alain Frisch to use Ulex with OCamlyacc *)
40 (* http://caml.inria.fr/pub/ml-archives/caml-list/2005/01/52cbc2cd2be4fc7ea0f00c39a760bf59.en.html *)
41 request (fun _ -> parse buffer) (Lexing.from_string "dummy")
42 in
43 try ((Ulexing.lexeme_end buffer, res()):int * RequestType.parse_request)
44 with _ -> Ulexing.lexeme_end buffer, RequestType.Incomplete
Something went wrong with that request. Please try again.