本文整理汇总了C++中Lexer::ReadString方法的典型用法代码示例。如果您正苦于以下问题:C++ Lexer::ReadString方法的具体用法?C++ Lexer::ReadString怎么用?C++ Lexer::ReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer::ReadString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Parse
/*
================
DeclParser::Parse
================
*/
void DeclParser::Parse( Lexer &lexer ) {
Dict *resultDict = OG_NULL;
bool getKeyValue = false;
int index;
const Token *token;
String key, value;
const char *p;
while ( (token = lexer.ReadToken()) != OG_NULL ) {
p = token->GetString();
if ( p ) {
if ( *p == '\0' )
lexer.Error("Unexpected Empty Token");
if ( !getKeyValue ) {
index = declTypes.Find(p);
if ( index != -1 ) {
value = lexer.ReadString();
if ( value.IsEmpty() )
lexer.Error("Empty name!");
DictEx<Dict> &result = declTypes[index]->declList;
index = result.Find(p);
if ( index == -1 )
resultDict = &result[p];
else {
resultDict = &result[index];
resultDict->Clear();
}
} else {
resultDict = OG_NULL;
lexer.Warning( Format("Unknown decl Type '$*'") << p );
}
lexer.ExpectToken("{");
getKeyValue = true;
} else {
if ( *p == '}' )
getKeyValue = false;
else if ( resultDict ) {
key = p;
(*resultDict).Set( key.c_str(), lexer.ReadString() );
}
}
}
}
if ( getKeyValue )
throw LexerError( LexerError::END_OF_FILE );
}
示例2: ReadGeoMObject
/*
================
ReadGeoMObject
================
*/
static void ReadGeoMObject( Lexer &lexer, ListEx<aseMesh> &myMeshList ) {
lexer.ExpectToken("{");
const char *p;
const Token *token;
String name;
while ( (token = lexer.ReadToken()) != OG_NULL ) {
p = token->GetString();
if ( !p || !*p )
continue;
if ( String::Icmp( p, "}" ) == 0 )
return;
if ( String::Icmp( p, "*" ) != 0 )
lexer.Error( Format("expected *, got '$*'") << p );
if ( lexer.CheckToken( "NODE_NAME" ) )
name = lexer.ReadString();
else if ( lexer.CheckToken( "MESH" ) ) {
aseMesh *inMesh = &myMeshList.Alloc();
inMesh->name = name;
ReadMesh( lexer, inMesh );
}
else if ( !SkipUnknown(lexer) )
break;
}
}
示例3: MakeBinary
/*
================
DeclParser::MakeBinary
================
*/
bool DeclParser::MakeBinary( const char *filename ) {
if ( commonFS == OG_NULL )
return false;
Lexer lexer;
if ( !lexer.LoadFile( filename ) )
return false;
File *f = commonFS->OpenWrite( Format( "$*.bin" ) << filename );
if ( !f )
return false;
try {
f->Write( DECL_DESCRIPTOR_STR, DECL_DESCRIPTOR_LENGTH );
Dict dict;
bool getKeyValue = false;
const Token *token;
String key, value;
String str;
const char *p;
while ( (token = lexer.ReadToken()) != OG_NULL ) {
//! @todo maybe token should be stored as String, so we don't have to recalc len/bytelen
p = token->GetString();
if ( p ) {
if ( *p == '\0' ) {
lexer.Error("Unexpected Empty Token");
return false;
}
if ( !getKeyValue ) {
str = p;
str.WriteToFile( f );
value = lexer.ReadString();
if ( value.IsEmpty() ) {
lexer.Error("Empty name!");
return false;
}
value.WriteToFile( f );
lexer.ExpectToken("{");
getKeyValue = true;
} else {
if ( *p == '}' ) {
getKeyValue = false;
dict.WriteToFile( f );
dict.Clear();
}
else {
key = p;
dict.Set( key.c_str(), lexer.ReadString() );
}
}
}
}
if ( getKeyValue ) {
lexer.Error("Unexpected End Of File");
return false;
}
return true;
}
catch( FileReadWriteError &err ) {
f->Close();
User::Error( ERR_FILE_WRITEFAIL, Format("Binary Decl: $*.bin" ) << err.ToString(), filename );
return false;
}
catch( LexerError &err ) {
f->Close();
String errStr;
err.ToString( errStr );
User::Error( ERR_LEXER_FAILURE, errStr.c_str(), filename );
return false;
}
}
示例4: Parse
/*
================
XDeclParser::Parse
================
*/
void XDeclParser::Parse( Lexer &lexer ) {
const Token *token;
String name, value;
XDeclNode *currentNode = &rootNode;
XDeclNode *newNode;
bool getKeyValue = false;
bool addNode;
Stack<XDeclNode *> nodeStack;
const char *p;
while ( (token = lexer.ReadToken()) != NULL ) {
p = token->GetString();
if ( p ) {
if ( *p == '\0' )
lexer.Error("Unexpected Empty Token");
if ( !getKeyValue ) {
if ( String::Cmp( p, "}" ) == 0 ) {
currentNode = nodeStack.Top();
nodeStack.Pop();
} else {
name = p;
addNode = false;
if ( lexer.CheckToken("=") ) {
currentNode->dict.Set( name.c_str(), lexer.ReadString() );
lexer.ExpectToken(";");
} else if ( lexer.CheckToken("(") ) {
addNode = true;
getKeyValue = true;
} else if ( lexer.CheckToken("{") ) {
addNode = true;
} else {
lexer.Error("Syntax Error, was expecting '(', '=' or '{'");
}
if ( addNode ) {
newNode = allocator.Alloc();
newNode->name = name;
currentNode->numChildren++;
if ( currentNode->firstChild == NULL )
currentNode->firstChild = newNode;
else
currentNode->lastChild->next = newNode;
currentNode->lastChild= newNode;
nodeStack.Push( currentNode );
currentNode = newNode;
}
}
} else {
name = p;
lexer.ExpectToken("=");
currentNode->dict.Set( name.c_str(), lexer.ReadString() );
if ( !lexer.CheckToken(",") ) {
lexer.ExpectToken(")");
if ( lexer.CheckToken(";") ) {
currentNode = nodeStack.Top();
nodeStack.Pop();
getKeyValue = false;
} else if ( lexer.CheckToken("{") ) {
getKeyValue = false;
} else {
lexer.Error("Syntax Error, was expecting ';' or '{'");
}
}
}
}
}
if ( getKeyValue || nodeStack.Num() )
throw LexerError( LexerError::END_OF_FILE );
}