Welcome to mirror list, hosted at ThFree Co, Russian Federation.

parse_months.cpp « opening_hours « 3party - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d16e1864e8d4962a0a4f85f88c7cb11d09d664d6 (plain)
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
#include "parse_opening_hours.hpp"
#include "opening_hours_parsers.hpp"

#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>

namespace osmoh
{
  namespace parsing
  {
    month_selector_parser::month_selector_parser() : month_selector_parser::base_type(main)
    {
      using qi::_1;
      using qi::_2;
      using qi::_3;
      using qi::_a;
      using qi::_val;
      using qi::uint_;
      using qi::ushort_;
      using qi::lit;
      using qi::double_;
      using qi::lexeme;
      using osmoh::DateOffset;
      using osmoh::MonthDay;
      using osmoh::MonthdayRange;

      static const qi::int_parser<unsigned, 10, 4, 4> year = {};

      day_offset = ((lit('+')[_a = 1] | lit('-')[_a = -1]) >>
                    ushort_ >> charset::no_case[(lit("days") | lit("day"))]) [_val = _a * _1];

      date_offset = ((lit('+')[_a = true] | lit('-')[_a = false])
                     >> charset::no_case[wdays] >> day_offset)
      [bind(&DateOffset::SetWDayOffset, _val, _1),
       bind(&DateOffset::SetOffset, _val, _2),
       bind(&DateOffset::SetWDayOffsetPositive, _val, _a)]
      | ((lit('+')[_a = true] | lit('-') [_a = false]) >> charset::no_case[wdays])
      [bind(&DateOffset::SetWDayOffset, _val, _1),
       bind(&DateOffset::SetWDayOffsetPositive, _val, _a)]
      | day_offset [bind(&DateOffset::SetOffset, _val, _1)]
      ;

      date_left = (year >> charset::no_case[month]) [bind(&MonthDay::SetYear, _val, _1),
                                                     bind(&MonthDay::SetMonth, _val, _2)]

      | charset::no_case[month]                 [bind(&MonthDay::SetMonth, _val, _1)]
      ;

      date_right = charset::no_case[month]          [bind(&MonthDay::SetMonth, _val, _1)]
      ;

      date_from = (date_left >> (daynum >> !(lit(':') >> qi::digit)))
      [_val = _1, bind(&MonthDay::SetDayNum, _val, _2)]
      | (year >> charset::no_case[lit("easter")]) [bind(&MonthDay::SetYear, _val, _1),
                                                   bind(&MonthDay::SetVariableDate, _val,
                                                        MonthDay::VariableDate::Easter)]
      | charset::no_case[lit("easter")]           [bind(&MonthDay::SetVariableDate, _val,
                                                        MonthDay::VariableDate::Easter)]
      ;

      date_to = date_from                        [_val = _1]
      | (daynum >> !(lit(':') >> qi::digit)) [bind(&MonthDay::SetDayNum, _val, _1)]
      ;

      date_from_with_offset = (date_from >> date_offset)
      [_val = _1, bind(&MonthDay::SetOffset, _val, _2)]
      | date_from         [_val = _1]
      ;

      date_to_with_offset = (date_to >> date_offset)
      [_val = _1, bind(&MonthDay::SetOffset, _val, _2)]
      | date_to         [_val = _1]
      ;

      monthday_range = (date_from_with_offset >> dash >> date_to_with_offset)
      [bind(&MonthdayRange::SetStart, _val, _1),
       bind(&MonthdayRange::SetEnd, _val, _2)]
      | (date_from_with_offset >> '+') [bind(&MonthdayRange::SetStart, _val, _1),
                                        bind(&MonthdayRange::SetPlus, _val, true)]
      | (date_left >> dash >> date_right >> '/' >> uint_)
      [bind(&MonthdayRange::SetStart, _val, _1),
       bind(&MonthdayRange::SetEnd, _val, _2),
       bind(&MonthdayRange::SetPeriod, _val, _3)]
      | (date_left >> lit("-") >> date_right) [bind(&MonthdayRange::SetStart, _val, _1),
                                               bind(&MonthdayRange::SetEnd, _val, _2)]
      | date_from [bind(&MonthdayRange::SetStart, _val, _1)]
      | date_left [bind(&MonthdayRange::SetStart, _val, _1)]
      ;

      main %= (monthday_range % ',');

      BOOST_SPIRIT_DEBUG_NODE(main);
      BOOST_SPIRIT_DEBUG_NODE(monthday_range);
      BOOST_SPIRIT_DEBUG_NODE(day_offset);
      BOOST_SPIRIT_DEBUG_NODE(date_offset);
      BOOST_SPIRIT_DEBUG_NODE(date_left);
      BOOST_SPIRIT_DEBUG_NODE(date_right);
      BOOST_SPIRIT_DEBUG_NODE(date_from);
      BOOST_SPIRIT_DEBUG_NODE(date_to);
      BOOST_SPIRIT_DEBUG_NODE(date_from_with_offset);
      BOOST_SPIRIT_DEBUG_NODE(date_to_with_offset);
    }
  }

  bool Parse(std::string const & str, TMonthdayRanges & context)
  {
    return osmoh::ParseImpl<parsing::month_selector_parser>(str, context);
  }
} // namespace osmoh