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; rc_t rc = kOkRC;
unsigned tid = kInvalidId; unsigned tid = kInvalidId;
@ -866,14 +866,16 @@ namespace cw
"/* block \n" "/* block \n"
"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;
} }
} }
} }

View File

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