summaryrefslogtreecommitdiff
path: root/ide/find_phrase.mll
blob: 1621e3132abc9834011803a770e1383cd74cadbf (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
(************************************************************************)
(*  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 6218 2004-10-15 14:27:04Z coq $ *)

{
  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'] {
      length := !length + 2; 
      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

}