ojacare.opp.exp 11.7 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 175 176 177
File "ojacare.mly", line 142, characters 18-25:
Warning: the token CAMLINT is unused.
File "ojacare.mly", line 151, characters 18-23:
Warning: the token COLON is unused.
%{
(*	$Id: parser.mly,v 1.3 2004/03/11 19:51:45 henry Exp $	*)

open Idl
open Syntax_error

(* fonctions de constructions : permets d'associer la position dans le fichier source *)

let make_ident s = {
  id_location = Loc.get ();
  id_desc = s
}

let make_qident p n = {
  qid_location = Loc.get ();
  qid_package = p;
  qid_name = n;
}

let make_type  t = {
  t_location = Loc.get ();
  t_desc = t
}

let make_modifiers desc = {
  mo_location = Loc.get ();
  mo_desc = desc 
}

let make_annotation desc = {
  an_location = Loc.get ();
  an_desc = desc 
}

let make_arg ?(annotations = []) ?ident t = {
  arg_location = Loc.get ();
  arg_type = t ;
  arg_annot = annotations
}

type def_sort =
    Content of content | Init of init

let make_init annotation args = 
  Init 
    {
     i_location = Loc.get ();
     i_annot = annotation; 
     i_args = args 
   }

let make_field ?(modifiers = []) ?(annotations = []) t name =
  List.iter (fun m -> match m.mo_desc with 
    Istatic | Ifinal -> () 
  | d -> raise (Syntax_error (Efield_modifiers m))) modifiers;
  Content (Field 
    {
     f_location = Loc.get ();
     f_modifiers = modifiers;
     f_annot = annotations; 
     f_name = name; 
     f_type = t 
   })

let make_method ?(modifiers = []) ?(annotations = []) rtype name args = 
  List.iter (fun m -> match m.mo_desc with 
    Istatic | Iabstract -> () 
  | d -> raise (Syntax_error (Emethod_modifiers m))) modifiers;
  Content (Method 
    {
     m_location = Loc.get ();
     m_annot = annotations;
     m_modifiers = modifiers;
     m_name = name;
     m_return_type = rtype;
     m_args = args
   })
    
let filter_inits l = List.fold_left (fun l -> (function (Init d) -> d::l | _ -> l)) [] l
let filter_contents l = List.fold_left (fun l -> (function (Content d) -> d::l | _ -> l)) [] l

let make_def ?(modifiers = []) ?(annotations = []) ?(interface = false) name  ?super ?(implements = []) decls = 
  let contents = filter_contents decls
  and inits = filter_inits decls in

(*  let inits = (* ajout init par dfaut ... non car conflit de nom *)
   if inits = [] && not interface then
   [{ i_location = Loc.get ();
   i_annot = []; 
   i_args = [] }]
   else inits in *)
  
  if interface then begin
    List.iter (fun m -> match m.mo_desc with 
    | d -> raise (Syntax_error (Einterface_modifiers m))) modifiers;
    if inits != [] then  raise (Syntax_error (Enoinit (List.hd inits)));
    List.iter (fun c -> 
      match c with 
      | Method m -> 
	  if m.m_modifiers != [] then 
	    let m = List.hd m.m_modifiers in
	    raise (Syntax_error (Einterfacemethod_modifiers m))
      | Field f -> 
	  if f.f_modifiers != [] then 
	    let f = List.hd f.f_modifiers in
	    raise (Syntax_error (Einterfacefield_modifiers f))
      ) contents;
  end
  else begin
    List.iter (fun m -> match m.mo_desc with 
      Iabstract -> () 
    | d -> raise (Syntax_error (Eclass_modifiers m))) modifiers
  end;
  {
   d_location = Loc.get ();
   d_super = super;
   d_implements = implements;
   d_interface = interface;
   d_modifiers = modifiers;
   d_annot = annotations;
   d_name = name;
   d_inits = inits;
   d_contents = contents;
 }

let make_package name defs = {
   p_name = name;
   p_defs = defs;
 }

%}
%start idl_file
%token VOID
%token TOP
%token STRING
%token STATIC
%token SHORT
%token SEMI
%token RPAREN
%token RBRACKET
%token RBRACE
%token PACKAGE
%token NAME
%token LPAREN
%token LONG
%token LBRACKET
%token LBRACE
%token INTERFACE
%token INT
%token INIT
%token IMPLEMENTS
%token <string> IDENT
%token FLOAT
%token FINAL
%token EXTENDS
%token EOF
%token DOUBLE
%token DOT
%token COMMA
%token COLON
%token CLASS
%token CHAR
%token CAMLINT
%token CALLBACK
%token BYTE
%token BOOLEAN
%token ARRAY
%token ABSTRACT

%type <Idl.file> idl_file
%%

idl_file:
178 179 180 181
| _1 = idl_file_list _2 = EOF
    {                    ( _1 )}
| _1 = defs _2 = EOF
    {           ( [make_package [] _1] )}
182 183

idl_file_list:
184 185 186 187
| _1 = PACKAGE _2 = ident_list _3 = SEMI _4 = defs
    {                               ( [make_package _2 _4] )}
| _1 = PACKAGE _2 = ident_list _3 = SEMI _4 = defs _5 = idl_file_list
    {                                             ( (make_package _2 _4) :: _5 )}
188 189

defs:
190 191 192 193
| _1 = def
    {      ( [_1] )}
| _1 = def _2 = defs
    {           ( _1 :: _2 )}
194 195

def:
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
| _1 = CLASS _2 = ident _3 = def_body
    {                       ( make_def _2 _3 )}
| _1 = annotations _2 = CLASS _3 = ident _4 = def_body
    {                                   ( make_def ~annotations:_1 _3 _4 )}
| _1 = modifiers _2 = CLASS _3 = ident _4 = def_body
    {                                 ( make_def  ~modifiers:_1 _3 _4 )}
| _1 = annotations _2 = modifiers _3 = CLASS _4 = ident _5 = def_body
    {                                             ( make_def ~modifiers:_2 ~annotations:_1 _4 _5 )}
| _1 = CLASS _2 = ident _3 = super _4 = def_body
    {                             ( make_def _2 ~super:_3 _4 )}
| _1 = annotations _2 = CLASS _3 = ident _4 = super _5 = def_body
    {                                         ( make_def ~annotations:_1 _3 ~super:_4 _5 )}
| _1 = modifiers _2 = CLASS _3 = ident _4 = super _5 = def_body
    {                                       ( make_def  ~modifiers:_1 _3 ~super:_4 _5 )}
| _1 = annotations _2 = modifiers _3 = CLASS _4 = ident _5 = super _6 = def_body
    {                                                   ( make_def ~modifiers:_2 ~annotations:_1 _4 ~super:_5 _6 )}
| _1 = CLASS _2 = ident _3 = IMPLEMENTS _4 = interface_list _5 = def_body
    {                                                 ( make_def _2 ~implements:_4 _5 )}
| _1 = annotations _2 = CLASS _3 = ident _4 = IMPLEMENTS _5 = interface_list _6 = def_body
    {                                                             ( make_def ~annotations:_1 _3 ~implements:_5 _6 )}
| _1 = modifiers _2 = CLASS _3 = ident _4 = IMPLEMENTS _5 = interface_list _6 = def_body
    {                                                           ( make_def  ~modifiers:_1 _3 ~implements:_5 _6 )}
| _1 = annotations _2 = modifiers _3 = CLASS _4 = ident _5 = IMPLEMENTS _6 = interface_list _7 = def_body
    {                                                                       ( make_def ~modifiers:_2 ~annotations:_1 _4 ~implements:_6 _7 )}
| _1 = CLASS _2 = ident _3 = super _4 = IMPLEMENTS _5 = interface_list _6 = def_body
    {                                                       ( make_def _2 ~super:_3 ~implements:_5 _6 )}
| _1 = annotations _2 = CLASS _3 = ident _4 = super _5 = IMPLEMENTS _6 = interface_list _7 = def_body
    {                                                                   ( make_def ~annotations:_1 _3 ~super:_4 ~implements:_6 _7 )}
| _1 = modifiers _2 = CLASS _3 = ident _4 = super _5 = IMPLEMENTS _6 = interface_list _7 = def_body
    {                                                                 ( make_def  ~modifiers:_1 _3 ~super:_4 ~implements:_6 _7 )}
| _1 = annotations _2 = modifiers _3 = CLASS _4 = ident _5 = super _6 = IMPLEMENTS _7 = interface_list _8 = def_body
    {                                                                             ( make_def ~modifiers:_2 ~annotations:_1 _4 ~super:_5 ~implements:_7 _8 )}
| _1 = INTERFACE _2 = ident _3 = def_body
    {                           ( make_def ~interface:true _2 _3 )}
| _1 = annotations _2 = INTERFACE _3 = ident _4 = def_body
    {                                       ( make_def ~annotations:_1 ~interface:true _3 _4 )}
| _1 = INTERFACE _2 = ident _3 = IMPLEMENTS _4 = interface_list _5 = def_body
    {                                                     ( make_def ~interface:true _2 ~implements:_4 _5 )}
| _1 = annotations _2 = INTERFACE _3 = ident _4 = IMPLEMENTS _5 = interface_list _6 = def_body
    {                                                                 ( make_def ~annotations:_1 ~interface:true _3 ~implements:_5 _6 )}
236 237

super:
238 239
| _1 = EXTENDS _2 = qident
    {                 ( _2 )}
240 241

def_body:
242 243 244 245
| _1 = LBRACE _2 = decls _3 = RBRACE
    {                      ( _2 )}
| _1 = LBRACE _2 = RBRACE
    {                ( [] )}
246 247

decls:
248 249 250 251
| _1 = decl _2 = SEMI
    {            ( [_1] )}
| _1 = decl _2 = SEMI _3 = decls
    {                  ( _1 :: _3 )}
252 253

decl:
254 255 256 257 258 259
| _1 = fields
    {         ( _1 )}
| _1 = methods
    {          ( _1 )}
| _1 = inits
    {        ( _1 )}
260 261

fields:
262 263 264 265 266 267 268 269
| _1 = typ _2 = ident
    {            ( make_field _1 _2 )}
| _1 = annotations _2 = typ _3 = ident
    {                        ( make_field ~annotations:_1 _2 _3 )}
| _1 = modifiers _2 = typ _3 = ident
    {                      ( make_field ~modifiers:_1 _2 _3 )}
| _1 = annotations _2 = modifiers _3 = typ _4 = ident
    {                                  ( make_field ~modifiers:_2 ~annotations:_1 _3 _4 )}
270 271

methods:
272 273 274 275 276 277 278 279
| _1 = typ _2 = ident _3 = args
    {      ( make_method _1 _2 _3 )}
| _1 = annotations _2 = typ _3 = ident _4 = args
    {      ( make_method ~annotations:_1 _2 _3 _4 )}
| _1 = modifiers _2 = typ _3 = ident _4 = args
    {      ( make_method ~modifiers:_1 _2 _3 _4 )}
| _1 = annotations _2 = modifiers _3 = typ _4 = ident _5 = args
    {      ( make_method ~modifiers:_2 ~annotations:_1 _3 _4 _5 )}
280 281

inits:
282 283 284 285
| _1 = annotations _2 = INIT _3 = args
    {                        ( make_init _1 _3 )}
| _1 = INIT _2 = args
    {            ( raise (Syntax_error (Einit_no_alias (Loc.get ()))) )}
286 287

args:
288 289 290 291
| _1 = LPAREN _2 = RPAREN
    {                ( [] )}
| _1 = LPAREN _2 = arg_list _3 = RPAREN
    {                         ( _2 )}
292 293

arg_list:
294 295 296 297
| _1 = arg
    {      ( [_1] )}
| _1 = arg _2 = COMMA _3 = arg_list
    {                     ( _1 :: _3 )}
298 299

arg:
300 301 302 303 304 305 306 307
| _1 = typ
    {      ( make_arg _1 )}
| _1 = annotations _2 = typ
    {                  ( make_arg ~annotations:_1 _2)}
| _1 = typ _2 = ident
    {            ( make_arg ~ident:_2 _1 )}
| _1 = annotations _2 = typ _3 = ident
    {                        ( make_arg ~annotations:_1 ~ident:_3 _2 )}
308 309

typ:
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
| _1 = VOID
    {       ( make_type Ivoid )}
| _1 = BOOLEAN
    {           ( make_type Iboolean )}
| _1 = BYTE
    {        ( make_type Ibyte )}
| _1 = SHORT
    {         ( make_type Ishort )}
| _1 = INT
    {       ( make_type Icamlint )}
| _1 = LONG
    {        ( make_type Ilong )}
| _1 = FLOAT
    {         ( make_type Ifloat )}
| _1 = DOUBLE
    {          ( make_type Idouble )}
| _1 = CHAR
    {       ( make_type Ichar )}
| _1 = STRING
    {         ( make_type Istring )}
| _1 = TOP
    {      ( make_type Itop )}
| _1 = typ _2 = LBRACKET _3 = RBRACKET
    {                        ( make_type (Iarray _1) )}
| _1 = qident
    {         ( make_type (Iobject _1) )}
336 337

modifiers:
338 339 340 341
| _1 = modifier
    {           ( [_1] )}
| _1 = modifier _2 = modifiers
    {                     ( _1::_2 )}
342 343

modifier:
344 345 346 347 348 349
| _1 = STATIC
    {         ( make_modifiers Istatic )}
| _1 = ABSTRACT
    {           ( make_modifiers Iabstract )}
| _1 = FINAL
    {         ( make_modifiers Ifinal )}
350 351

annotations:
352 353
| _1 = LBRACKET _2 = ann_list _3 = RBRACKET
    {                             ( _2 )}
354 355

ann_list:
356 357 358 359
| _1 = ann
    {      ( [_1] )}
| _1 = ann _2 = COMMA _3 = ann_list
    {                     ( _1 :: _3 )}
360 361

ann:
362 363 364 365 366 367
| _1 = NAME _2 = ident
    {             ( make_annotation (Iname _2) )}
| _1 = CALLBACK
    {           ( make_annotation Icallback )}
| _1 = ARRAY
    {        ( make_annotation (Icamlarray) )}
368 369

ident:
370 371
| _1 = IDENT
    {        ( make_ident _1 )}
372 373

ident_list:
374 375 376 377
| _1 = IDENT
    {        ( [_1] )}
| _1 = ident_list _2 = DOT _3 = IDENT
    {                       ( _3 :: _1 )}
378 379

qident:
380 381 382 383
| _1 = ident
    {        ( make_qident [] _1 )}
| _1 = ident_list _2 = DOT _3 = ident
    {                       ( make_qident _1 _3 )}
384 385

interface_list:
386 387 388 389
| _1 = qident
    {         ( [_1] )}
| _1 = qident _2 = COMMA _3 = interface_list
    {                              ( _1 :: _3 )}
390 391 392 393 394

%%