aboutsummaryrefslogtreecommitdiff
path: root/src/tafreader.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-27 18:11:13 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-27 18:11:13 +0000
commitc86c0cf088492e02431dffb1f860ff2f6faa492d (patch)
tree1191879314028bb8f58daf45d48dacc6ba9ea583 /src/tafreader.cpp
parent5ec9a131e12d021c42b46b601f5e79502485bebb (diff)
downloadlibbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.tar.gz
libbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.tar.bz2
libbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.tar.xz
libbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.zip
The taf system is new and improved. The writer works, we added C++ style
comment blocks, and it retains the order of all nodes.
Diffstat (limited to 'src/tafreader.cpp')
-rw-r--r--src/tafreader.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/tafreader.cpp b/src/tafreader.cpp
index 1187176..db465e9 100644
--- a/src/tafreader.cpp
+++ b/src/tafreader.cpp
@@ -8,6 +8,7 @@ Bu::TafReader::TafReader( Bu::Stream &sIn ) :
8 c( 0 ), 8 c( 0 ),
9 sIn( sIn ) 9 sIn( sIn )
10{ 10{
11 next(); next();
11} 12}
12 13
13Bu::TafReader::~TafReader() 14Bu::TafReader::~TafReader()
@@ -15,60 +16,74 @@ Bu::TafReader::~TafReader()
15 16
16} 17}
17 18
18Bu::TafNode *Bu::TafReader::getNode() 19Bu::TafGroup *Bu::TafReader::readGroup()
19{ 20{
20 if( c == 0 ) next();
21 TafNode *pNode = new TafNode();
22 ws(); 21 ws();
23 if( c != '{' ) 22 if( c != '{' )
24 throw TafException("Expected '{'"); 23 throw TafException("Expected '{'");
25 next(); 24 next();
26 ws(); 25 ws();
27 FString sName = readStr(); 26 FString sName = readStr();
28 pNode->setName( sName ); 27 TafGroup *pGroup = new TafGroup( sName );
29 next(); 28 next();
30 //printf("Node[%s]:\n", sName.getStr() ); 29 //printf("Node[%s]:\n", sName.getStr() );
31 30
32 nodeContent( pNode ); 31 groupContent( pGroup );
33 32
34 if( c != '}' ) 33 if( c != '}' )
35 throw TafException("Expected '}'"); 34 throw TafException("Expected '}'");
36 35
37 next(); 36 next();
38 37
39 return pNode; 38 return pGroup;
40} 39}
41 40
42void Bu::TafReader::nodeContent( Bu::TafNode *pNode ) 41void Bu::TafReader::groupContent( Bu::TafGroup *pGroup )
43{ 42{
44 for(;;) 43 for(;;)
45 { 44 {
46 ws(); 45 ws();
47 if( c == '{' ) 46 if( c == '{' )
48 pNode->addChild( getNode() ); 47 pGroup->addChild( readGroup() );
49 else if( c == '}' ) 48 else if( c == '}' )
50 return; 49 return;
50 else if( c == '/' && la == '*' )
51 pGroup->addChild( readComment() );
51 else 52 else
52 nodeProperty( pNode ); 53 pGroup->addChild( readProperty() );
53 } 54 }
54} 55}
55 56
56void Bu::TafReader::nodeProperty( Bu::TafNode *pNode ) 57Bu::TafProperty *Bu::TafReader::readProperty()
57{ 58{
58 FString sName = readStr(); 59 FString sName = readStr();
59 ws(); 60 ws();
60 if( c != '=' ) 61 if( c != '=' )
61 { 62 {
62 //printf(" %s (true)\n", sName.getStr() ); 63 //printf(" %s (true)\n", sName.getStr() );
63 pNode->setProperty( sName, "" ); 64 return new Bu::TafProperty( sName, "" );
64 return;
65 } 65 }
66 next(); 66 next();
67 FString sValue = readStr(); 67 FString sValue = readStr();
68 pNode->setProperty( sName, sValue ); 68 return new Bu::TafProperty( sName, sValue );
69 //printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); 69 //printf(" %s = %s\n", sName.getStr(), sValue.getStr() );
70} 70}
71 71
72Bu::TafComment *Bu::TafReader::readComment()
73{
74 next();
75 FString sCmnt;
76 for(;;)
77 {
78 next();
79 if( c == '*' && la == '/' )
80 break;
81 sCmnt += c;
82 }
83
84 return new TafComment( sCmnt );
85}
86
72Bu::FString Bu::TafReader::readStr() 87Bu::FString Bu::TafReader::readStr()
73{ 88{
74 ws(); 89 ws();
@@ -134,6 +149,7 @@ bool Bu::TafReader::isws()
134 149
135void Bu::TafReader::next() 150void Bu::TafReader::next()
136{ 151{
137 sIn.read( &c, 1 ); 152 c = la;
153 sIn.read( &la, 1 );
138} 154}
139 155