blob: 23019185666b1684d71dc23fd4963411060fd3b2 (
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
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
(* $Id: find_phrase.mll 9240 2006-10-13 17:51:11Z notin $ *)
{
exception Lex_error of string
let length = ref 0
let buff = Buffer.create 513
}
let phrase_sep = '.'
rule next_phrase = parse
| "(*" { incr length; incr length;
skip_comment lexbuf;
next_phrase lexbuf}
| '"'[^'"']*'"' { let lexeme = Lexing.lexeme lexbuf in
let ulen = Glib.Utf8.length lexeme in
length := !length + ulen;
Buffer.add_string buff lexeme;
next_phrase lexbuf
}
| phrase_sep[' ''\n''\t''\r'] {
begin
if !Preferences.current.Preferences.lax_syntax
then length := !length + 1
else length := !length + 2
end;
Buffer.add_string buff (Lexing.lexeme lexbuf);
Buffer.contents buff}
| phrase_sep eof{
length := !length + 1;
Buffer.add_string buff (Lexing.lexeme lexbuf);
Buffer.contents buff}
| phrase_sep phrase_sep
{
length := !length + 2;
Buffer.add_string buff (Lexing.lexeme lexbuf);
next_phrase lexbuf
}
| _
{
let c = Lexing.lexeme_char lexbuf 0 in
if Ideutils.is_char_start c then incr length;
Buffer.add_char buff c ;
next_phrase lexbuf
}
| eof { raise (Lex_error "Phrase should end with . followed by a separator") }
and skip_comment = parse
| "*)" {incr length; incr length; ()}
| "(*" {incr length; incr length;
skip_comment lexbuf;
skip_comment lexbuf}
| _ { if Ideutils.is_char_start (Lexing.lexeme_char lexbuf 0) then
incr length;
skip_comment lexbuf}
| eof { raise (Lex_error "No closing *)") }
{
let get lb =
Buffer.reset buff;
length := 0;
next_phrase lb
}
|