mb_set_parser_func |
status_t mb_set_parser_func( mb_interpreter_t* s, mb_parser_func_t pHandler )
Sets a parser handler to perform special parse functions. Format of parser function:
typedef int (*mb_parser_func_t)( struct mb_interpreter_t*, mb_parse_e cmdType, int row, int col, char* cmdLine );
///////////////////////////////////////////////////////////////////////////// // Parser Types for mb_parser_func_t // typedef enum mb_parse_e { MB_PARSE_FINISH = -1, MB_PARSE_INIT = 0, MB_PARSE_COMMENT = 1, MB_PARSE_LIST = 2, } mb_parse_e;
This is used internally in MyBASIC2 to store comments when comments have been enabled in the debugger.
Example
// Need to enable Parsing Debugger ? if ( wEnable & MB_DBG_ENABLE_PARSING ) { // This will store all comments so they can be loaded into debugger(s) mb_set_parser_func( s, _parse_function );
debugger = s->debugger_context; debugger->enabled |= wEnable; } endif
///////////////////////////////////////////////////////////////////////////// // This is the Parse Function in the MyBASIC2 Debugger Interface // This will load comments into an array so they can be displayed // int _parse_function( struct mb_interpreter_t* s, mb_parse_e cmdType, int row, int col, char* cmdLine ) { char strLine[2048]; char strRow[32]; char strCol[32]; int i; char* lpszComment; char cSep; int nMax; int len; _ls_node_t* pNode;
_debugger_context_t* debugger = s->debugger_context; _parsing_context_t* context = (_parsing_context_t*)s->parsing_context;
if ( !debugger ) return MB_FUNC_ERR; if ( !context ) return MB_FUNC_ERR;
if ( cmdType == MB_PARSE_INIT ) { // Destroy Old Comments first
_parse_function( s, MB_PARSE_FINISH, 0, 0, NULL );
// Create a new comment heap
context->comments = _ls_create(); } else if ( cmdType == MB_PARSE_FINISH ) { // Destroy Comment Heap
if ( context->comments ) { _ls_foreach( context->comments, _destroy_data ); _ls_destroy( context->comments ); context->comments = NULL; } endif } else if ( cmdType == MB_PARSE_COMMENT ) { // Add Comment to Heap
lpszComment = mb_malloc( strlen( cmdLine ) + 1 );
if ( lpszComment ) { safe_strcpy( lpszComment, cmdLine ); _ls_pushback_xg( context->comments, lpszComment, (void*)MAKELONG( row, col ) ); } endif } else if ( cmdType == MB_PARSE_LIST ) { // Output Comment Heap to buffer supplied as cmdLine using current debug format
if ( cmdLine ) { STRCLEAR( cmdLine ); } endif
if ( context->comments ) { len = 0;
cSep = HIBYTE( debugger->opt_format ); nMax = LOBYTE( debugger->opt_format );
for ( i = 0; i < (int)_ls_count_g( context->comments ); i++ ) { pNode = _ls_at_g( context->comments, i );
if ( pNode ) { lpszComment = pNode->data; row = LOWORD( pNode->extra ); col = HIWORD( pNode->extra );
len += sprintf( strLine, "%s%c%s%c%s\n", _int_to_string( row, strRow, ( nMax == 255 ? 255 : 5 ) ), cSep, _int_to_string( col, strCol, ( nMax == 255 ? 255 : 5 ) ), cSep, lpszComment ); } endif
if ( cmdLine ) { strcat( debugger->buffer, strLine ); } endif } endfor } endif
return len; } else { return MB_PARSING_ERR; } endif
return MB_FUNC_OK; } endfunc
|