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
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 ABSTRACT
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
%token ARRAY
%token BOOLEAN
%token BYTE
%token CALLBACK
%token CAMLINT
%token CHAR
%token CLASS
%token COLON
%token COMMA
%token DOT
%token DOUBLE
%token EOF
%token EXTENDS
%token FINAL
%token FLOAT
%token <string> IDENT
%token IMPLEMENTS
%token INIT
%token INT
%token INTERFACE
%token LBRACE
%token LBRACKET
%token LONG
%token LPAREN
%token NAME
%token PACKAGE
%token RBRACE
%token RBRACKET
%token RPAREN
%token SEMI
%token SHORT
%token STATIC
%token STRING
%token TOP
%token VOID
173 174 175 176
%type <Idl.file> idl_file
%%

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

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

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

def:
195
  _1 = CLASS _2 = ident _3 = def_body
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
    {                       ( 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 )}
235 236

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

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

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

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

fields:
261
  _1 = typ _2 = ident
262 263 264 265 266 267 268
    {            ( 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 )}
269 270

methods:
271
  _1 = typ _2 = ident _3 = args
272 273 274 275 276 277 278
    {      ( 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 )}
279 280

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

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

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

arg:
299
  _1 = typ
300 301 302 303 304 305 306
    {      ( 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 )}
307 308

typ:
309
  _1 = VOID
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
    {       ( 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) )}
335 336

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

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

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

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

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

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

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

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

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

%%