From: <gsa...@us...> - 2010-12-01 10:35:00
|
Revision: 26 http://simfqt.svn.sourceforge.net/simfqt/?rev=26&view=rev Author: gsabatier Date: 2010-12-01 10:34:54 +0000 (Wed, 01 Dec 2010) Log Message: ----------- [Simfqt] A few improvements with spirit v2 parser Modified Paths: -------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 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-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-12-01 10:34:54 UTC (rev 26) @@ -4,6 +4,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// STL +#include <string> // Boost Spirit (Parsing) #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> @@ -40,6 +42,7 @@ /** Up-to-4-digit-integer parser */ typedef boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p_t; +; } #endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.cpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-12-01 10:34:54 UTC (rev 26) @@ -24,7 +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-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/command/FareParser.cpp 2010-12-01 10:34:54 UTC (rev 26) @@ -23,7 +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-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-12-01 10:34:54 UTC (rev 26) @@ -163,11 +163,11 @@ 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); } + _fareRule._channel = lChannel; STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); } @@ -345,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); } @@ -394,79 +394,141 @@ FareRuleParser::base_type(start), _bomRoot(ioBomRoot), _fareRule(iofareRule) { - + start = *(comments | fare_rule) ; + + comments = (boost::spirit::qi::lexeme[ + boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_('/')] + >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) + >> 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(_bomRoot, _fareRule)] + ; + + fare_rule_end = boost::spirit::ascii::char_(';') + ; + + fare_key = fare_id + >> ';' >> origin >> ';' >> destination + >> ';' >> dateRangeStart >> ';' >> dateRangeEnd + >> ';' >> timeRangeStart >> ';' >> timeRangeEnd + >> ';' >> position + >> ';' >> channel + >> ';' >> advancePurchase + >> ';' >> saturdayStay + >> ';' >> changeFees + >> ';' >> nonRefundable + >> ';' >> minimumStay + >> ';' >> fare + ; + + fare_id = uint1_4_p[storeFareId(_fareRule)] + ; + + origin = boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")][storeOrigin(_fareRule)] + ; - comments = (boost::spirit::qi::lexeme[ (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("/")]) >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) >> 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_("/")) ]) - ; + destination = boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")][storeDestination(_fareRule)] + ; + + dateRangeStart = date[storeDateRangeStart(_fareRule)] + ; - fare_rule = fare_key - >> +( ';' >> segment ) - >> fare_rule_end[doEndFare(_bomRoot, _fareRule)] - ; + dateRangeEnd = date[storeDateRangeEnd(_fareRule)] + ; + + 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] + ] + ; - fare_rule_end = boost::spirit::ascii::char_(";") - ; + timeRangeStart = time[storeStartRangeTime(_fareRule)] + ; + + timeRangeEnd = time[storeEndRangeTime(_fareRule)] + ; - fare_key = fare_id - >> ';' >> 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)] - ; + 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]) + ] + ; - fare_id = uint1_4_p[storeFareId(_fareRule)]; - - 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::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]) ] - ; + position = boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")][storePOS(_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)] - ; + channel = boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")][storeChannel(_fareRule)] + ; + + advancePurchase = uint1_4_p[storeAdvancePurchase(_fareRule)] + ; - //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); + saturdayStay = boost::spirit::ascii::char_("A-Z")[storeSaturdayStay(_fareRule)] + ; + + changeFees = boost::spirit::ascii::char_("A-Z")[storeChangeFees(_fareRule)] + ; + + nonRefundable = boost::spirit::ascii::char_("A-Z")[storeNonRefundable(_fareRule)] + ; + + minimumStay = uint1_4_p[storeMinimumStay(_fareRule)] + ; + + fare = boost::spirit::qi::double_[storeFare(_fareRule)] + ; + + segment = 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 (start); + BOOST_SPIRIT_DEBUG_NODE (comments); + BOOST_SPIRIT_DEBUG_NODE (fare_rule); + BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); + BOOST_SPIRIT_DEBUG_NODE (fare_key); + BOOST_SPIRIT_DEBUG_NODE (fare_id); + BOOST_SPIRIT_DEBUG_NODE (origin); + BOOST_SPIRIT_DEBUG_NODE (destination); + BOOST_SPIRIT_DEBUG_NODE (dateRangeStart); + BOOST_SPIRIT_DEBUG_NODE (dateRangeEnd); + BOOST_SPIRIT_DEBUG_NODE (date); + BOOST_SPIRIT_DEBUG_NODE (timeRangeStart); + BOOST_SPIRIT_DEBUG_NODE (timeRangeEnd); + BOOST_SPIRIT_DEBUG_NODE (time); + BOOST_SPIRIT_DEBUG_NODE (position); + BOOST_SPIRIT_DEBUG_NODE (channel); + BOOST_SPIRIT_DEBUG_NODE (advancePurchase); + BOOST_SPIRIT_DEBUG_NODE (saturdayStay); + BOOST_SPIRIT_DEBUG_NODE (changeFees); + BOOST_SPIRIT_DEBUG_NODE (nonRefundable); + BOOST_SPIRIT_DEBUG_NODE (minimumStay); + BOOST_SPIRIT_DEBUG_NODE (fare); + BOOST_SPIRIT_DEBUG_NODE (segment); } } + ///////////////////////////////////////////////////////////////////////// // // Entry class for the file parser @@ -500,8 +562,6 @@ STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); - - // File to be parsed const std::string* lFileName = &_filename; const char *lChar = (*lFileName).c_str(); @@ -527,10 +587,9 @@ // Launch the parsing of the file and, thanks to the doEndFare // call-back structure, the building of the whole BomRoot BOM - STDAIR_LOG_DEBUG ("Begin parsing") ; + const bool hasParsingBeenSuccesful = boost::spirit::qi::phrase_parse(start, end, lFPParser, boost::spirit::ascii::space); - STDAIR_LOG_DEBUG ("End parsing") ; if (hasParsingBeenSuccesful == false) { // TODO: decide whether to throw an exceqption @@ -545,7 +604,7 @@ } if (hasParsingBeenSuccesful == true && start == end) { STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename - << " succeeded ;)"); + << " succeeded"); } return hasParsingBeenSuccesful; } Modified: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-12-01 10:34:54 UTC (rev 26) @@ -298,8 +298,10 @@ // Instantiation of rules boost::spirit::qi::rule<iterator_t, boost::spirit::ascii::space_type> - start, comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, - date, time; + start, comments, fare_rule, fare_rule_end, fare_key, fare_id, origin, + destination, dateRangeStart, dateRangeEnd, date, timeRangeStart, + timeRangeEnd, time, position, channel, advancePurchase, saturdayStay, + changeFees, nonRefundable, minimumStay, fare, segment; // Parser Context stdair::BomRoot& _bomRoot; @@ -307,10 +309,7 @@ }; } - /** Short Description - <br> Detailed Description.*/ - ///////////////////////////////////////////////////////////////////////// // // Entry class for the file parser This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |