blob: b84d8588a6545c9ce0d9fe6b7385e82e3c9f0df6 (
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
|
(***********************************************************************)
(* *)
(* Objective Caml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed *)
(* under the terms of the Q Public License version 1.0. *)
(* *)
(***********************************************************************)
(* $Id$ *)
(* Auxiliaries for the parser. *)
open Syntax
let regexp_for_string s =
let l = String.length s in
if l = 0 then
Epsilon
else begin
let re = ref(Characters [String.get s (l - 1)]) in
for i = l - 2 downto 0 do
re := Sequence(Characters [String.get s i], !re)
done;
!re
end
let char_class c1 c2 =
let cl = ref [] in
for i = Char.code c2 downto Char.code c1 do
cl := Char.chr i :: !cl
done;
!cl
let all_chars = char_class '\001' '\255'
let rec subtract l1 l2 =
match l1 with
[] -> []
| a::l -> if List.mem a l2 then subtract l l2 else a :: subtract l l2
|