Debian Codegraph @

vendor/opam/src/format/opamLineLexer.mll

raw
1 (**************************************************************************)
2 (* *)
3 (* Copyright 2012-2016 OCamlPro *)
4 (* Copyright 2012 INRIA *)
5 (* *)
6 (* All rights reserved. This file is distributed under the terms of the *)
7 (* GNU Lesser General Public License version 2.1, with the special *)
8 (* exception on linking described in the file LICENSE. *)
9 (* *)
10 (**************************************************************************)
11
12 {
13
14 type token =
15 | WORD of string
16 | NEWLINE
17 | EOF
18
19 let word = Buffer.create 57
20
21 }
22
23 let normalchar = [^' ' '\t' '\r' '\n' '\\']
24
25 rule main = parse
26 | '\n' | "\r\n"
27 { Lexing.new_line lexbuf; NEWLINE }
28 | [' ' '\t']+ { main lexbuf }
29 | ('@' normalchar*) as w '\\'
30 { Buffer.reset word ; Buffer.add_string word w; escaped lexbuf }
31 | ('@' normalchar*) as w
32 { if w = "@" then WORD "" else WORD w }
33 | (normalchar* as w) '\\'
34 { Buffer.reset word ; Buffer.add_string word w; escaped lexbuf }
35 | (normalchar+ as w)
36 { WORD w }
37 | eof { EOF }
38
39 and escaped = parse
40 | (_ normalchar*) as w '\\'
41 { Buffer.add_string word w; escaped lexbuf }
42 | (_ normalchar*) as w
43 { Buffer.add_string word w; WORD (Buffer.contents word) }
44
45 {
46
47 let main lexbuf =
48 let rec aux lines words =
49 match main lexbuf with
50 | WORD s -> aux lines (s::words)
51 | NEWLINE ->
52 let lines = if words = [] then lines else List.rev words::lines in
53 aux lines []
54 | EOF ->
55 let lines = if words = [] then lines else List.rev words::lines in
56 List.rev lines
57 in
58 aux [] []
59
60 }