cwLex.h/cpp : test() now returns an rc_t. Added test for use of floating point suffix 'f'.

This commit is contained in:
kevin 2024-04-26 16:58:01 -04:00
parent 78ca1b3e35
commit e42dd71b09
2 changed files with 12 additions and 10 deletions

View File

@ -853,7 +853,7 @@ namespace cw
//)
//(
void test()
rc_t test()
{
rc_t rc = kOkRC;
unsigned tid = kInvalidId;
@ -866,14 +866,16 @@ namespace cw
"/* block \n"
"comment */"
"\"quoted string\""
"ident1"
"ident1 "
"1234.56f"
"345u"
" // last line comment";
// initialize a lexer with a buffer of text
if((rc = lex::create(h,buf,strlen(buf), kReturnSpaceLexFl | kReturnCommentsLexFl)) != kOkRC )
{
cwLogError(rc,"Lexer initialization failed.");
return;
rc = cwLogError(rc,"Lexer initialization failed.");
goto errLabel;
}
// register some additional recoginizers
@ -884,7 +886,7 @@ namespace cw
while( (tid = lex::getNextToken(h)) != kEofLexTId )
{
// 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::currentColumnNumber(h),
lex::idToLabel(h,tid),
@ -899,11 +901,9 @@ namespace cw
int iv = lex::tokenInt(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
if( tid == kErrorLexTId )
{
@ -912,10 +912,12 @@ namespace cw
}
}
// finalize the lexer
lex::destroy(h);
errLabel:
return rc;
}
}
}

View File

@ -129,7 +129,7 @@ namespace cw
const char* idToLabel( handle_t h, unsigned typeId );
// Lexer testing stub.
void test( );
rc_t test( );
}
}