~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to parsing/g_ascii_syntax.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(***********************************************************************)
 
2
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team    *)
 
3
(* <O___,, *        INRIA-Rocquencourt  &  LRI-CNRS-Orsay              *)
 
4
(*   \VV/  *************************************************************)
 
5
(*    //   *      This file is distributed under the terms of the      *)
 
6
(*         *       GNU Lesser General Public License Version 2.1       *)
 
7
(***********************************************************************)
 
8
 
 
9
(*i $Id: g_ascii_syntax.ml 11309 2008-08-06 10:30:35Z herbelin $ i*)
 
10
 
 
11
open Pp
 
12
open Util
 
13
open Names
 
14
open Pcoq
 
15
open Rawterm
 
16
open Topconstr
 
17
open Libnames
 
18
open Coqlib
 
19
open Bigint
 
20
 
 
21
exception Non_closed_ascii
 
22
 
 
23
let make_dir l = make_dirpath (List.map id_of_string (List.rev l))
 
24
let make_kn dir id = Libnames.encode_kn (make_dir dir) (id_of_string id)
 
25
let make_path dir id = Libnames.make_path (make_dir dir) (id_of_string id)
 
26
 
 
27
let ascii_module = ["Coq";"Strings";"Ascii"]
 
28
 
 
29
let ascii_path = make_path ascii_module "ascii"
 
30
 
 
31
let ascii_kn = make_kn ascii_module "ascii"
 
32
let path_of_Ascii = ((ascii_kn,0),1)
 
33
let static_glob_Ascii  = ConstructRef path_of_Ascii
 
34
 
 
35
let make_reference id = find_reference "Ascii interpretation" ascii_module id
 
36
let glob_Ascii = lazy (make_reference "Ascii")
 
37
 
 
38
open Lazy
 
39
 
 
40
let interp_ascii dloc p =
 
41
  let rec aux n p = 
 
42
     if n = 0 then [] else
 
43
     let mp = p mod 2 in
 
44
     RRef (dloc,if mp = 0 then glob_false else glob_true)
 
45
     :: (aux (n-1) (p/2)) in
 
46
  RApp (dloc,RRef(dloc,force glob_Ascii), aux 8 p)
 
47
 
 
48
let interp_ascii_string dloc s =
 
49
  let p = 
 
50
    if String.length s = 1 then int_of_char s.[0]
 
51
    else
 
52
      if String.length s = 3 & is_digit s.[0] & is_digit s.[1] & is_digit s.[2]
 
53
      then int_of_string s
 
54
      else
 
55
        user_err_loc (dloc,"interp_ascii_string",
 
56
          str "Expects a single character or a three-digits ascii code.") in
 
57
  interp_ascii dloc p
 
58
 
 
59
let uninterp_ascii r =
 
60
  let rec uninterp_bool_list n = function
 
61
    | [] when n = 0 -> 0
 
62
    | RRef (_,k)::l when k = glob_true  -> 1+2*(uninterp_bool_list (n-1)  l)
 
63
    | RRef (_,k)::l when k = glob_false -> 2*(uninterp_bool_list (n-1) l)
 
64
    | _ -> raise Non_closed_ascii in
 
65
  try 
 
66
    let rec aux = function
 
67
    | RApp (_,RRef (_,k),l) when k = force glob_Ascii -> uninterp_bool_list 8 l
 
68
    | _ -> raise Non_closed_ascii in
 
69
    Some (aux r)
 
70
  with 
 
71
   Non_closed_ascii -> None
 
72
 
 
73
let make_ascii_string n =
 
74
  if n>=32 && n<=126 then String.make 1 (char_of_int n)
 
75
  else Printf.sprintf "%03d" n
 
76
 
 
77
let uninterp_ascii_string r = Option.map make_ascii_string (uninterp_ascii r)
 
78
 
 
79
let _ =
 
80
  Notation.declare_string_interpreter "char_scope"
 
81
    (ascii_path,ascii_module)
 
82
    interp_ascii_string
 
83
    ([RRef (dummy_loc,static_glob_Ascii)], uninterp_ascii_string, true)