Mercurial > hg > index.cgi
diff lwbasic/lexer.c @ 31:574931d87abd
Created a function to prettyprint the current lexer token
author | lost@l-w.ca |
---|---|
date | Thu, 03 Feb 2011 21:28:24 -0700 |
parents | 26aa76da75ad |
children | 890a8f688889 |
line wrap: on
line diff
--- a/lwbasic/lexer.c Thu Feb 03 21:19:11 2011 -0700 +++ b/lwbasic/lexer.c Thu Feb 03 21:28:24 2011 -0700 @@ -217,3 +217,25 @@ state -> lexer_token = token_char; return; } + +char *lexer_return_token(cstate *state) +{ + static char *buffer = NULL; + static int buflen = 0; + int l; + + if (buflen == 0) + { + buffer = lw_alloc(128); + buflen = 128; + } + + l = snprintf(buffer, buflen, "%s (%d)", state -> lexer_token_string, state -> lexer_token); + if (l >= buflen) + { + buffer = lw_realloc(buffer, l + 1); + buflen = l + 1; + snprintf(buffer, buflen, "%s (%d)", state -> lexer_token_string, state -> lexer_token); + } + return buffer; +}