|
From: <bl...@us...> - 2003-04-26 21:11:33
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv9532/include/rfta/parser
Modified Files:
Parser.h ParserTools.h
Log Message:
* added functionalities to use CStringView & CStringEnumerator
Index: Parser.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/Parser.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Parser.h 26 Apr 2003 10:51:58 -0000 1.6
--- Parser.h 26 Apr 2003 21:11:29 -0000 1.7
***************
*** 8,11 ****
--- 8,12 ----
#include <rfta/parser/ASTNode.h>
+ #include <xtl/Forwards.h>
#include <boost/utility.hpp>
#include <boost/format.hpp>
***************
*** 13,17 ****
namespace Refactoring
{
!
class ParseContext;
--- 14,22 ----
namespace Refactoring
{
!
! namespace ParserTools {
! class ParseError;
! }
!
class ParseContext;
***************
*** 46,49 ****
--- 51,58 ----
const ASTNodeWeakPtr &parentNode,
const SourceRange &sourceRange ) const;
+
+ ASTNodePtr createASTNode( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
+ const Xtl::CStringView &string ) const;
protected:
***************
*** 103,107 ****
void throwFailure( const boost::format &format );
! int getIndexOf( const char *pos );
SourceRange getTrimedRange( const SourceRange &sourceRange );
--- 112,118 ----
void throwFailure( const boost::format &format );
! void throwFailure( const ParserTools::ParseError &error );
!
! int getIndexOf( const char *pos ) const;
SourceRange getTrimedRange( const SourceRange &sourceRange );
Index: ParserTools.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ParserTools.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ParserTools.h 22 Dec 2002 16:03:50 -0000 1.3
--- ParserTools.h 26 Apr 2003 21:11:30 -0000 1.4
***************
*** 3,6 ****
--- 3,9 ----
#include <rfta/parser/Config.h>
+ #include <xtl/CStringView.h>
+ #include <stdexcept>
+ #include <string>
***************
*** 13,16 ****
--- 16,31 ----
{
+ class ParseError : public std::runtime_error
+ {
+ public:
+ ParseError( const std::string &message,
+ const Xtl::CStringEnumerator &context )
+ : std::runtime_error( message )
+ {
+ }
+
+ Xtl::CStringEnumerator context_;
+ };
+
inline bool
***************
*** 38,41 ****
--- 53,165 ----
const char *end,
int inIdentifierIndex );
+
+ // A Skip Policy must have a single method compatible with the following signature:
+ // Notes that type Enumerator may be either CStringEnumerator and CStringBackEnumerator.
+ // A templated member function is usually used to deal with both case.
+ // void handleSkip( Enumerator &enumerator );
+
+ struct SkipNonePolicy
+ {
+ static void handleSkip( Xtl::CStringEnumerator &enumerator )
+ {
+ }
+
+ static void handleSkip( Xtl::CStringBackEnumerator &enumerator )
+ {
+ }
+ };
+
+ template<typename Enumerator>
+ static void
+ skipSpaces( Enumerator &enumerator )
+ {
+ while ( enumerator.hasNext() && *enumerator == ' ' )
+ ++enumerator;
+ }
+
+
+ template<typename Enumerator
+ ,typename SkipPolicy>
+ static void
+ skipUntil( Enumerator &enumerator,
+ char charToFind,
+ const SkipPolicy &skipPolicy = SkipPolicy() )
+ {
+ while ( enumerator.hasNext() )
+ {
+ skipPolicy.handleSkip( enumerator );
+ if ( *enumerator++ == charToFind )
+ return;
+ }
+
+ throw ParseError( "missing character", enumerator );
+ }
+
+
+ template<typename Enumerator>
+ static void
+ skipUntil( Enumerator &enumerator,
+ char charToFind )
+ {
+ skipUntil( enumerator, charToFind, SkipNonePolicy() );
+ }
+
+
+ template<typename Enumerator
+ ,typename SkipPolicy>
+ static void
+ findNextBalanced( Enumerator &enumerator,
+ char opening,
+ char closing,
+ const SkipPolicy &skipPolicy = SkipPolicy() )
+ {
+ Enumerator start = enumerator;
+ int balance = 1;
+ while ( enumerator.hasNext() )
+ {
+ if ( *enumerator == opening )
+ ++balance;
+ else if ( *enumerator == closing )
+ {
+ --balance;
+ if ( balance == 0 )
+ return;
+ }
+ else
+ skipPolicy.handleSkip( enumerator );
+
+ ++enumerator;
+ }
+
+ throw ParseError( "unbalanced symbol", --start );
+ }
+
+
+ template<typename Enumerator>
+ static void
+ findNextBalanced( Enumerator &enumerator,
+ char opening,
+ char closing )
+ {
+ findNextBalanced( enumerator, opening, closing, SkipNonePolicy() );
+ }
+
+
+ struct SkipBalancingBracePolicy
+ {
+
+ static void handleSkip( Xtl::CStringEnumerator &enumerator )
+ {
+ if ( *enumerator == '(' )
+ findNextBalanced( ++enumerator, '(', ')' );
+ }
+
+ static void handleSkip( Xtl::CStringBackEnumerator &enumerator )
+ {
+ if ( *enumerator == ')' )
+ findNextBalanced( ++enumerator, ')', '(' );
+ }
+
+ };
|