---------------------------------------------- ---------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P A R S E R -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2006, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ -- This package contains the top-level procedures to convert the XML/Dia file -- into a abstract syntax tree with Ada.Text_IO; use Ada.Text_IO; with Input_Sources.File; with DOM.Readers; with DOM.Core; with DOM.Core.Documents; with Ocarina.Dia.Parser.Core; with Ocarina.Dia.Parser.Core.Diagram; with Ocarina.Dia.Parser.Translate; with Ocarina.Parser; package body Ocarina.Dia.Parser is ---------- -- Init -- ---------- procedure Init is begin Ocarina.Parser.Register_Parser (".dia", Process'Access); end Init; -- Parse the file File_Name and return the Node_Id or the root of -- the resulting AADL tree, or No_Node if the parsing failed. If -- AADL_Root is not No_Node, then return itself, as it is the tree -- root. function Process (File_Name : String; AADL_Root : Types.Node_Id) return Node_Id is use DOM.Core; use Ocarina.Dia.Parser.Core.Diagram; pragma Unreferenced (AADL_Root); F : Input_Sources.File.File_Input; T : DOM.Readers.Tree_Reader; R : Types.Node_Id; begin -- Open file Put_Line ("Opening file : " & File_Name); Input_Sources.File.Open (File_Name, F); Put_Line ("Parsing file with DOM..."); DOM.Readers.Parse (T, F); Put_Line ("Processing Diagram objects..."); declare use Ocarina.Dia.Parser.Core; use Ocarina.Dia.Parser.Translate; D : constant Document := DOM.Readers.Get_Tree (T); Root : constant Element := Documents.Get_Element (D); NL : constant Ocarina.Dia.Parser.Core.Node_List := Process_Diagram (Root); begin -- Put_Line ("Printing nodes :"); -- for I in 0 .. (Length (NL) - 1) loop -- Print_Node (Item (NL, I)); -- end loop; -- Translate from the internal representation to the Ocarina -- Core Internal Tree Put_Line ("Translating to the internal tree"); R := Ocarina.Dia.Parser.Translate.Translate (NL); end; Put_Line ("Freeing Memory"); DOM.Readers.Free (T); Put_Line ("Closing input file"); Input_Sources.File.Close (F); return R; end Process; end Ocarina.Dia.Parser;