00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef BRACKET_EXPRESSIONBRACKET_LIST_H
00021 #define BRACKET_EXPRESSIONBRACKET_LIST_H
00022
00023 namespace bracket_expression {
00024
00025 template<typename E>
00026 class bracket_list
00027 {
00028 typedef typename grammar_to_parser::basic_parser<E>::parser_list
00029 parser_list;
00030
00031 class follow_list_and_hyphen
00032 {
00033 grammar_to_parser::basic_choice<E,follow_list<E> > m_follow_list;
00034 grammar_to_parser::basic_terminal<E,'-'> m_hyphen;
00035
00036 public:
00037 unsigned long recognize( const E* buf, const unsigned long buf_length )
00038 {
00039 unsigned long size = m_follow_list->recognize(buf,buf_length);
00040 if( size == 0 )
00041 {
00042 if( buf[0] == m_hyphen.get_valid() )
00043 {
00044 size = 1;
00045 }
00046 }
00047 return size;
00048 }
00049 follow_list_and_hyphen() {};
00050
00051 ~follow_list_and_hyphen() {};
00052 void push_parsers( parser_list &l )
00053 {
00054 l.push_back( &m_follow_list );
00055 l.push_back( &m_hyphen );
00056 }
00057
00058 };
00059
00060 class hyphen_and_follow_list
00061 {
00062 grammar_to_parser::basic_terminal<E,'-'> m_hyphen;
00063 grammar_to_parser::basic_choice<E,follow_list<E> > m_follow_list;
00064 public:
00065 unsigned long recognize( const E* buf, const unsigned long buf_length )
00066 {
00067 if( buf[0] == m_hyphen.get_valid() )
00068 {
00069 return 1;
00070 }
00071 else
00072 {
00073 return m_follow_list->recognize(buf,buf_length);
00074 }
00075 }
00076 void push_parsers( parser_list &l )
00077 {
00078 l.push_back( &m_hyphen );
00079 l.push_back( &m_follow_list );
00080 }
00081 };
00082
00083 class hyphen_hyphen_end_range
00084 {
00085 protected:
00086 grammar_to_parser::basic_terminal<E,'-'> m_hyphen;
00087 grammar_to_parser::basic_terminal<E,'-'> m_sep;
00088 grammar_to_parser::basic_choice<E,collating_choice<E> > m_end_range;
00089 public:
00090 virtual unsigned long recognize( const E* buf, const unsigned long buf_length )
00091 {
00092 std::locale l;
00093
00094 int end_ret = m_end_range->compare(buf,buf_length);
00095 int size = m_end_range->matched_size();
00096 while( end_ret > 0 && size > 1)
00097 {
00098 size--;
00099
00100
00101 end_ret = m_end_range->compare(buf,size);
00102 }
00103 int start_ret = 0;
00104 if( end_ret < 0 )
00105 {
00106 start_ret = std::use_facet<std::collate<E> >(l).compare(
00107 buf,
00108 buf+size,
00109 m_hyphen.get(),
00110 m_hyphen.get()+1);
00111 while( start_ret < 0 &&
00112 size > 1 &&
00113 m_end_range->compare(buf,size-1) <= 0 )
00114 {
00115 size--;
00116 start_ret = std::use_facet<std::collate<E> >(l).compare(
00117 buf,
00118 buf+size,
00119 m_hyphen.get(),
00120 m_hyphen.get()+1);
00121 }
00122 }
00123 if( start_ret >=0 && end_ret <= 0 )
00124 return size;
00125 else
00126 return 0;
00127 }
00128 virtual void push_parsers( parser_list &l )
00129 {
00130 l.push_back( &m_hyphen );
00131 l.push_back( &m_sep );
00132 l.push_back( &m_end_range );
00133 }
00134 };
00135
00136 class hyphen_hyphen_endrange_follow_list : public hyphen_hyphen_end_range
00137 {
00138 protected:
00139 grammar_to_parser::basic_choice<E,follow_list<E> > m_follow_list;
00140 public:
00141 virtual unsigned long recognize( const E* buf, const unsigned long buf_length )
00142 {
00143 int ret = hyphen_hyphen_end_range::recognize(buf,buf_length);
00144 if( ret == 0 )
00145 {
00146 return m_follow_list->recognize(buf,buf_length);
00147 }
00148 else
00149 {
00150 return ret;
00151 }
00152 }
00153 void push_parsers( parser_list &l )
00154 {
00155 hyphen_hyphen_end_range::push_parsers(l);
00156 l.push_back( &m_follow_list );
00157 }
00158 };
00159 grammar_to_parser::basic_choice<E,follow_list<E> >
00160 m_follow_list;
00161 grammar_to_parser::basic_non_terminal<E,follow_list_and_hyphen >
00162 m_follow_list_hyphen;
00163 grammar_to_parser::basic_non_terminal<E,hyphen_and_follow_list >
00164 m_hyphen_follow_list;
00165 grammar_to_parser::basic_non_terminal<E,hyphen_hyphen_end_range>
00166 m_hyphen_hyphen_end_range;
00167 grammar_to_parser::basic_non_terminal<E,hyphen_hyphen_endrange_follow_list>
00168 m_hyphen_hyphen_endrange_follow;
00169
00170 public:
00171 unsigned long recognize( const E* buf, const unsigned long buf_length )
00172 {
00173 if( m_follow_list.is_parsed() )
00174 {
00175 return m_follow_list->recognize(buf,buf_length);
00176 }
00177 else if( m_follow_list_hyphen.is_parsed() )
00178 {
00179 return m_follow_list_hyphen->recognize(buf,buf_length);
00180 }
00181 else if( m_hyphen_follow_list.is_parsed() )
00182 {
00183 return m_hyphen_follow_list->recognize(buf,buf_length);
00184 }
00185 else if( m_hyphen_hyphen_end_range.is_parsed() )
00186 {
00187 return m_hyphen_hyphen_end_range->recognize(buf,buf_length);
00188 }
00189 else
00190 {
00191 return m_hyphen_hyphen_endrange_follow->recognize(buf,buf_length);
00192 }
00193 }
00194
00195 bracket_list() :
00196 m_follow_list_hyphen(),
00197 m_hyphen_follow_list(),
00198 m_hyphen_hyphen_end_range(),
00199 m_hyphen_hyphen_endrange_follow() {};
00200
00201 ~bracket_list() {};
00202
00203 void push_parsers( parser_list &l )
00204 {
00205
00206
00207
00208
00209
00210
00211 l.push_back( &m_hyphen_hyphen_endrange_follow );
00212 l.push_back( &m_hyphen_hyphen_end_range );
00213 l.push_back( &m_hyphen_follow_list );
00214 l.push_back( &m_follow_list_hyphen );
00215 l.push_back( &m_follow_list );
00216 }
00217 };
00218
00219 };
00220
00221 #endif