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

special_chars.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_EXPRESSIONSPECIAL_CHARS_H
00021 #define EXTENDED_REGULAR_EXPRESSIONSPECIAL_CHARS_H
00022 
00023 namespace extended_regular_expression {
00024 
00025 template<typename E>
00026 class special_chars
00027 {
00028 typedef typename grammar_to_parser::basic_parser<E>::parser_list parser_list;
00029         
00030         grammar_to_parser::basic_terminal<E,'.'>        m_period;
00031         grammar_to_parser::basic_terminal<E,'['>        m_left_bracket;
00032         grammar_to_parser::basic_terminal<E,'\\'>       m_backslash;
00033         grammar_to_parser::basic_terminal<E,'('>        m_left_parenthesis;
00034         grammar_to_parser::basic_terminal<E,')'>        m_right_parenthesis;
00035         grammar_to_parser::basic_terminal<E,'*'>        m_asterix;
00036         grammar_to_parser::basic_terminal<E,'+'>        m_plus;
00037         grammar_to_parser::basic_terminal<E,'?'>        m_question_mark;
00038         grammar_to_parser::basic_terminal<E,'{'>        m_left_brace;
00039         grammar_to_parser::basic_terminal<E,'}'>        m_right_brace;
00040         grammar_to_parser::basic_terminal<E,'|'>        m_vertical_line;
00041         grammar_to_parser::basic_terminal<E,'^'>        m_circumflex;
00042         grammar_to_parser::basic_terminal<E,'$'>        m_dollar;
00043 
00044 public:
00045         special_chars() {};
00046 
00047     ~special_chars() {};
00048 
00049         void push_parsers( parser_list &l )
00050         {    
00051                 l.push_back(&m_period);
00052                 l.push_back(&m_left_bracket);
00053                 l.push_back(&m_backslash);
00054                 l.push_back(&m_left_parenthesis);
00055                 l.push_back(&m_right_parenthesis);
00056                 l.push_back(&m_asterix);
00057                 l.push_back(&m_plus);
00058                 l.push_back(&m_question_mark);
00059                 l.push_back(&m_left_brace);
00060                 l.push_back(&m_right_brace);
00061                 l.push_back(&m_vertical_line);
00062                 l.push_back(&m_circumflex);
00063                 l.push_back(&m_dollar);
00064         }
00065         
00066         unsigned long recognize( const E* buf, const unsigned long buf_length )
00067         {
00068                 E c=0;
00069                 if( m_period.is_parsed() ) c = m_period.get_valid();
00070                 else if( m_left_bracket.is_parsed() ) c = m_left_bracket.get_valid();
00071                 else if( m_backslash.is_parsed() ) c = m_backslash.get_valid();
00072                 else if( m_left_parenthesis.is_parsed() ) c = m_left_parenthesis.get_valid();
00073                 else if( m_right_parenthesis.is_parsed() ) c = m_right_parenthesis.get_valid();
00074                 else if( m_asterix.is_parsed() ) c = m_asterix.get_valid();
00075                 else if( m_plus.is_parsed() ) c = m_plus.get_valid();
00076                 else if( m_question_mark.is_parsed() ) c = m_question_mark.get_valid();
00077                 else if( m_left_brace.is_parsed() ) c = m_left_brace.get_valid();
00078                 else if( m_right_brace.is_parsed() ) c = m_right_brace.get_valid();
00079                 else if( m_vertical_line.is_parsed() ) c = m_vertical_line.get_valid();
00080                 else if( m_circumflex.is_parsed() ) c = m_circumflex.get_valid();
00081                 else if( m_dollar.is_parsed()) c = m_dollar.get_valid();
00082                 
00083                 if( c == buf[0] ) return 1;
00084                 else return 0;
00085         }
00086 };
00087 
00088 };
00089 
00090 #endif

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