00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GRAMMAR_TO_PARSEREXCEPT_TERMINAL_H
00021 #define GRAMMAR_TO_PARSEREXCEPT_TERMINAL_H
00022
00023 #include "object_parser.h"
00024 #include "choice.h"
00025
00026 namespace grammar_to_parser {
00027
00037 template< typename E, typename except_choice >
00038 class basic_except_terminal : public basic_object_parser<E,E>
00039 {
00040 public:
00041 basic_except_terminal() : basic_object_parser<E,E>("ExceptTerminal") {};
00042
00047 unsigned long parse( const E *buf, const unsigned long buf_length )
00048 {
00049 prepare_for_parsing();
00050
00051 basic_choice<E,except_choice> except;
00052 except.parse( buf, buf_length );
00053 if( !except.is_parsed() && buf_length > 0 )
00054 {
00055 std_auto_ptr::operator=( std_auto_ptr(new E(buf[0])) );
00056 m_parsed_size = 1;
00057 m_is_parsed = true;
00058 }
00059 return m_parsed_size;
00060 }
00061
00066 std::basic_istream<E>& parse( std::basic_istream<E>& is )
00067 {
00068 prepare_for_parsing();
00069
00070 basic_choice<E,except_choice> except;
00071 std::streampos str_pos = is.tellg();
00072 E input = 0;
00073
00074 is.read( &input, 1 );
00075 if( is.good() )
00076 {
00077 except.parse( &input, 1 );
00078 if( !except.is_parsed() )
00079 {
00080 std_auto_ptr::operator =( std_auto_ptr(new E(input)) );;
00081 m_parsed_size = 1;
00082 m_is_parsed = true;
00083 }
00084 else
00085 {
00086 is.clear();
00087 is.seekg( str_pos );
00088 }
00089 }
00090 return is;
00091 }
00092
00093
00097 std::basic_ostream<E>& format( std::basic_ostream<E>& os )
00098 {
00099 prepare_for_formatting();
00100
00101 std::streampos strPos = os.tellp();
00102 if( (std::streamoff)strPos < 0 ) strPos = 0;
00103
00104 E out = get_valid();
00105 if( os.good() )
00106 {
00107 os.write( (const E*)&out,sizeof(E) );
00108 m_formatted_size = sizeof(E);
00109 m_is_formatted = true;
00110 }
00111 else
00112 {
00113 os.clear();
00114 os.seekp( strPos );
00115 }
00116 return os;
00117 }
00118
00119 };
00120
00124 template< class except_choice >
00125 class except_terminal : public basic_except_terminal<char,except_choice>
00126 {
00127 };
00128
00132 template< class except_choice >
00133 class wexcept_terminal : public basic_except_terminal<wchar_t,except_choice>
00134 {
00135 };
00136
00137 };
00138
00139 #endif