c20388da69cebf71d88c073bbab5ccaad97cb26b
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / src / lineCount.mll
1 (**************************************************************************)
2 (* *)
3 (* Menhir *)
4 (* *)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
7 (* *)
8 (* Copyright 2005-2008 Institut National de Recherche en Informatique *)
9 (* et en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0, with the change *)
11 (* described in file LICENSE. *)
12 (* *)
13 (**************************************************************************)
14
15 (* This simple function counts the number of newline characters
16 in a string. *)
17
18 let newline = ('\010' | '\013' | "\013\010")
19
20 let ordinary = [^ '\010' '\013']+
21
22 rule count n = parse
23 | eof
24 { n }
25 | newline
26 { count (n + 1) lexbuf }
27 | ordinary
28 { count n lexbuf }
29