2001-01-11 20:10 UTC-0800 Ron Pinkas <ron@profit-master.com>

* source/compiler/harbour.l
   * source/compiler/harbour.slx
     + Added logic to ignore, rest of line after //
                              content of /**/ comments
                              content of strings and char constants
                              escape codes within strings and char constants
   * tests/inline_c.prg
     + Added sample comments and strings containing { and \".
This commit is contained in:
Ron Pinkas
2001-01-12 04:15:26 +00:00
parent c54c5b8c7a
commit 5a7c00ebfb
4 changed files with 179 additions and 45 deletions

View File

@@ -1,3 +1,13 @@
2001-01-11 20:10 UTC-0800 Ron Pinkas <ron@profit-master.com>
* source/compiler/harbour.l
* source/compiler/harbour.slx
+ Added logic to ignore, rest of line after //
content of /**/ comments
content of strings and char constants
escape codes within strings and char constants
* tests/inline_c.prg
+ Added sample comments and strings containing { and \".
2001-01-11 17:00 UTC-0500 David G. Holm <dholm@jsd-llc.com>
* test/inline_c.prg
+ Added missing CVS ID line!

View File

@@ -761,57 +761,117 @@ Separator {SpaceTab}
%}
"hb_inline" {
char sBuffer[ YY_BUF_SIZE ], *pBuffer, sInlineSym[] = "HB_INLINE_0";
int iSize, iBraces = 0;
extern BOOL hb_pp_bInline;
#define INLINE_NORMAL 0
#define INLINE_SINGLE_QUOT 1
#define INLINE_DOUBLE_QUOT 2
#define INLINE_COMMENT 3
char sBuffer[ YY_BUF_SIZE ], *pBuffer, sInlineSym[] = "HB_INLINE_0", cMode = INLINE_NORMAL;
int iSize, iBraces = 0;
extern BOOL hb_pp_bInline;
PINLINE pInline;
hb_pp_bInline = TRUE;
sInlineSym[10] = hb_comp_cInlineID++;
sInlineSym[10] = hb_comp_cInlineID++;
switch( sInlineSym[10] )
{
case '9' + 1 :
sInlineSym[10] = 'A';
break;
switch( sInlineSym[10] )
{
case '9' + 1 :
sInlineSym[10] = 'A';
break;
case 'Z' + 1 :
case 'Z' + 1 :
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_TOOMANY_INLINE, NULL, NULL );
break;
}
break;
}
pInline = hb_compInlineAdd( hb_compIdentifierNew( sInlineSym, TRUE ) );
DigestInline :
DigestInline :
YY_INPUT( (char*) sBuffer, iSize, YY_BUF_SIZE );
if( iSize == 0 )
{
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_INVALID_INLINE, hb_comp_functions.pLast->szName, NULL );
hb_pp_bInline = FALSE;
return '\n';
}
pBuffer = (char*) sBuffer;
while( *pBuffer /* && ( *pBuffer == ' ' || *pBuffer == '\t' ) */ )
if( iSize == 0 )
{
if( *pBuffer == '{' )
hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_INVALID_INLINE, hb_comp_functions.pLast->szName, NULL );
hb_pp_bInline = FALSE;
return '\n';
}
pBuffer = (char*) sBuffer;
while( *pBuffer )
{
switch( cMode )
{
iBraces++;
}
else if( *pBuffer == '}' && iBraces > 1 )
{
iBraces--;
}
else if( *pBuffer == '}' )
{
hb_pp_bInline = FALSE;
case INLINE_NORMAL :
if( *pBuffer == '{' )
{
iBraces++;
}
else if( *pBuffer == '}' && iBraces > 1 )
{
iBraces--;
}
else if( *pBuffer == '}' )
{
hb_pp_bInline = FALSE;
break;
}
else if( *pBuffer == '\'' )
{
cMode = INLINE_SINGLE_QUOT;
}
else if( *pBuffer == '"' )
{
cMode = INLINE_DOUBLE_QUOT;
}
else if( *pBuffer == '/' && *(pBuffer+1) == '/' )
{
goto SaveInline;
}
else if( *pBuffer == '/' && *(pBuffer+1) == '*' )
{
pBuffer++;
cMode = INLINE_COMMENT;
}
break;
case INLINE_SINGLE_QUOT :
if( *pBuffer == '\\' )
{
pBuffer++;
}
else if( *pBuffer == '\'' )
{
cMode = INLINE_NORMAL;
}
break;
case INLINE_DOUBLE_QUOT :
if( *pBuffer == '\\' )
{
pBuffer++;
}
else if( *pBuffer == '"' )
{
cMode = INLINE_NORMAL;
}
break;
case INLINE_COMMENT :
if( *pBuffer == '*' && *(pBuffer+1) == '/' )
{
pBuffer++;
cMode = INLINE_NORMAL;
}
break;
}
pBuffer++;
}
SaveInline :
if( pInline->pCode == NULL )
{
pInline->pCode = hb_xgrab( ( iSize = strlen( (char*) sBuffer ) ) + 1 );

View File

@@ -1002,7 +1002,12 @@ int hb_comp_SLX_CustomAction( int x, int aiHold[], int *ptr_iHold, BOOL *ptr_bIg
case HB_INLINE :
{
char sBuffer[ YY_BUF_SIZE ], *pBuffer, sInlineSym[] = "HB_INLINE_0";
#define INLINE_NORMAL 0
#define INLINE_SINGLE_QUOT 1
#define INLINE_DOUBLE_QUOT 2
#define INLINE_COMMENT 3
char sBuffer[ YY_BUF_SIZE ], *pBuffer, sInlineSym[] = "HB_INLINE_0", cMode = INLINE_NORMAL;
int iSize, iBraces = 0;
extern BOOL hb_pp_bInline;
PINLINE pInline;
@@ -1035,24 +1040,79 @@ int hb_comp_SLX_CustomAction( int x, int aiHold[], int *ptr_iHold, BOOL *ptr_bIg
}
pBuffer = (char*) sBuffer;
while( *pBuffer /* && ( *pBuffer == ' ' || *pBuffer == '\t' ) */ )
while( *pBuffer )
{
if( *pBuffer == '{' )
switch( cMode )
{
iBraces++;
}
else if( *pBuffer == '}' && iBraces > 1 )
{
iBraces--;
}
else if( *pBuffer == '}' )
{
hb_pp_bInline = FALSE;
case INLINE_NORMAL :
if( *pBuffer == '{' )
{
iBraces++;
}
else if( *pBuffer == '}' && iBraces > 1 )
{
iBraces--;
}
else if( *pBuffer == '}' )
{
hb_pp_bInline = FALSE;
break;
}
else if( *pBuffer == '\'' )
{
cMode = INLINE_SINGLE_QUOT;
}
else if( *pBuffer == '"' )
{
cMode = INLINE_DOUBLE_QUOT;
}
else if( *pBuffer == '/' && *(pBuffer+1) == '/' )
{
goto SaveInline;
}
else if( *pBuffer == '/' && *(pBuffer+1) == '*' )
{
pBuffer++;
cMode = INLINE_COMMENT;
}
break;
case INLINE_SINGLE_QUOT :
if( *pBuffer == '\\' )
{
pBuffer++;
}
else if( *pBuffer == '\'' )
{
cMode = INLINE_NORMAL;
}
break;
case INLINE_DOUBLE_QUOT :
if( *pBuffer == '\\' )
{
pBuffer++;
}
else if( *pBuffer == '"' )
{
cMode = INLINE_NORMAL;
}
break;
case INLINE_COMMENT :
if( *pBuffer == '*' && *(pBuffer+1) == '/' )
{
pBuffer++;
cMode = INLINE_NORMAL;
}
break;
}
pBuffer++;
}
SaveInline :
if( pInline->pCode == NULL )
{
pInline->pCode = hb_xgrab( ( iSize = strlen( (char*) sBuffer ) ) + 1 );

View File

@@ -14,6 +14,9 @@ PROCEDURE MAIN( cLine, cDelim )
? '"' + a[ i ] + '"'
NEXT i
QOut( HB_INLINE() )
{ hb_retc( "\na C String, including { and \" \n" ); }
RETURN
FUNCTION aTokens( cLine, cDelimiter )
@@ -27,12 +30,13 @@ FUNCTION aTokens( cLine, cDelimiter )
ENDIF
HB_INLINE( aTokens, cLine, Asc( cDelimiter ) )
{
{ // Note including {
PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY );
PHB_ITEM pLine = hb_param( 2, HB_IT_STRING );
char cDelimiter = (char) hb_parni(3);
size_t i, iOffset = 0, iIndex = 1;
/* Comment including { */
for( i = 0; i < pLine->item.asString.length; i++ )
{
if( pLine->item.asString.value[i] == cDelimiter )