ocamldoc-odoc.opp.exp 4.13 KB
Newer Older
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
%{
(***********************************************************************)
(*                             OCamldoc                                *)
(*                                                                     *)
(*            Maxence Guesdon, projet Cristal, INRIA Rocquencourt      *)
(*                                                                     *)
(*  Copyright 2001 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: odoc_parser.mly,v 1.3 2003/11/24 10:43:11 starynke Exp $ *)

open Odoc_types
open Odoc_comments_global

let uppercase = "[A-Z\192-\214\216-\222]"
let identchar = 
  "[A-Za-z_\192-\214\216-\246\248-\255'0-9]"
let blank = "[ \010\013\009\012]"

let print_DEBUG s = print_string s; print_newline ()
%}
%start info_part2
%start main
%start see_info
%token T_VERSION
%token T_SINCE
%token T_SEE
%token T_RETURN
%token T_RAISES
%token T_PARAM
%token T_DEPRECATED
%token <string> T_CUSTOM
%token T_AUTHOR
%token <string> See_url
%token <string> See_file
%token <string> See_doc
%token EOF
%token <string * (string option)> Description
%token <string> Desc

%type <unit> info_part2
%type <(string * (string option)) option> main
%type <Odoc_types.see_ref * string> see_info
%%

see_info:
| see_ref Desc
    { ($1, $2) }

see_ref:
| See_url
    { Odoc_types.See_url $1 }
| See_file
    { Odoc_types.See_file $1 }
| See_doc
    { Odoc_types.See_doc $1 }

main:
| Description
    { Some $1 }
| EOF
    { None }

info_part2:
| element_list EOF
    { () }

element_list:
| element
    { () }
| element element_list
    { () }

element:
| param
    { () }
| author
    { () }
| version
    { () }
| see
    { () }
| since
    { () }
| deprecated
    { () }
| raise_exc
    { () }
| return
    { () }
| custom
    { () }

param:
| T_PARAM Desc
    { 
      (* isolate the identificator *)
      (* we only look for simple id, no pattern nor tuples *)
      let s = $2 in
      match Str.split (Str.regexp (blank^"+")) s with
        []
      | _ :: [] ->
          raise (Failure "usage: @param id description")
      | id :: _ ->    
          print_DEBUG ("Identificator "^id);
          let reg = identchar^"+" in
          print_DEBUG ("reg="^reg);
          if Str.string_match (Str.regexp reg) id 0 then
            let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in
            print_DEBUG ("T_PARAM Desc remain="^remain);
            let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in
            params := !params @ [(id, remain2)] 
          else
            raise (Failure (id^" is not a valid parameter identificator in \"@param "^s^"\""))
    }

author:
| T_AUTHOR Desc
    { authors := !authors @ [ $2 ] }

version:
| T_VERSION Desc
    { version := Some $2 }

see:
| T_SEE Desc
    { sees := !sees @ [$2] }

since:
| T_SINCE Desc
    { since := Some $2 }

deprecated:
| T_DEPRECATED Desc
    { deprecated := Some $2 }

raise_exc:
| T_RAISES Desc
    { 
      (* isolate the exception construtor name *)
      let s = $2 in
      match Str.split (Str.regexp (blank^"+")) s with
        []
      | _ :: [] ->
          raise (Failure "usage: @raise Exception description")
      | id :: _ ->    
          print_DEBUG ("exception "^id);
          let reg = uppercase^identchar^"*"^"\\(\\."^uppercase^identchar^"*\\)*" in
          print_DEBUG ("reg="^reg);
          if Str.string_match (Str.regexp reg) id 0 then
            let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in
            let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in
            raised_exceptions := !raised_exceptions @ [(id, remain2)] 
          else
            raise (Failure (id^" is not a valid exception constructor in \"@raise "^s^"\""))
    }

return:
| T_RETURN Desc
    { return_value := Some $2 }

custom:
| T_CUSTOM Desc
    { customs := !customs @ [($1, $2)] }

%%