jdl_parser.cpp

Go to the documentation of this file.
00001 //  This file is part of jdl_parser.
00002 //
00003 //  jdl_parser is free software: you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation, either version 3 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  jdl_parser is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with jdl_parser.  If not, see <http://www.gnu.org/licenses/>.
00015 
00016 // Copyright Simone Pellegrini 2007-2008; e-mail: motonacciu@gmail.com
00017 
00018 #include "jdl_parser.hpp"
00019 
00020 using namespace jdl;
00021 
00022 bool jdl::parse_string(jdl_parser& parser, std::string const& jdl){
00023         if(jdl.length() == 0)
00024                 return false;
00025         try{
00026                 return parser.parse(jdl);
00027         }catch(parser_error<Errors, char const *> ex){
00028                 std::ostringstream err;
00029                 err << "Syntax error occurred: " << endl;
00030                 switch(ex.descriptor){
00031                         case semicolon_expected:
00032                                 err << "';' expected";
00033                                 break;
00034                         case right_quad_par_expected:
00035                                 err << "']' expected";
00036                                 break;
00037                         case right_round_par_expected:
00038                                 err << "')' expected";
00039                                 break;
00040                         case right_graph_par_expected:
00041                                 err << "'}' expected";
00042                                 break;
00043                         case colon_expected:
00044                                 err << "':' expected";
00045                                 break;
00046                         case attribute_expected: 
00047                                 err << "valid attribute expected";
00048                                 break;
00049                         default:
00050                                 err << "Error occured";
00051                 }
00052                 pair<int,int> err_desc = iter2RowCol(jdl, ex.where);
00053                 throw jdl::parse_error(err.str(), err_desc.first, err_desc.second);
00054         }catch(semantic_error e){
00055                 string error = e.what();
00056                 pair<int,int> err_desc = iter2RowCol(jdl, e.where);
00057                 throw jdl::parse_error(error, err_desc.first, err_desc.second);
00058         }
00059 }

Generated on Sun Feb 17 16:55:14 2008 for JDLParser by  doxygen 1.5.3