lineCount.mll 276 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(* This simple function counts the number of newline characters
   in a string. *)

let newline = ('\010' | '\013' | "\013\010")

let ordinary = [^ '\010' '\013']+

rule count n = parse
| eof
    { n }
| newline
    { count (n + 1) lexbuf }
| ordinary
    { count n lexbuf }