File: repeat.ml

package info (click to toggle)
ocaml-sedlex 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 792 kB
  • sloc: ml: 7,866; makefile: 24; sh: 9
file content (26 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (3)
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
let rec token buf =
  match%sedlex buf with
    | white_space ->
        print_endline "\tWhitespace";
        token buf
    | 'a', Rep (white_space, 1) ->
        print_endline "a\n\tWhitespace";
        token buf
    | Rep ("bc", 2) ->
        print_endline "bcbc";
        token buf
    | Rep ("d", 1 .. 1) ->
        print_endline "d";
        token buf
    | Rep ("ef", 1 .. 3) ->
        Printf.printf "%s\n" (Sedlexing.Utf8.lexeme buf);
        token buf
    | eof -> print_endline "\tEnd"
    | any ->
        print_endline "Other";
        token buf
    | _ -> failwith "Internal failure: Reached impossible place"

let () =
  let lexbuf = Sedlexing.Utf8.from_string "a bcbc d ef efef efefef" in
  token lexbuf