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

one_char_or_coll_elem_ere.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_EXPRESSIONONE_CHAR_OR_COLL_ELEM_ERE_H
00021 #define EXTENDED_REGULAR_EXPRESSIONONE_CHAR_OR_COLL_ELEM_ERE_H
00022 
00023 namespace extended_regular_expression {
00024 
00044 template<typename E>
00045 class one_char_or_coll_elem_ere
00046 {
00047 typedef typename grammar_to_parser::basic_parser<E>::parser_list 
00048                                                                                                                         parser_list;
00049 typedef bracket_expression::bracket_expr<E>                                     bracket_expr_type;
00050 typedef bracket_expression::collating_symbol<E>                         collating_symbol_type;
00051         
00052         class quoted_char
00053         {
00054                 grammar_to_parser::basic_terminal<E,'\\'>                       m_backslash;
00055                 grammar_to_parser::basic_choice<E, special_chars<E> >
00056                                                                                                                         m_spec_chars;
00057         public:
00058                 quoted_char() {};
00059                 ~quoted_char() {};
00060                 
00061                 void push_parsers( parser_list &l )
00062                 {
00063                         l.push_back(&m_backslash);
00064                         l.push_back(&m_spec_chars);
00065                 }
00066                 unsigned long recognize( const E* buf, 
00067                                                                 const unsigned long buf_length )
00068                 {
00069                         return m_spec_chars->recognize(buf,buf_length);
00070                 }
00071         };
00072         grammar_to_parser::basic_except_terminal<E,special_chars<E> >
00073                                                                                                                         m_ord_char;
00074         grammar_to_parser::basic_non_terminal<E,quoted_char>    m_quoted_char;
00075         grammar_to_parser::basic_terminal<E,'.'>                                m_dot;
00076         grammar_to_parser::basic_choice<E, bracket_expr_type >  m_bracket_expr;
00077 public:
00078     one_char_or_coll_elem_ere() {};
00079     ~one_char_or_coll_elem_ere() {};
00080 
00081         void push_parsers( parser_list &l )
00082         {
00083                 l.push_back(&m_ord_char);
00084                 l.push_back(&m_quoted_char);
00085                 l.push_back(&m_dot);
00086                 l.push_back(&m_bracket_expr);
00087         }
00088         
00089         unsigned long recognize( const E* buf, 
00090                                                         const unsigned long buf_length,
00091                                                         const unsigned long buf_offset )
00092         {
00093                 if( m_ord_char.is_parsed() )
00094                 {
00095                         if( m_ord_char.get_valid() == buf[buf_offset] )
00096                         {
00097                                 return collating_symbol_type::get_symbol_len(buf+buf_offset,
00098                                                                                                                 buf_length-buf_offset);
00099                         }
00100                         else
00101                         {
00102                                 return 0;
00103                         }
00104                 } 
00105                 else if( m_quoted_char.is_parsed() )
00106                 {      
00107                         return m_quoted_char->recognize( buf+buf_offset,
00108                                                                                         buf_length-buf_offset );
00109                 }
00110                 else if( m_dot.is_parsed() )
00111                 {
00112                         return collating_symbol_type::get_symbol_len( buf+buf_offset,
00113                                                                                                         buf_length-buf_offset );
00114                 }
00115                 else
00116                 {
00117                         return m_bracket_expr->recognize( buf+buf_offset,
00118                                                                                         buf_length-buf_offset );
00119                 }
00120         }
00121 };
00122 
00123 
00124 };
00125 #endif

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