q_symbol.ml 497 Bytes
Newer Older
1 2 3
let symbols = ref []

let define s =
4 5 6 7 8 9
  let i = 
    try String.index s '=' 
    with Not_found -> failwith ("Invalid symbol definition :" ^ s) in
  symbols := 
  (String.sub s 0 i, String.sub s (i + 1) (String.length s - i - 1)) ::
    !symbols
10 11 12

let expr _ s =
  try List.assoc s !symbols
13
  with Not_found -> failwith ("No definition for symbol " ^ s)
14 15 16

let _ =
  Quotation.add "symbol" (Quotation.ExStr expr);
17
  Pcaml.add_option "-symbol" (Arg.String define) 
18
    "<symbol=value> Define a symbol"