From 2a7952bc286b38acd498e36f77efdd65f312dd55 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Sun, 25 Jun 2000 23:09:08 +0000 Subject: [PATCH] 2000-06-25 03:35 UTC-0800 Ron Pinkas * source/compiler/hbgenerr.c ! Refined line numbers reported. * source/compiler/harbour.l ! Rewrote (again) rules for STRING1 STRING2 STRING3 INDEX. Rules for strings much simpler. /* Flex had some problem with $ that caused output of strings. */ --- harbour/source/compiler/harbour.l | 139 ++++++++++++++++++++--------- harbour/source/compiler/hbgenerr.c | 11 ++- 2 files changed, 103 insertions(+), 47 deletions(-) diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 3957d3a81d..02975086a4 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -157,65 +157,88 @@ Separator {SpaceTab} ^[ \t]*"do"[ \t]*"while"[ \t]*"[" { BEGIN STRING3; return WHILE; } \[ { BEGIN STRING3; } -[^'\n]*$ { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); - iIndexSets = 0; - i_INDEX_STATE = 0; - hb_comp_iState = LOOKUP; - BEGIN 0; - return '\n'; - } -[^\"\n]*$ { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); - iIndexSets = 0; - i_INDEX_STATE = 0; - hb_comp_iState = LOOKUP; - BEGIN 0; - return '\n'; - } -[^\]\n]*$ { hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); - iIndexSets = 0; - i_INDEX_STATE = 0; - hb_comp_iState = LOOKUP; - BEGIN 0; - return '\n'; +[^'\n]*\n { + unput( '\n' ); + + yytext[--yyleng] = '\0'; + + #ifdef DEBUG_STRINGS + printf("\nEOL in STRING1\n"); + #endif + + hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + iIndexSets = 0; + i_INDEX_STATE = 0; + hb_comp_iState = LOOKUP; + BEGIN 0; + return LITERAL; + } + +[^"\n]*\n { + unput( '\n' ); + + yytext[--yyleng] = '\0'; + + #ifdef DEBUG_STRINGS + printf("\nEOL in STRING2\n"); + #endif + + hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + iIndexSets = 0; + i_INDEX_STATE = 0; + hb_comp_iState = LOOKUP; + BEGIN 0; + return LITERAL; + } + +[^]\n]*\n { + unput( '\n' ); + + yytext[--yyleng] = '\0'; + + #ifdef DEBUG_STRINGS + printf("\nEOL in STRING3\n"); + #endif + + hb_compGenError( hb_comp_szErrors, 'E', HB_COMP_ERR_STRING_TERMINATOR, yytext, NULL ); + iIndexSets = 0; + i_INDEX_STATE = 0; + hb_comp_iState = LOOKUP; + BEGIN 0; + return LITERAL; } -[^"'"\n]*' { if( i_INDEX_STATE ) +[^'\n]*' { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yyleng--; - yytext[yyleng] = 0; + yytext[yyleng--] = '\0'; yylval.string = hb_strdup( yytext ); return LITERAL; } -[^\"\n]*\" { if( i_INDEX_STATE ) +[^"\n]*\" { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yyleng--; - yytext[yyleng] = 0; + yytext[yyleng--] = '\0'; yylval.string = hb_strdup( yytext ); return LITERAL; } -[^\]\n]*\] { if( i_INDEX_STATE ) +[^\]\n]*] { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yyleng--; - yytext[yyleng] = 0; + yytext[yyleng--] = '\0'; yylval.string = hb_strdup( yytext ); return LITERAL; } -\[[^\n]*$ { iIndexSets++; - /* - printf( "%i >%s<\n", iIndexSets, yytext ); - */ +\[[^;\n]*[;\n] { { char * tmpStr = yytext; @@ -223,6 +246,12 @@ Separator {SpaceTab} { if( *tmpStr++ == ']' ) { + iIndexSets++; + + #ifdef DEBUG_INDEX + printf( "Open %i At >%s< Ends At: >%s<\n", iIndexSets, yytext, tmpStr ); + #endif + yyless(1); return '['; } @@ -234,30 +263,37 @@ Separator {SpaceTab} iIndexSets = 0; hb_comp_iState = LOOKUP; BEGIN 0; - return '\n'; + return yytext[yyleng -1]; } } -\][^\n]*\n { if( iIndexSets ) +\][^;\n]*[;\n] { if( iIndexSets ) iIndexSets-- ; - /* - printf( ">%s<\n", yytext ); - */ + #ifdef DEBUG_INDEX + printf( "Closed: %i At: >%s<\n", iIndexSets, yytext ); + #endif if( iIndexSets == 0 ) { - char * tmpStr = yytext; + char * tmpStr = yytext + 1; - /* Default to no Opening Bracket. */ + /* Default to no immediate Opening Bracket. */ i_INDEX_STATE = 0; BEGIN 0; - /* No longer in this state. */ - while( *tmpStr != '\0' ) + #ifdef DEBUG_INDEX + printf( "Assumed Normal but Searching...\n" ); + #endif + + /* We have to BEGIN INDEX because lex ate the ']' so it will misss the "]"[ \t]"[" SubArray rule. */ + while( ( *tmpStr == ' ' || *tmpStr == '\t' || *tmpStr == '[' ) && *tmpStr != '\0' ) { if( *tmpStr++ == '[' ) { + #ifdef DEBUG_INDEX + printf( "Retained! Found: >%s<\n", tmpStr ); + #endif i_INDEX_STATE = 1; BEGIN INDEX; @@ -265,6 +301,12 @@ Separator {SpaceTab} } } } + else + { + #ifdef DEBUG_INDEX + printf( "Still Open: %i\n", iIndexSets ); + #endif + } yyless(1); hb_comp_iState = OPERATOR; @@ -275,6 +317,7 @@ Separator {SpaceTab} \n. { /* "." after "\n" is important so we skip empty lines, until begining of non empty next line - don't remove!!! */ hb_comp_iState = LOOKUP; + iIndexSets = 0; yyless( 1 ); @@ -288,7 +331,17 @@ Separator {SpaceTab} %{ /* ************************************************************************ */ %} -; { yy_set_bol(1); hb_comp_iState = LOOKUP; if( ! i_INDEX_STATE ) return ';'; } +; { if( ! i_INDEX_STATE ) + { + #ifdef DEBUG_NEWLINE + printf( "New Line\n" ); + #endif + + yy_set_bol(1); + hb_comp_iState = LOOKUP; + return ';'; + } + } %{ /* ************************************************************************ */ %} diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index bd0d13e12a..fdb201994a 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -124,14 +124,16 @@ char * hb_comp_szWarnings[] = void hb_compGenError( char * szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) { + int iLine = hb_comp_files.pLast->iLine - 1; + if( cPrefix != 'F' && hb_comp_bError ) return; - /* - printf( "Eol: %i >%s<\n", hb_comp_EOL, yytext ); - */ + #ifdef DEBUG_ERRORS + printf( "PP %i Empty: %i >%s<\n", hb_comp_files.pLast->iLine, hb_pp_nEmptyStrings, yytext ); + #endif - printf( "\r%s(%i) ", hb_comp_szFile, hb_comp_iCompiled + ( yytext[0] == '\n' ? 1: 0 ) ); + printf( "\r%s(%i) ", hb_comp_szFile, iLine ); printf( "Error %c%04i ", cPrefix, iError ); printf( szErrors[ iError - 1 ], szError1, szError2 ); @@ -139,6 +141,7 @@ void hb_compGenError( char * szErrors[], char cPrefix, int iError, char * szErro hb_comp_iErrorCount++; hb_comp_bError = TRUE; + hb_comp_iCompiled = hb_comp_files.pLast->iLine - 1; /* fatal error - exit immediately */ if( cPrefix == 'F' )