diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2013-02-10 21:53:22 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2013-02-10 21:53:22 +0000 |
| commit | 1538ef47d1d4cc08e5f9c5894350bfa225866d40 (patch) | |
| tree | caacdbe75db8a134a14074229892af2dbebf1ad1 /c++-libbu++/src/object.h | |
| parent | 058caf24d2b48ab6b49ae8efe5e1eb1ed246eff1 (diff) | |
| download | libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.tar.gz libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.tar.bz2 libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.tar.xz libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.zip | |
Made the gats text parser much more robust.
Diffstat (limited to '')
| -rw-r--r-- | c++-libbu++/src/object.h | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/c++-libbu++/src/object.h b/c++-libbu++/src/object.h index e4da8de..a876061 100644 --- a/c++-libbu++/src/object.h +++ b/c++-libbu++/src/object.h | |||
| @@ -48,9 +48,69 @@ namespace Gats | |||
| 48 | static Object *strToGats( const Bu::String &sStr ); | 48 | static Object *strToGats( const Bu::String &sStr ); |
| 49 | 49 | ||
| 50 | private: | 50 | private: |
| 51 | static Object *strToGats( Bu::String::const_iterator &i ); | 51 | class StrPos |
| 52 | static Bu::String token( Bu::String::const_iterator &i ); | 52 | { |
| 53 | static void skipWs( Bu::String::const_iterator &i ); | 53 | public: |
| 54 | StrPos( const Bu::String::const_iterator &i ) : | ||
| 55 | i( i ), iLine( 1 ), iChar( 1 ) | ||
| 56 | { } | ||
| 57 | Bu::String::const_iterator i; | ||
| 58 | int iLine; | ||
| 59 | int iChar; | ||
| 60 | |||
| 61 | char operator*() | ||
| 62 | { | ||
| 63 | return *i; | ||
| 64 | } | ||
| 65 | StrPos &operator++(int) | ||
| 66 | { | ||
| 67 | i++; | ||
| 68 | if( i ) | ||
| 69 | { | ||
| 70 | if( *i == '\n' ) | ||
| 71 | { | ||
| 72 | iLine++; | ||
| 73 | iChar = 0; | ||
| 74 | } | ||
| 75 | else | ||
| 76 | iChar++; | ||
| 77 | } | ||
| 78 | return *this; | ||
| 79 | } | ||
| 80 | operator bool() | ||
| 81 | { | ||
| 82 | return i; | ||
| 83 | } | ||
| 84 | }; | ||
| 85 | |||
| 86 | class Thrower : public Bu::String::FormatProxyEndAction | ||
| 87 | { | ||
| 88 | public: | ||
| 89 | Thrower( Gats::Object::StrPos &i ) : | ||
| 90 | i( i ) | ||
| 91 | { | ||
| 92 | } | ||
| 93 | |||
| 94 | virtual ~Thrower() | ||
| 95 | { | ||
| 96 | } | ||
| 97 | |||
| 98 | virtual void operator()( const Bu::String &sFinal ) | ||
| 99 | { | ||
| 100 | throw Bu::ExceptionBase( | ||
| 101 | (Bu::String("%1: %2: ").arg(i.iLine).arg(i.iChar).end() + sFinal) | ||
| 102 | .getStr() | ||
| 103 | ); | ||
| 104 | } | ||
| 105 | |||
| 106 | private: | ||
| 107 | Gats::Object::StrPos &i; | ||
| 108 | }; | ||
| 109 | |||
| 110 | static Bu::String::FormatProxy posError( Gats::Object::StrPos &i, const Bu::String &msg ); | ||
| 111 | static Object *strToGats( Gats::Object::StrPos &i ); | ||
| 112 | static Bu::String token( Gats::Object::StrPos &i ); | ||
| 113 | static void skipWs( Gats::Object::StrPos &i ); | ||
| 54 | }; | 114 | }; |
| 55 | 115 | ||
| 56 | const char *typeToStr( Type t ); | 116 | const char *typeToStr( Type t ); |
