Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

extended_regular_expression.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Radko Mihal                                     *
00003  *   rmihal@pobox.sk                                                       *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
00019  ***************************************************************************/
00020 #ifndef EXTENDED_REGULAR_EXPRESSIONERE_H
00021 #define EXTENDED_REGULAR_EXPRESSIONERE_H
00022 
00023 #include <map>
00024 #include <list>
00025 
00026 #include "grammar_to_parser.h"
00027 
00028 #include "match.h"
00029 #include "matches.h"
00030 #include "bracket_expression.h"
00031 #include "ere_base.h" 
00032 #include "ere_dupl_symbol.h"
00033 #include "ere_dups.h"
00034 #include "special_chars.h"
00035 #include "one_char_or_coll_elem_ere.h"
00036 #include "ere_expression.h"
00037 #include "ere_branch.h"
00038 #include "extended_reg_exp.h"
00039 
00040 namespace extended_regular_expression
00041 {
00042         
00043 template< typename E >
00044 class ere
00045 {
00046 typedef typename grammar_to_parser::basic_parser<E>::parser_list parser_list;
00047 
00048         grammar_to_parser::basic_choice< E, extended_reg_exp<E> >       m_ext_reg_exp;
00049         unsigned long   m_rec_size;
00050         unsigned long   m_rec_pos;
00051         bool                    m_is_rec;
00052 
00053 public:
00054         ere() : m_rec_size(0), m_rec_pos(0), m_is_rec(false)  {};
00055         ~ere() {};
00056         
00057         unsigned long recognize( const E* buf, 
00058                                                         const unsigned long buf_length,
00059                                                         bool try_positions = true )
00060         {
00061                 m_ext_reg_exp->recognize( buf, buf_length, 0, try_positions );
00062                 m_is_rec = m_ext_reg_exp->is_recognized();
00063                 m_rec_pos = m_ext_reg_exp->recognized_position();
00064                 m_rec_size = m_ext_reg_exp->recognized_size();
00065                 return m_rec_size;
00066         }
00067         void assign_matches( matches& m )
00068         {
00069                 unsigned long branch_pos = 0;
00070                 matches::match_key key = "1";
00071                 if( m_ext_reg_exp.is_parsed() ) m_ext_reg_exp->assign_matches( key, branch_pos, m );
00072         };
00073         
00074         void push_parsers( parser_list& l )
00075         {
00076                 l.push_back( &m_ext_reg_exp );
00077         }
00078         
00079         bool is_recognized()
00080         {
00081                 return m_is_rec;
00082         }
00083         
00084         const unsigned long recognized_size() const
00085         {
00086                 return m_rec_size;
00087         }
00088         
00089         const unsigned long recognized_position() const
00090         {
00091                 return m_rec_pos;
00092         }
00093 };
00094 
00095 };
00096 
00097 #endif

Generated on Sun Jul 2 18:39:43 2006 for grammar2parser.kdevelop by  doxygen 1.4.1