2000-06-25 03:35 UTC-0800 Ron Pinkas <Ron@Profit-Master.com>

* 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. */
This commit is contained in:
Ron Pinkas
2000-06-25 23:09:08 +00:00
parent c2f5cbc281
commit 2a7952bc28
2 changed files with 103 additions and 47 deletions

View File

@@ -157,65 +157,88 @@ Separator {SpaceTab}
^[ \t]*"do"[ \t]*"while"[ \t]*"[" { BEGIN STRING3; return WHILE; }
<INITIAL>\[ { BEGIN STRING3; }
<STRING1>[^'\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';
}
<STRING2>[^\"\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';
}
<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';
<STRING1>[^'\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;
}
<STRING2>[^"\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;
}
<STRING3>[^]\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;
}
<STRING1>[^"'"\n]*' { if( i_INDEX_STATE )
<STRING1>[^'\n]*' { if( i_INDEX_STATE )
BEGIN INDEX;
else
BEGIN 0;
yyleng--;
yytext[yyleng] = 0;
yytext[yyleng--] = '\0';
yylval.string = hb_strdup( yytext );
return LITERAL;
}
<STRING2>[^\"\n]*\" { if( i_INDEX_STATE )
<STRING2>[^"\n]*\" { if( i_INDEX_STATE )
BEGIN INDEX;
else
BEGIN 0;
yyleng--;
yytext[yyleng] = 0;
yytext[yyleng--] = '\0';
yylval.string = hb_strdup( yytext );
return LITERAL;
}
<STRING3>[^\]\n]*\] { if( i_INDEX_STATE )
<STRING3>[^\]\n]*] { if( i_INDEX_STATE )
BEGIN INDEX;
else
BEGIN 0;
yyleng--;
yytext[yyleng] = 0;
yytext[yyleng--] = '\0';
yylval.string = hb_strdup( yytext );
return LITERAL;
}
<INDEX>\[[^\n]*$ { iIndexSets++;
/*
printf( "%i >%s<\n", iIndexSets, yytext );
*/
<INDEX>\[[^;\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];
}
}
<INDEX>\][^\n]*\n { if( iIndexSets )
<INDEX>\][^;\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 ';';
}
}
%{
/* ************************************************************************ */
%}

View File

@@ -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' )