q_symbol.ml 508 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
let symbols = ref []

let define s =
  try
    let i = String.index s '=' in
    symbols := 
      (String.sub s 0 i, String.sub s (i + 1) (String.length s - i - 1)) ::
      !symbols
  with Not_found ->
    failwith ("Invalid symbol definition :" ^ s)

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

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