From: <bl...@us...> - 2003-05-03 17:39:22
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv663/include/rfta/parser Modified Files: ParserTools.h Log Message: * added expression skipper and makeComposite(). Index: ParserTools.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ParserTools.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ParserTools.h 2 May 2003 06:22:26 -0000 1.7 --- ParserTools.h 3 May 2003 17:39:18 -0000 1.8 *************** *** 62,74 **** struct SkipNonePolicy { ! static void handleSkip( Xtl::CStringEnumerator &enumerator ) { } ! static void handleSkip( Xtl::CStringBackEnumerator &enumerator ) { } }; template<typename Enumerator> static void --- 62,212 ---- struct SkipNonePolicy { ! static bool handleSkip( Xtl::CStringEnumerator &enumerator ) { + return false; } ! static bool handleSkip( Xtl::CStringBackEnumerator &enumerator ) ! { ! return false; ! } ! }; ! ! ! ! ! template<typename Policy1 ! ,typename Policy2> ! struct Skip2Policy ! { ! Skip2Policy( Policy1 policy1, Policy2 policy2 ) ! : policy1_( policy1 ) ! , policy2_( policy2 ) ! { ! } ! ! bool handleSkip( Xtl::CStringEnumerator &enumerator ) const ! { ! return policy1_.handleSkip( enumerator ) || policy2_.handleSkip( enumerator ); ! } ! ! void handleSkip( Xtl::CStringBackEnumerator &enumerator ) const ! { ! return policy1_.handleSkip( enumerator ) || policy2_.handleSkip( enumerator ); ! } ! ! Policy1 policy1_; ! Policy2 policy2_; ! }; ! ! ! template<typename Policy1 ! ,typename Policy2 ! ,typename Policy3> ! struct Skip3Policy ! { ! Skip3Policy( Policy1 policy1, Policy2 policy2, Policy3 policy3 ) ! : policy1_( policy1 ) ! , policy2_( policy2 ) ! , policy3_( policy3 ) ! { ! } ! ! bool handleSkip( Xtl::CStringEnumerator &enumerator ) const { + return policy1_.handleSkip( enumerator ) + || policy2_.handleSkip( enumerator ); + || policy3_.handleSkip( enumerator ); } + + bool handleSkip( Xtl::CStringBackEnumerator &enumerator ) const + { + return policy1_.handleSkip( enumerator ) + || policy2_.handleSkip( enumerator ); + || policy3_.handleSkip( enumerator ); + } + + Policy1 policy1_; + Policy2 policy2_; + Policy3 policy3_; }; + + template<typename Policy1 + ,typename Policy2 + ,typename Policy3 + ,typename Policy4> + struct Skip4Policy + { + Skip4Policy( Policy1 policy1, Policy2 policy2, Policy3 policy3, Policy4 policy4 ) + : policy1_( policy1 ) + , policy2_( policy2 ) + , policy3_( policy3 ) + , policy4_( policy4 ) + { + } + + bool handleSkip( Xtl::CStringEnumerator &enumerator ) const + { + return policy1_.handleSkip( enumerator ) + || policy2_.handleSkip( enumerator ) + || policy3_.handleSkip( enumerator ) + || policy4_.handleSkip( enumerator ); + } + + bool handleSkip( Xtl::CStringBackEnumerator &enumerator ) const + { + return policy1_.handleSkip( enumerator ) + || policy2_.handleSkip( enumerator ) + || policy3_.handleSkip( enumerator ) + || policy4_.handleSkip( enumerator ); + } + + Policy1 policy1_; + Policy2 policy2_; + Policy3 policy3_; + Policy4 policy4_; + }; + + + template<typename Policy1 + ,typename Policy2> + Skip2Policy<Policy1,Policy2> + makePolicy( Policy1 policy1, Policy2 policy2 ) + { + return Skip2Policy<Policy1,Policy2>( policy1, policy2 ); + } + + + template<typename Policy1 + ,typename Policy2 + ,typename Policy3> + Skip3Policy<Policy1,Policy2,Policy3> + makePolicy( Policy1 policy1, Policy2 policy2, Policy3 policy3 ) + { + return Skip3Policy<Policy1,Policy2,Policy3>( policy1, policy2, policy3 ); + } + + + template<typename Policy1 + ,typename Policy2 + ,typename Policy3 + ,typename Policy4> + Skip4Policy<Policy1,Policy2,Policy3,Policy4> + makePolicy( Policy1 policy1, Policy2 policy2, Policy3 policy3, Policy4 policy4 ) + { + return Skip4Policy<Policy1,Policy2,Policy3,Policy4>( policy1, policy2, policy3, policy4 ); + } + + + template<typename EnumeratorType + ,typename SkipPolicy> + void skip( EnumeratorType &enumerator, SkipPolicy policy ) + { + while ( policy.handleSkip( enumerator ) ) + ; + } + + template<typename Enumerator> static void *************** *** 89,93 **** while ( enumerator.hasNext() ) { ! skipPolicy.handleSkip( enumerator ); if ( *enumerator++ == charToFind ) return; --- 227,231 ---- while ( enumerator.hasNext() ) { ! skip( enumerator, skipPolicy ); if ( *enumerator++ == charToFind ) return; *************** *** 98,101 **** --- 236,258 ---- + template<typename Enumerator + ,typename SkipPolicy> + static bool + trySkipUntil( Enumerator &enumerator, + char charToFind, + const SkipPolicy &skipPolicy = SkipPolicy() ) + { + Enumerator start = enumerator; + while ( enumerator.hasNext() ) + { + skip( enumerator, skipPolicy ); + if ( *enumerator++ == charToFind ) + return true; + } + + enumerator = start; + return false; + } + template<typename Enumerator> static void *************** *** 128,132 **** } else ! skipPolicy.handleSkip( enumerator ); ++enumerator; --- 285,289 ---- } else ! skip( enumerator, skipPolicy ); ++enumerator; *************** *** 149,216 **** struct SkipBalancingBracePolicy { ! static void handleSkip( Xtl::CStringEnumerator &enumerator ) { if ( *enumerator == '(' ) findNextBalanced( ++enumerator, '(', ')' ); } ! static void handleSkip( Xtl::CStringBackEnumerator &enumerator ) { if ( *enumerator == ')' ) findNextBalanced( ++enumerator, ')', '(' ); } }; ! struct SkipScopeOperatorPolicy { ! static void handleSkip( Xtl::CStringEnumerator &enumerator ) { ! if ( enumerator[0] == ':' && enumerator[1] == ':' ) enumerator += 2; } ! static void handleSkip( Xtl::CStringBackEnumerator &enumerator ) { ! if ( enumerator[0] == ':' && enumerator[-1] == ':' ) enumerator += 2; } }; ! template<typename Policy1 ! ,typename Policy2> ! struct Skip2Policy { ! Skip2Policy( Policy1 policy1, Policy2 policy2 ) ! : policy1_( policy1 ) ! , policy2_( policy2 ) { ! } ! void handleSkip( Xtl::CStringEnumerator &enumerator ) const ! { ! policy1_.handleSkip( enumerator ); ! policy2_.handleSkip( enumerator ); } ! void handleSkip( Xtl::CStringBackEnumerator &enumerator ) const { ! policy1_.handleSkip( enumerator ); ! policy2_.handleSkip( enumerator ); ! } ! Policy1 policy1_; ! Policy2 policy2_; }; ! template<typename Policy1 ! ,typename Policy2> ! Skip2Policy<Policy1,Policy2> ! makePolicy( Policy1 policy1, Policy2 policy2 ) ! { ! return Skip2Policy<Policy1,Policy2>( policy1, policy2 ); ! } bool RFTAPARSER_API tryReadIdentifier( Xtl::CStringEnumerator &enumerator, Xtl::CStringView& identifier ); --- 306,415 ---- struct SkipBalancingBracePolicy { ! static bool handleSkip( Xtl::CStringEnumerator &enumerator ) { if ( *enumerator == '(' ) + { findNextBalanced( ++enumerator, '(', ')' ); + return true; + } + return false; } ! static bool handleSkip( Xtl::CStringBackEnumerator &enumerator ) { if ( *enumerator == ')' ) + { findNextBalanced( ++enumerator, ')', '(' ); + return true; + } + return false; } }; ! template<const char symbol1 ! ,const char symbol2 = symbol1> ! struct SkipDoubleSymbolPolicy { ! static bool handleSkip( Xtl::CStringEnumerator &enumerator ) { ! if ( enumerator[0] == symbol1 && enumerator[1] == symbol2 ) ! { enumerator += 2; + return true; + } + return false; } ! static bool handleSkip( Xtl::CStringBackEnumerator &enumerator ) { ! if ( enumerator[0] == symbol2 && enumerator[-1] == symbol1 ) ! { enumerator += 2; + return true; + } + return false; } }; ! typedef SkipDoubleSymbolPolicy<':'> SkipScopeOperatorPolicy; ! typedef SkipDoubleSymbolPolicy<'<'> SkipLeftShiftOperatorPolicy; ! typedef SkipDoubleSymbolPolicy<'>'> SkipRightShiftOperatorPolicy; ! typedef SkipDoubleSymbolPolicy<'-', '>'> SkipArrowOperatorPolicy; ! ! ! struct SkipExpressionPolicy { ! static bool handleSkip( Xtl::CStringEnumerator &enumerator ) { ! if ( *enumerator != '<' ) ! return false; ! if ( enumerator[1] == '<' ) // << ! { ! enumerator += 2; ! return true; ! } ! ! if ( !isIdentifierLetter( enumerator[-1] ) ) // 1 < 2 ! { ! ++enumerator; ! return true; ! } ! ! ++enumerator; ! ! findNextBalanced( enumerator, '<', '>', makePolicy( SkipLeftShiftOperatorPolicy(), ! SkipRightShiftOperatorPolicy(), ! SkipBalancingBracePolicy(), ! SkipArrowOperatorPolicy() ) ); ! return true; } ! static bool handleSkip( Xtl::CStringBackEnumerator &enumerator ) { ! if ( *enumerator != '>' ) ! return false; ! if ( enumerator[-1] == '>' || enumerator[-1] == '->' ) // >> or -> ! { ! enumerator += 2; ! return true; ! } ! ! ++enumerator; ! ! findNextBalanced( enumerator, '>', '<', makePolicy( SkipLeftShiftOperatorPolicy(), ! SkipRightShiftOperatorPolicy(), ! SkipBalancingBracePolicy(), ! SkipArrowOperatorPolicy() ) ); ! return true; ! } }; ! Xtl::CStringView RFTAPARSER_API readNextIdentifier( Xtl::CStringEnumerator &enumerator ); ! bool RFTAPARSER_API tryReadIdentifier( Xtl::CStringEnumerator &enumerator, Xtl::CStringView& identifier ); |