From: <gsa...@us...> - 2010-11-29 08:52:30
|
Revision: 23 http://simfqt.svn.sourceforge.net/simfqt/?rev=23&view=rev Author: gsabatier Date: 2010-11-29 08:52:23 +0000 (Mon, 29 Nov 2010) Log Message: ----------- [Simfqt] Running error with spirit v2 parser Modified Paths: -------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp trunk/simfqt/simfqt/basic/sources.mk trunk/simfqt/simfqt/batches/simfqt.cpp trunk/simfqt/simfqt/bom/FareRuleStruct.cpp trunk/simfqt/simfqt/command/FareParser.cpp trunk/simfqt/simfqt/command/FareParserHelper.cpp trunk/simfqt/simfqt/command/FareParserHelper.hpp Modified: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-29 08:52:23 UTC (rev 23) @@ -1,22 +1,14 @@ -#ifndef __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP -#define __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP +#ifndef __SIMFQT_BAS_BASCOMPARSERTYPES_HPP +#define __SIMFQT_BAS_BASCOMPARSERTYPES_HPP // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// STL -#include <string> -// Boost -//#define BOOST_SPIRIT_DEBUG -#include <boost/spirit/home/classic/core.hpp> -#include <boost/spirit/home/classic/attribute.hpp> -#include <boost/spirit/home/classic/utility/functor_parser.hpp> -#include <boost/spirit/home/classic/utility/loops.hpp> -#include <boost/spirit/home/classic/utility/chset.hpp> -#include <boost/spirit/home/classic/utility/confix.hpp> -#include <boost/spirit/home/classic/iterator/file_iterator.hpp> -#include <boost/spirit/home/classic/actor/push_back_actor.hpp> -#include <boost/spirit/home/classic/actor/assign_actor.hpp> +// Boost Spirit (Parsing) +#include <boost/spirit/include/qi.hpp> +#include <boost/spirit/include/phoenix_core.hpp> +#include <boost/spirit/include/phoenix_operator.hpp> +#include <boost/spirit/include/support_multi_pass.hpp> namespace SIMFQT { @@ -25,47 +17,29 @@ // Definition of Basic Types // // /////////////////////////////////////////////////////////////////////// - // For a file, the parsing unit is the character (char). For a string, - // it is a "char const *". - // typedef char const* iterator_t; - typedef char char_t; // The types of iterator, scanner and rule are then derived from // the parsing unit. - typedef boost::spirit::classic::file_iterator<char_t> iterator_t; - typedef boost::spirit::classic::scanner<iterator_t> scanner_t; - typedef boost::spirit::classic::rule<scanner_t> rule_t; - + typedef std::istreambuf_iterator<char> base_iterator_t; + typedef boost::spirit::multi_pass<base_iterator_t> iterator_t; + + // /////////////////////////////////////////////////////////////////////// // // Parser related types // // /////////////////////////////////////////////////////////////////////// /** 1-digit-integer parser */ - typedef boost::spirit::classic::int_parser<unsigned int, 10, 1, 1> int1_p_t; + typedef boost::spirit::qi::int_parser<unsigned int, 10, 1, 1> int1_p_t; /** 2-digit-integer parser */ - typedef boost::spirit::classic::uint_parser<unsigned int, 10, 2, 2> uint2_p_t; + typedef boost::spirit::qi::uint_parser<unsigned int, 10, 2, 2> uint2_p_t; /** 4-digit-integer parser */ - typedef boost::spirit::classic::uint_parser<unsigned int, 10, 4, 4> uint4_p_t; + typedef boost::spirit::qi::uint_parser<unsigned int, 10, 4, 4> uint4_p_t; /** Up-to-4-digit-integer parser */ - typedef boost::spirit::classic::uint_parser<unsigned int, 10, 1, 4> uint1_4_p_t; - - /** character set */ - typedef boost::spirit::classic::chset<char_t> chset_t; - - /** (Repeating) sequence of a given number of characters: - repeat_p(min, max) */ - typedef boost::spirit::classic::impl::loop_traits<chset_t, - unsigned int, - unsigned int>::type repeat_p_t; - - /** Bounded-number-of-integers parser */ - typedef boost::spirit::classic::bounded<uint2_p_t, unsigned int> bounded2_p_t; - typedef boost::spirit::classic::bounded<uint4_p_t, unsigned int> bounded4_p_t; - typedef boost::spirit::classic::bounded<uint1_4_p_t, unsigned int> bounded1_4_p_t; - + typedef boost::spirit::qi::uint_parser<unsigned int, 10, 1, 4> uint1_4_p_t; + } -#endif // __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP +#endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/basic/sources.mk =================================================================== --- trunk/simfqt/simfqt/basic/sources.mk 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/basic/sources.mk 2010-11-29 08:52:23 UTC (rev 23) @@ -1,5 +1,6 @@ simfqt_bas_h_sources = \ $(top_srcdir)/simfqt/basic/BasConst_General.hpp \ - $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp + $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp \ + $(top_srcdir)/simfqt/basic/BasParserTypes.hpp simfqt_bas_cc_sources = \ $(top_srcdir)/simfqt/basic/BasConst.cpp Modified: trunk/simfqt/simfqt/batches/simfqt.cpp =================================================================== --- trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -27,7 +27,7 @@ const std::string K_SIMFQT_DEFAULT_LOG_FILENAME ("simfqt.log"); /** Default name and location for the (CSV) input file. */ -const std::string K_SIMFQT_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare01.csv"); +const std::string K_SIMFQT_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare02.csv"); /** Default query string. */ const std::string K_SIMFQT_DEFAULT_QUERY_STRING ("my good old query"); Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.cpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -24,6 +24,7 @@ _changeFees("T"), _nonRefundable("T"), _minimumStay(0), _fare(0), _airlineCode(""), _classCode("") { + STDAIR_LOG_DEBUG ("fare rule struct."); } // //////////////////////////////////////////////////////////////////// Modified: trunk/simfqt/simfqt/command/FareParser.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParser.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/command/FareParser.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -6,6 +6,7 @@ #include <string> // StdAir //#include <stdair/bom/Inventory.hpp> +#include <stdair/service/Logger.hpp> // AirSched #include <simfqt/command/FareParserHelper.hpp> #include <simfqt/command/FareParser.hpp> @@ -22,6 +23,7 @@ // Parse the CSV-formatted fare input file generate the // corresponding fare rules and fulfill the WorldSchedule. lFareRuleFileParser.generateFareRules (); + STDAIR_LOG_DEBUG ("Finish!"); } } Modified: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -4,6 +4,7 @@ // STL #include <cassert> #include <vector> +#include <fstream> // StdAir #include <stdair/basic/BasFileMgr.hpp> #include <stdair/bom/BomRoot.hpp> @@ -32,16 +33,18 @@ } // ////////////////////////////////////////////////////////////////// - void storeFareId::operator() (unsigned int iFareId) const { - _fareRule._fareId = iFareId; + void storeFareId::operator() (unsigned int iFareId, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + //_fareRule._fareId = iFareId; - //STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule._fareId); + STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule._fareId); _fareRule._nbOfAirlines = 0; - _fareRule._airlineCode = ""; - _fareRule._classCode = ""; - _fareRule._airlineCodeList.clear(); - _fareRule._classCodeList.clear(); + _fareRule._airlineCode = ""; + _fareRule._classCode = ""; + _fareRule._airlineCodeList.clear(); + _fareRule._classCodeList.clear(); } // ////////////////////////////////////////////////////////////////// @@ -51,10 +54,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeOrigin::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::AirportCode_T lOrigin (iStr, iStrEnd); - //STDAIR_LOG_DEBUG ( "Origin: " << lOrigin); + void storeOrigin::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::AirportCode_T lOrigin (iChar.begin(), iChar.end()); + STDAIR_LOG_DEBUG ( "Origin: " << lOrigin); _fareRule._origin = lOrigin; } @@ -65,10 +69,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeDestination::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::AirportCode_T lDestination (iStr, iStrEnd); - //STDAIR_LOG_DEBUG ( "Destination: " << lDestination); + void storeDestination::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::AirportCode_T lDestination (iChar.begin(), iChar.end()); + STDAIR_LOG_DEBUG ( "Destination: " << lDestination); _fareRule._destination = lDestination; } @@ -79,10 +84,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeDateRangeStart::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeDateRangeStart::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._dateRangeStart = _fareRule.getDate(); - //STDAIR_LOG_DEBUG ("Date Range Start: "<< _fareRule._dateRangeStart); + STDAIR_LOG_DEBUG ("Date Range Start: "<< _fareRule._dateRangeStart); } // ////////////////////////////////////////////////////////////////// @@ -92,10 +98,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeDateRangeEnd::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeDateRangeEnd::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._dateRangeEnd = _fareRule.getDate(); - //STDAIR_LOG_DEBUG ("Date Range End: " << _fareRule._dateRangeEnd); + STDAIR_LOG_DEBUG ("Date Range End: " << _fareRule._dateRangeEnd); } // ////////////////////////////////////////////////////////////////// @@ -105,10 +112,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeStartRangeTime::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeStartRangeTime::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._timeRangeStart = _fareRule.getTime(); - //STDAIR_LOG_DEBUG ("Time Range Start: " << _fareRule._timeRangeStart); + STDAIR_LOG_DEBUG ("Time Range Start: " << _fareRule._timeRangeStart); // Reset the number of seconds _fareRule._itSeconds = 0; } @@ -120,10 +128,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeEndRangeTime::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeEndRangeTime::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._timeRangeEnd = _fareRule.getTime(); - // STDAIR_LOG_DEBUG ("Time Range End: " << _fareRule._timeRangeEnd); + STDAIR_LOG_DEBUG ("Time Range End: " << _fareRule._timeRangeEnd); // Reset the number of seconds _fareRule._itSeconds = 0; } @@ -135,11 +144,12 @@ } // ////////////////////////////////////////////////////////////////// - void storePOS::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::AirlineCode_T lPOS (iStr, iStrEnd); + void storePOS::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::AirlineCode_T lPOS (iChar.begin(), iChar.end()); _fareRule._pos = lPOS; - //STDAIR_LOG_DEBUG ("POS: " << _fareRule._pos); + STDAIR_LOG_DEBUG ("POS: " << _fareRule._pos); } // ////////////////////////////////////////////////////////////////// @@ -149,15 +159,16 @@ } // ////////////////////////////////////////////////////////////////// - void storeChannel::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::ChannelLabel_T lChannel (iStr, iStrEnd); + void storeChannel::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::ChannelLabel_T lChannel (iChar.begin(), iChar.end()); _fareRule._channel = lChannel; if (lChannel != "IN" && lChannel != "IF" && lChannel != "DN" && lChannel != "DF") { STDAIR_LOG_DEBUG ("Invalid channel " << lChannel); } - // STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); + STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); } // ////////////////////////////////////////////////////////////////// @@ -167,9 +178,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeAdvancePurchase::operator() (unsigned int iAdancePurchase) const { + void storeAdvancePurchase::operator() (unsigned int iAdancePurchase, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._advancePurchase = iAdancePurchase; - //STDAIR_LOG_DEBUG ( "Advance Purchase: " << _fareRule._advancePurchase); + STDAIR_LOG_DEBUG ( "Advance Purchase: " << _fareRule._advancePurchase); } // ////////////////////////////////////////////////////////////////// @@ -179,7 +192,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeSaturdayStay::operator() (char iSaturdayStay) const { + void storeSaturdayStay::operator() (char iSaturdayStay, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lBool = false; if (iSaturdayStay == 'T') { lBool = true; @@ -190,7 +205,7 @@ } stdair::SaturdayStay_T lSaturdayStay (lBool); _fareRule._saturdayStay = lSaturdayStay; - //STDAIR_LOG_DEBUG ("Saturday Stay: " << _fareRule._saturdayStay); + STDAIR_LOG_DEBUG ("Saturday Stay: " << _fareRule._saturdayStay); } // ////////////////////////////////////////////////////////////////// @@ -200,7 +215,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeChangeFees::operator() (char iChangefees) const { + void storeChangeFees::operator() (char iChangefees, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lBool = false; if (iChangefees == 'T') { @@ -212,7 +229,7 @@ } stdair::ChangeFees_T lChangefees (lBool); _fareRule._changeFees = lChangefees; - //STDAIR_LOG_DEBUG ("Change fees: " << _fareRule._changeFees); + STDAIR_LOG_DEBUG ("Change fees: " << _fareRule._changeFees); } // ////////////////////////////////////////////////////////////////// @@ -222,7 +239,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeNonRefundable::operator() (char iNonRefundable) const { + void storeNonRefundable::operator() (char iNonRefundable, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lBool = false; if (iNonRefundable == 'T') { lBool = true; @@ -233,7 +252,7 @@ } stdair::NonRefundable_T lNonRefundable (lBool); _fareRule._nonRefundable = lNonRefundable; - // STDAIR_LOG_DEBUG ("Non refundable: " << _fareRule._nonRefundable); + STDAIR_LOG_DEBUG ("Non refundable: " << _fareRule._nonRefundable); } // ////////////////////////////////////////////////////////////////// @@ -243,9 +262,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeMinimumStay::operator() (unsigned int iMinStay) const { + void storeMinimumStay::operator() (unsigned int iMinStay, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._minimumStay = iMinStay; - //STDAIR_LOG_DEBUG ("Minimum Stay: " << _fareRule._minimumStay ); + STDAIR_LOG_DEBUG ("Minimum Stay: " << _fareRule._minimumStay ); } // ////////////////////////////////////////////////////////////////// @@ -255,9 +276,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeFare::operator() (double iFare) const { + void storeFare::operator() (double iFare, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._fare = iFare; - // STDAIR_LOG_DEBUG ("Fare: " << _fareRule._fare); + STDAIR_LOG_DEBUG ("Fare: " << _fareRule._fare); } // ////////////////////////////////////////////////////////////////// @@ -267,11 +290,12 @@ } // ////////////////////////////////////////////////////////////////// - void storeAirlineCode::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeAirlineCode::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lAlreadyInTheList = false; - stdair::AirlineCode_T lAirlineCode (iStr, iStrEnd); + stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end()); // Update the airline code _fareRule._airlineCode = lAirlineCode; // Test if the FareRule Struct stands for interline products @@ -299,7 +323,7 @@ << lAirlineCode);*/ _fareRule._airlineCodeList.push_back (lAirlineCode); } - // STDAIR_LOG_DEBUG ( "Airline code: " << lAirlineCode); + STDAIR_LOG_DEBUG ( "Airline code: " << lAirlineCode); } // ////////////////////////////////////////////////////////////////// @@ -309,7 +333,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeClass::operator() (char iChar) const { + void storeClass::operator() (char iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { std::ostringstream ostr; ostr << iChar; std::string classCodeStr = ostr.str(); @@ -319,7 +345,7 @@ std::ostringstream ostrr; ostrr << _fareRule._classCode << classCodeStr; _fareRule._classCode = ostrr.str(); - //STDAIR_LOG_DEBUG ("Class Code: " << lClassCode << std::endl); + STDAIR_LOG_DEBUG ("Class Code: " << lClassCode << std::endl); } @@ -333,164 +359,152 @@ // ////////////////////////////////////////////////////////////////// - void doEndFare::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void doEndFare::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { // Generation of the fare rule object. + STDAIR_LOG_DEBUG ("Do End"); FareRuleGenerator::createFareRule (_bomRoot, _fareRule); - } - + } + // /////////////////////////////////////////////////////////////////// // // Utility Parsers // // /////////////////////////////////////////////////////////////////// - + /** 1-digit-integer parser */ + int1_p_t int1_p; + /** 2-digit-integer parser */ uint2_p_t uint2_p; - + /** 4-digit-integer parser */ uint4_p_t uint4_p; - + /** Up-to-4-digit-integer parser */ uint1_4_p_t uint1_4_p; - /** Sequence of (capital) alphabetic characters: chset_p("A-Z") */ - chset_t alpha_cap_set_p ("A-Z"); - - /** Airport Parser: repeat_p(3)[chset_p("0-9A-Z")] */ - repeat_p_t airport_p (chset_t("0-9A-Z").derived(), 3, 3); - - /** Year Parser: limit_d(2000u, 2099u)[uint4_p] */ - bounded4_p_t year_p (uint4_p.derived(), 2000u, 2099u); - - /** Month Parser: limit_d(1u, 12u)[uint2_p] */ - bounded2_p_t month_p (uint2_p.derived(), 1u, 12u); - - /** Day Parser: limit_d(1u, 31u)[uint2_p] */ - bounded2_p_t day_p (uint2_p.derived(), 1u, 31u); - - /** Hour Parser: limit_d(0u, 23u)[uint2_p] */ - bounded2_p_t hours_p (uint2_p.derived(), 0u, 23u); - - /** Minute Parser: limit_d(0u, 59u)[uint2_p] */ - bounded2_p_t minutes_p (uint2_p.derived(), 0u, 59u); - - /** Second Parser: limit_d(0u, 59u)[uint2_p] */ - bounded2_p_t seconds_p (uint2_p.derived(), 0u, 59u); - - /** Airline Code Parser: repeat_p(2,3)[chset_p("0-9A-Z")] */ - repeat_p_t airline_code_p (chset_t("0-9A-Z").derived(), 2, 3); - - /** Channel type Parser: repeat_p(2,3)[chset_p("A-ZA-Z")] */ - repeat_p_t channel_type_p (chset_t("A-Z").derived(), 2, 3); - // ////////////////////////////////////////////////////////////////// // (Boost Spirit) Grammar Definition // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// - FareRuleParser:: - FareRuleParser (stdair::BomRoot& ioBomRoot, - FareRuleStruct& ioFareRule) - : _bomRoot (ioBomRoot), - _fareRule (ioFareRule) { - } + template <typename ITERATOR> + struct FareRuleParser : + public boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> { - // ////////////////////////////////////////////////////////////////// - template<typename ScannerT> - FareRuleParser::definition<ScannerT>:: - definition (FareRuleParser const& self) { + FareRuleParser (stdair::BomRoot& ioBomRoot, + FareRuleStruct& iofareRule) : + FareRuleParser::base_type(start), + _bomRoot(ioBomRoot), + _fareRule(iofareRule) { - fare_rule_list = *( comments | fare_rule ) - ; + STDAIR_LOG_DEBUG ("Begin parsing"); + + start = * (fare_rule) // *(comments | fare_rule) + ; - comments = boost::spirit::classic::comment_p("//") - | boost::spirit::classic::comment_p("/*", "*/") + comments = (boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("/")]) + >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) + >> +(boost::spirit::ascii::char_) + >> boost::spirit::qi::eol ] + | boost::spirit::qi::lexeme[ + (boost::spirit::ascii::char_("/") + >> boost::spirit::ascii::char_("*") + >> +(boost::spirit::ascii::char_ - boost::spirit::ascii::char_("*")) + >> boost::spirit::ascii::char_("*") + >> boost::spirit::ascii::char_("/")) ]) ; - fare_rule = fare_key - >> +( ';' >> segment ) - >> fare_rule_end[doEndFare(self._bomRoot, self._fareRule)] + fare_rule =// fare_key + //>> +( ';' >> segment ) + //>> + fare_rule_end[doEndFare(_bomRoot, _fareRule)] ; - fare_rule_end = boost::spirit::classic::ch_p(';') + fare_rule_end = boost::spirit::ascii::char_(";") ; fare_key = fare_id - >> ';' >> (airport_p)[storeOrigin(self._fareRule)] - >> ';' >> (airport_p)[storeDestination(self._fareRule)] - >> ';' >> date[storeDateRangeStart(self._fareRule)] - >> ';' >> date[storeDateRangeEnd(self._fareRule)] - >> ';' >> time[storeStartRangeTime(self._fareRule)] - >> ';' >> time[storeEndRangeTime(self._fareRule)] - >> ';' >> (airport_p)[storePOS(self._fareRule)] - >> ';' >> (channel_type_p)[storeChannel(self._fareRule)] - >> ';' >> (uint1_4_p)[storeAdvancePurchase(self._fareRule)] - >> ';' >> (alpha_cap_set_p)[storeSaturdayStay(self._fareRule)] - >> ';' >> (alpha_cap_set_p)[storeChangeFees(self._fareRule)] - >> ';' >> (alpha_cap_set_p)[storeNonRefundable(self._fareRule)] - >> ';' >> (uint1_4_p)[storeMinimumStay(self._fareRule)] - >> ';' >> (boost::spirit::classic::ureal_p)[storeFare(self._fareRule)] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storeOrigin(_fareRule)] ] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storeDestination(_fareRule)] ] + >> ';' >> date[storeDateRangeStart(_fareRule)] + >> ';' >> date[storeDateRangeEnd(_fareRule)] + >> ';' >> time[storeStartRangeTime(_fareRule)] + >> ';' >> time[storeEndRangeTime(_fareRule)] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storePOS(_fareRule)] ] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")])[storeChannel(_fareRule)] ] + >> ';' >> (uint1_4_p)[storeAdvancePurchase(_fareRule)] + >> ';' >> boost::spirit::ascii::char_("A-Z")[storeSaturdayStay(_fareRule)] + >> ';' >> boost::spirit::ascii::char_("A-Z")[storeChangeFees(_fareRule)] + >> ';' >> boost::spirit::ascii::char_("A-Z")[storeNonRefundable(_fareRule)] + >> ';' >> uint1_4_p[storeMinimumStay(_fareRule)] + >> ';' >> boost::spirit::qi::double_[storeFare(_fareRule)] ; - fare_id = boost::spirit::classic::lexeme_d[ - (uint1_4_p)[storeFareId(self._fareRule)]] + fare_id = boost::spirit::qi::lexeme[ + uint1_4_p[storeFareId(_fareRule)] ] ; - date = boost::spirit::classic::lexeme_d[ - (year_p)[boost::spirit::classic::assign_a(self._fareRule._itYear)] - >> '-' - >> (month_p)[boost::spirit::classic::assign_a(self._fareRule._itMonth)] - >> '-' - >> (day_p)[boost::spirit::classic::assign_a(self._fareRule._itDay)]] + date = boost::spirit::qi::lexeme[ + uint4_p[boost::phoenix::ref(_fareRule._itYear) = boost::spirit::qi::labels::_1] + >> '-' + >> uint2_p[boost::phoenix::ref(_fareRule._itMonth) =boost::spirit::qi::labels::_1] + >> '-' + >> uint2_p[boost::phoenix::ref(_fareRule._itDay) = boost::spirit::qi::labels::_1] ] ; - - time = boost::spirit::classic::lexeme_d[ - (hours_p)[boost::spirit::classic::assign_a(self._fareRule._itHours)] - >> ':' - >> (minutes_p)[boost::spirit::classic::assign_a(self._fareRule._itMinutes)] - >> !(':' >> (seconds_p)[boost::spirit::classic::assign_a(self._fareRule._itSeconds)])] - ; + + time = boost::spirit::qi::lexeme[ + uint2_p[boost::phoenix::ref(_fareRule._itHours) = boost::spirit::qi::labels::_1] + >> ':' + >> uint2_p[boost::phoenix::ref(_fareRule._itMinutes) = boost::spirit::qi::labels::_1] + >> !(':' >> (uint2_p)[boost::phoenix::ref(_fareRule._itSeconds) = boost::spirit::qi::labels::_1]) ] + ; - segment = boost::spirit::classic::lexeme_d[ - (airline_code_p)[storeAirlineCode(self._fareRule)]] - >> ';' >> (alpha_cap_set_p)[storeClass(self._fareRule)] + segment = boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")])[storeAirlineCode(_fareRule)] ] + >> ';' + >> boost::spirit::ascii::char_("A-Z")[storeClass(_fareRule)] ; - //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); - BOOST_SPIRIT_DEBUG_NODE (fare_rule_list); - BOOST_SPIRIT_DEBUG_NODE (comments); - BOOST_SPIRIT_DEBUG_NODE (fare_rule); - BOOST_SPIRIT_DEBUG_NODE (fare_id); - BOOST_SPIRIT_DEBUG_NODE (fare_key); - BOOST_SPIRIT_DEBUG_NODE (segment); - BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); - BOOST_SPIRIT_DEBUG_NODE (date); - BOOST_SPIRIT_DEBUG_NODE (time); + //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); + BOOST_SPIRIT_DEBUG_NODE (start); + BOOST_SPIRIT_DEBUG_NODE (comments); + BOOST_SPIRIT_DEBUG_NODE (fare_rule); + BOOST_SPIRIT_DEBUG_NODE (fare_id); + BOOST_SPIRIT_DEBUG_NODE (fare_key); + BOOST_SPIRIT_DEBUG_NODE (segment); + BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); + BOOST_SPIRIT_DEBUG_NODE (date); + BOOST_SPIRIT_DEBUG_NODE (time); + } - } + boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> + start, comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, + date, time; + + // Parser Context + stdair::BomRoot& _bomRoot; + FareRuleStruct& _fareRule; + }; - // ////////////////////////////////////////////////////////////////// - template<typename ScannerT> - boost::spirit::classic::rule<ScannerT> const& - FareRuleParser::definition<ScannerT>::start() const { - return fare_rule_list; - } - } - - ///////////////////////////////////////////////////////////////////////// // // Entry class for the file parser // ///////////////////////////////////////////////////////////////////////// - + // ////////////////////////////////////////////////////////////////////// FareRuleFileParser:: - FareRuleFileParser (stdair::BomRoot& ioBomRoot, - const stdair::Filename_T& iFilename) + FareRuleFileParser (stdair::BomRoot& ioBomRoot, + const stdair::Filename_T& iFilename) : _filename (iFilename), _bomRoot (ioBomRoot) { init(); } @@ -503,61 +517,65 @@ if (doesExistAndIsReadable == false) { STDAIR_LOG_ERROR ("The fare schedule file " << _filename - << " does not exist or can not be read."); + << " does not exist or can not be read."); throw FareInputFileNotFoundException ("The fare file " + _filename + " does not exist or can not be read"); } - // Open the file - _startIterator = iterator_t (_filename); + // File to be parsed + const std::string* lFileName = &_filename; + const char *lChar = (*lFileName).c_str(); + std::ifstream fileToBeParsed(lChar, std::ios_base::in); // Check the filename exists and can be open - if (!_startIterator) { + if (fileToBeParsed == false) { STDAIR_LOG_ERROR ("The fare file " << _filename << " can not be open." << std::endl); throw FareInputFileNotFoundException ("The file " + _filename + " does not exist or can not be read"); } + + // Create an input iterator + base_iterator_t inputBegin(fileToBeParsed); + typedef boost::spirit::multi_pass<base_iterator_t> iterator_t; - // Create an EOF iterator - _endIterator = _startIterator.make_end(); + // Convert input iterator to an iterator usable by spirit parser + iterator_t _startIterator = boost::spirit::make_default_multi_pass(inputBegin); } // ////////////////////////////////////////////////////////////////////// bool FareRuleFileParser::generateFareRules () { - bool oResult = false; STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); // Initialise the parser (grammar) with the helper/staging structure. - FareParserHelper::FareRuleParser lFPParser (_bomRoot, _fareRule); + typedef FareParserHelper::FareRuleParser<iterator_t> FareRule_T; + FareRule_T lFPParser(_bomRoot, _fareRule); // Launch the parsing of the file and, thanks to the doEndFare // call-back structure, the building of the whole BomRoot BOM - boost::spirit::classic::parse_info<iterator_t> info = - boost::spirit::classic::parse (_startIterator, _endIterator, lFPParser, - boost::spirit::classic::space_p); - - // Retrieves whether or not the parsing was successful - oResult = info.hit; + STDAIR_LOG_DEBUG ("Begin parsing"); + + const bool hasParsingBeenSuccesful = + boost::spirit::qi::phrase_parse(_startIterator, _endIterator, lFPParser, boost::spirit::ascii::space); - const std::string hasBeenFullyReadStr = (info.full == true)?"":"not "; - if (oResult == true) { - STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename - << " succeeded: read " << info.length - << " characters. The input file has " - << hasBeenFullyReadStr - << "been fully read. Stop point: " << info.stop); + STDAIR_LOG_DEBUG ("Finish parsing"); + if (hasParsingBeenSuccesful == false) { + // TODO: decide whether to throw an exceqption + STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename + << " failed"); - } else { - // TODO: decide whether to throw an exception - STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename - << " failed: read " << info.length - << " characters. The input file has " - << hasBeenFullyReadStr - << "been fully read. Stop point: " << info.stop); } - return oResult; + // if (_startIterator != _endIterator) { + // // TODO: decide whether to throw an exception + // STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename + // << " failed"); + // } + // if (hasParsingBeenSuccesful == true && _startIterator == _endIterator) { + // STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename + // << " succeeded ;)"); + // } + return hasParsingBeenSuccesful; } } Modified: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-29 08:52:23 UTC (rev 23) @@ -6,10 +6,10 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> -// #define BOOST_SPIRIT_DEBUG +//#define BOOST_SPIRIT_DEBUG // StdAir #include <stdair/command/CmdAbstract.hpp> -// AirSched +// Simfqt #include <simfqt/SIMFQT_Types.hpp> #include <simfqt/basic/BasParserTypes.hpp> #include <simfqt/bom/FareRuleStruct.hpp> @@ -40,7 +40,9 @@ /** Actor Constructor. */ storeFareId (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (unsigned int) const; + void operator() (unsigned int, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed origin. */ @@ -48,7 +50,9 @@ /** Actor Constructor. */ storeOrigin (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed destination. */ @@ -56,7 +60,9 @@ /** Actor Constructor. */ storeDestination (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed start of the date range. */ @@ -64,7 +70,9 @@ /** Actor Constructor. */ storeDateRangeStart (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed end of the date range. */ @@ -72,7 +80,9 @@ /** Actor Constructor. */ storeDateRangeEnd (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed start range time. */ @@ -80,7 +90,9 @@ /** Actor Constructor. */ storeStartRangeTime (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t iStr, iterator_t iStrEnd) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed end start range time. */ @@ -88,7 +100,9 @@ /** Actor Constructor. */ storeEndRangeTime (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed customer position. */ @@ -96,7 +110,9 @@ /** Actor Constructor. */ storePOS (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the channel distribution. */ @@ -104,7 +120,9 @@ /** Actor Constructor. */ storeChannel (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed advance purchase days. */ @@ -112,7 +130,9 @@ /** Actor Constructor. */ storeAdvancePurchase (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (unsigned int) const; + void operator() (unsigned int, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed saturday night. */ @@ -120,7 +140,9 @@ /** Actor Constructor. */ storeSaturdayStay (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed change fees. */ @@ -128,7 +150,9 @@ /** Actor Constructor. */ storeChangeFees (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed refundable option */ @@ -136,7 +160,9 @@ /** Actor Constructor. */ storeNonRefundable (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed minimum stay. */ @@ -144,7 +170,9 @@ /** Actor Constructor. */ storeMinimumStay (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (unsigned int) const; + void operator() (unsigned int, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed fare value. */ @@ -152,7 +180,9 @@ /** Actor Constructor. */ storeFare (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (double) const; + void operator() (double, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed airline code. */ @@ -160,7 +190,9 @@ /** Actor Constructor. */ storeAirlineCode (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed class. */ @@ -168,7 +200,9 @@ /** Actor Constructor. */ storeClass (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Mark the end of the fare-rule parsing. */ @@ -176,7 +210,9 @@ /** Actor Constructor. */ doEndFare (stdair::BomRoot&, FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; /** Actor Specific Context. */ stdair::BomRoot& _bomRoot; }; @@ -255,27 +291,20 @@ */ /** Grammar for the Fare-Rule parser. */ + /*template <typename ITERATOR> struct FareRuleParser : - public boost::spirit::classic::grammar<FareRuleParser> { + public boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> { FareRuleParser (stdair::BomRoot&, FareRuleStruct&); - template <typename ScannerT> - struct definition { - definition (FareRuleParser const& self); + boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> start, + comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, date, + time; - // Instantiation of rules - boost::spirit::classic::rule<ScannerT> fare_rule_list, comments, - fare_rule, fare_id, fare_key, segment, fare_rule_end, date, time; - - /** Entry point of the parser. */ - boost::spirit::classic::rule<ScannerT> const& start() const; - }; - // Parser Context stdair::BomRoot& _bomRoot; FareRuleStruct& _fareRule; - }; + };*/ } /** Short Description @@ -316,7 +345,7 @@ /** End iterator for the parser. */ iterator_t _endIterator; - + /** stdair::BomRoot. */ stdair::BomRoot& _bomRoot; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |