00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef EXTENDED_REGULAR_EXPRESSIONERE_DUPL_SYMBOL_H
00021 #define EXTENDED_REGULAR_EXPRESSIONERE_DUPL_SYMBOL_H
00022
00023 namespace extended_regular_expression {
00024
00043 template<typename E>
00044 class ere_dupl_symbol
00045 {
00046 typedef typename grammar_to_parser::basic_parser<E>::parser_list
00047 parser_list;
00048
00049 class dup_count
00050 {
00051 protected:
00052 grammar_to_parser::basic_terminal<E,'{'> m_left_bracket;
00053 grammar_to_parser::basic_value_parser<E,unsigned long> m_repeat_min;
00054 grammar_to_parser::basic_terminal<E,'}'> m_right_bracket;
00055 public:
00056 void push_parsers( parser_list &l )
00057 {
00058 l.push_back(&m_left_bracket);
00059 l.push_back(&m_repeat_min);
00060 l.push_back(&m_right_bracket);
00061 }
00062 virtual unsigned long get_min()
00063 {
00064 return m_repeat_min.get_valid();
00065 }
00066 virtual unsigned long get_max()
00067 {
00068 return m_repeat_min.get_valid();
00069 }
00070 };
00071
00072 class dup_count_unbound : public dup_count
00073 {
00074 protected:
00075 grammar_to_parser::basic_terminal<E,','> m_sep;
00076 public:
00077 void push_parsers( parser_list &l )
00078 {
00079 l.push_back(&m_left_bracket);
00080 l.push_back(&m_repeat_min);
00081 l.push_back(&m_sep);
00082 l.push_back(&m_right_bracket);
00083 }
00084 unsigned long get_max()
00085 {
00086
00087 long i = -1;
00088 return (unsigned long)i;
00089
00090 }
00091
00092 };
00093
00094 class dup_count_max : public dup_count_unbound
00095 {
00096 protected:
00097 grammar_to_parser::basic_value_parser<E,unsigned long>
00098 m_repeat_max;
00099 public:
00100 void push_parsers( parser_list &l )
00101 {
00102 l.push_back(&m_left_bracket);
00103 l.push_back(&m_repeat_min);
00104 l.push_back(&m_sep);
00105 l.push_back(&m_repeat_max);
00106 l.push_back(&m_right_bracket);
00107 }
00108 unsigned long get_max()
00109 {
00110 return m_repeat_max.get_valid();
00111 }
00112
00113 };
00114
00115 class lazy_star
00116 {
00117 grammar_to_parser::basic_terminal<E, '*'> m_star;
00118 grammar_to_parser::basic_terminal<E, '?'> m_lazy;
00119 public:
00120 void push_parsers( parser_list& l )
00121 {
00122 l.push_back( &m_star );
00123 l.push_back( &m_lazy );
00124 }
00125 };
00126
00127 class lazy_plus
00128 {
00129 grammar_to_parser::basic_terminal<E, '*'> m_plus;
00130 grammar_to_parser::basic_terminal<E, '?'> m_lazy;
00131 public:
00132 void push_parsers( parser_list& l )
00133 {
00134 l.push_back( &m_plus );
00135 l.push_back( &m_lazy );
00136 }
00137 };
00138
00139 grammar_to_parser::basic_non_terminal<E, lazy_star> m_lazy_star;
00140 grammar_to_parser::basic_non_terminal<E, lazy_plus> m_lazy_plus;
00141 grammar_to_parser::basic_terminal<E,'*'> m_star;
00142 grammar_to_parser::basic_terminal<E,'+'> m_plus;
00143 grammar_to_parser::basic_terminal<E,'?'> m_question_mark;
00144 grammar_to_parser::basic_non_terminal<E,dup_count> m_dup;
00145 grammar_to_parser::basic_non_terminal<E,dup_count_unbound>
00146 m_dup_unbound;
00147 grammar_to_parser::basic_non_terminal<E,dup_count_max>
00148 m_dup_max;
00149
00150 unsigned long m_rep;
00151 public:
00152
00153 ere_dupl_symbol() :
00154 m_lazy_star(),
00155 m_lazy_plus(),
00156 m_dup(),
00157 m_dup_unbound(),
00158 m_dup_max() {};
00159 ~ere_dupl_symbol() {};
00160
00161 bool is_lazy()
00162 {
00163 return m_lazy_star.is_parsed() || m_lazy_plus.is_parsed();
00164 }
00165
00166 unsigned long get_min()
00167 {
00168
00169 if( m_star.is_parsed() ) return 0;
00170 else if( m_plus.is_parsed() ) return 1;
00171 else if( m_lazy_star.is_parsed() ) return 0;
00172 else if( m_lazy_plus.is_parsed() ) return 1;
00173 else if( m_question_mark.is_parsed() ) return 0;
00174 else if( m_dup.is_parsed() ) return m_dup->get_min();
00175 else if( m_dup_unbound.is_parsed() ) return m_dup_unbound->get_min();
00176 else return m_dup_max->get_min();
00177 }
00178
00179 unsigned long get_max()
00180 {
00181 if( m_star.is_parsed() ) return INT_MAX;
00182 else if( m_plus.is_parsed() ) return INT_MAX;
00183 else if( m_lazy_star.is_parsed() ) return INT_MAX;
00184 else if( m_lazy_plus.is_parsed() ) return INT_MAX;
00185 else if( m_question_mark.is_parsed() ) return 1;
00186 else if( m_dup.is_parsed() ) return m_dup->get_max();
00187 else if( m_dup_unbound.is_parsed() ) return m_dup_unbound->get_max();
00188 else return m_dup_max->get_max();
00189 }
00190
00191 void set_recognized_dup( unsigned long rec_dup )
00192 {
00193 m_rep = rec_dup;
00194 }
00195
00196 unsigned long get_recognized_dup()
00197 {
00198 return m_rep;
00199 }
00200
00201 void push_parsers( parser_list &l )
00202 {
00203 l.push_back(&m_lazy_star);
00204 l.push_back(&m_lazy_plus);
00205 l.push_back(&m_star);
00206 l.push_back(&m_plus);
00207 l.push_back(&m_question_mark);
00208 l.push_back(&m_dup);
00209 l.push_back(&m_dup_unbound);
00210 l.push_back(&m_dup_max);
00211 }
00212 };
00213
00214 };
00215
00216 #endif