00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef EXTENDED_REGULAR_EXPRESSIONERE_EXPRESSION_H
00021 #define EXTENDED_REGULAR_EXPRESSIONERE_EXPRESSION_H
00022
00023 namespace extended_regular_expression {
00024
00025 template< typename E > class extended_reg_exp;
00026
00045 template<typename E>
00046 class ere_expression : public ere_base<E>
00047 {
00048 typedef typename grammar_to_parser::basic_parser<E>::parser_list
00049 parser_list;
00050
00051 class subexpression : public ere_base<E>
00052 {
00053 grammar_to_parser::basic_terminal<E,'('> m_left_paren;
00054 grammar_to_parser::basic_choice<E,extended_reg_exp<E> > m_extened_regexp;
00055 grammar_to_parser::basic_terminal<E,')'> m_right_paren;
00056 public:
00057 subexpression() : ere_base<E>() {};
00058 ~subexpression() {};
00059
00060 unsigned long recognize( const E* buf,
00061 const unsigned long buf_length,
00062 const unsigned long buf_offset,
00063 bool try_positions = true );
00064 void assign_matches( matches::match_key key,
00065 unsigned long& branch_pos,
00066 matches& m );
00067
00068 void push_parsers( parser_list& l );
00069 };
00070
00071 class ere_expression_no_dup : public ere_expression<E>
00072 {
00073 public:
00074
00075 void push_parsers( parser_list& l )
00076 {
00077 l.push_back( &m_one_elem );
00078 l.push_back( &m_left_anchor );
00079 l.push_back( &m_right_anchor );
00080 l.push_back( &m_subexpression );
00081 }
00082 };
00083
00084 class ere_expression_and_dupl : public ere_base<E>
00085 {
00086 grammar_to_parser::basic_choice<E,ere_expression_no_dup >
00087 m_ere;
00088 grammar_to_parser::basic_choice<E,ere_dups<E> > m_dup;
00089
00090 matches m_matches;
00091
00092
00093 unsigned long divide_and_recognize( const E* buf,
00094 const unsigned long buf_length,
00095 const unsigned long buf_offset,
00096 unsigned long rep,
00097 bool assign_matches );
00098 public:
00099 ere_expression_and_dupl() : ere_base<E>() {};
00100 ~ere_expression_and_dupl() {};
00101
00102 unsigned long recognize( const E* buf,
00103 const unsigned long buf_length,
00104 const unsigned long buf_offset,
00105 bool try_positions = true );
00106 void assign_matches( matches::match_key key,
00107 unsigned long& branch_pos,
00108 matches& m );
00109 void push_parsers( parser_list& l );
00110 bool is_lazy() { return m_dup.is_parsed() && m_dup->is_lazy(); }
00111
00112 };
00113
00114 grammar_to_parser::basic_choice<E,one_char_or_coll_elem_ere<E> >
00115 m_one_elem;
00116 grammar_to_parser::basic_terminal<E,'^'> m_left_anchor;
00117 grammar_to_parser::basic_terminal<E,'$'> m_right_anchor;
00118 grammar_to_parser::basic_non_terminal<E,subexpression>
00119 m_subexpression;
00120 grammar_to_parser::basic_non_terminal<E,ere_expression_and_dupl>
00121 m_ere_expr_and_dup;
00122 public:
00123
00124 ere_expression() :
00125 ere_base<E>(),
00126 m_subexpression(),
00127 m_ere_expr_and_dup()
00128 {};
00129 ~ere_expression() {};
00130
00131 bool is_right_anchor() { return m_right_anchor.is_parsed(); }
00132 bool is_left_anchor() { return m_left_anchor.is_parsed(); }
00133 bool is_subexpression() { return m_subexpression.is_parsed(); }
00134 bool is_lazy()
00135 {
00136 return m_ere_expr_and_dup.is_parsed() && m_ere_expr_and_dup->is_lazy();
00137 }
00138
00139 unsigned long recognize( const E* buf,
00140 const unsigned long buf_length,
00141 const unsigned long buf_offset,
00142 bool try_positions = true );
00143 void assign_matches( matches::match_key key,
00144 unsigned long& branch_pos,
00145 matches& m );
00146
00147 void push_parsers( parser_list& l );
00148
00149 };
00150
00151 };
00152
00153 #endif