diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 750e492ea3..f2058b46b1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,13 @@ +2001-01-11 20:10 UTC-0800 Ron Pinkas + * 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 * test/inline_c.prg + Added missing CVS ID line! diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index eafc2bbed0..e72da81b54 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -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 ); diff --git a/harbour/source/compiler/harbour.slx b/harbour/source/compiler/harbour.slx index 102fefc8e1..82bc43990d 100644 --- a/harbour/source/compiler/harbour.slx +++ b/harbour/source/compiler/harbour.slx @@ -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 ); diff --git a/harbour/tests/inline_c.prg b/harbour/tests/inline_c.prg index 0525f2a8ac..c63d1f3cbb 100644 --- a/harbour/tests/inline_c.prg +++ b/harbour/tests/inline_c.prg @@ -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 )