aboutsummaryrefslogtreecommitdiffhomepage
path: root/ide/find_phrase.mll
blob: 677ca428feddc77633a8bec8f257b63c18c54880 (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$ *)

{
  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

}