cwLex.h/cpp : test() now returns an rc_t. Added test for use of floating point suffix 'f'.
This commit is contained in:
parent
78ca1b3e35
commit
e42dd71b09
16
cwLex.cpp
16
cwLex.cpp
@ -853,7 +853,7 @@ namespace cw
|
|||||||
//)
|
//)
|
||||||
|
|
||||||
//(
|
//(
|
||||||
void test()
|
rc_t test()
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
unsigned tid = kInvalidId;
|
unsigned tid = kInvalidId;
|
||||||
@ -867,13 +867,15 @@ namespace cw
|
|||||||
"comment */"
|
"comment */"
|
||||||
"\"quoted string\""
|
"\"quoted string\""
|
||||||
"ident1 "
|
"ident1 "
|
||||||
|
"1234.56f"
|
||||||
|
"345u"
|
||||||
" // last line comment";
|
" // last line comment";
|
||||||
|
|
||||||
// initialize a lexer with a buffer of text
|
// initialize a lexer with a buffer of text
|
||||||
if((rc = lex::create(h,buf,strlen(buf), kReturnSpaceLexFl | kReturnCommentsLexFl)) != kOkRC )
|
if((rc = lex::create(h,buf,strlen(buf), kReturnSpaceLexFl | kReturnCommentsLexFl)) != kOkRC )
|
||||||
{
|
{
|
||||||
cwLogError(rc,"Lexer initialization failed.");
|
rc = cwLogError(rc,"Lexer initialization failed.");
|
||||||
return;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// register some additional recoginizers
|
// register some additional recoginizers
|
||||||
@ -884,7 +886,7 @@ namespace cw
|
|||||||
while( (tid = lex::getNextToken(h)) != kEofLexTId )
|
while( (tid = lex::getNextToken(h)) != kEofLexTId )
|
||||||
{
|
{
|
||||||
// print information about each token
|
// print information about each token
|
||||||
cwLogInfo("%i %i %s '%.*s' (%i) ",
|
cwLogInfo("ln:%i col:%i tok:%s '%.*s' len:%i ",
|
||||||
lex::currentLineNumber(h),
|
lex::currentLineNumber(h),
|
||||||
lex::currentColumnNumber(h),
|
lex::currentColumnNumber(h),
|
||||||
lex::idToLabel(h,tid),
|
lex::idToLabel(h,tid),
|
||||||
@ -899,11 +901,9 @@ namespace cw
|
|||||||
int iv = lex::tokenInt(h);
|
int iv = lex::tokenInt(h);
|
||||||
double dv = lex::tokenDouble(h);
|
double dv = lex::tokenDouble(h);
|
||||||
|
|
||||||
cwLogInfo("%i %f",iv,dv);
|
cwLogInfo("Number: int:%i dbl:%f unsigned:%i float:%i",iv,dv,tokenIsUnsigned(h),tokenIsSinglePrecision(h));
|
||||||
}
|
}
|
||||||
|
|
||||||
cwLogInfo("\n");
|
|
||||||
|
|
||||||
// handle errors
|
// handle errors
|
||||||
if( tid == kErrorLexTId )
|
if( tid == kErrorLexTId )
|
||||||
{
|
{
|
||||||
@ -916,6 +916,8 @@ namespace cw
|
|||||||
// finalize the lexer
|
// finalize the lexer
|
||||||
lex::destroy(h);
|
lex::destroy(h);
|
||||||
|
|
||||||
|
errLabel:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user