Project

General

Profile

Bug #9918

tilde doesn't duplicate semicolon in alternative codings

Added by Stefan Vieru about 1 year ago. Updated 3 months ago.

Status:
Internal Test
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:
4GL Preprocessor

Related issues

Related to Conversion Tools - Bug #6308: post string literal alternative coding quirk in 4GL preprocessor Internal Test
Related to Testing - Support #6859: preprocessor tests Test

History

#1 Updated by Stefan Vieru about 1 year ago

  • Subject changed from tilde duplicates semicolon in alternative codings to tilde doesn't duplicate semicolon in alternative codings

While developing some more tests i have found that:

txt3 = 'txt1'~;*.
txt4 = "txt2"~;*.

In OE we get:

txt3 = 'txt1'~;;*.
txt4 = "txt2"~;;*.

But in FWD:

txt3 = 'txt1'~;*.
txt4 = "txt2"~;*.

It seems that ~ doesn't just stop alternative representation from converting, but also duplicating the ;.
This is not the case for
  • ;?n converts to ~nn (;? = ~)
  • ~;* stays ~;*
  • ~;& stays ~;&
  • ~;< stays ~;<
  • ~;> stays ~;>
  • ~;% stays ~;%
  • ~;?n stays ~;?n

#2 Updated by Stefan Vieru about 1 year ago

  • Assignee set to Stefan Vieru

#3 Updated by Stefan Vieru about 1 year ago

  • Status changed from New to WIP

#4 Updated by Stefan Vieru about 1 year ago

Created branch 9918a with revno 15876
I detailed in code the change, so as a summary:
  • when we are placed inside a comment the alternative coding is not processed and ; is NOT duplicated
  • when we are outside a comment the alternative coding is not processed and ; IS duplicated

#5 Updated by Stefan Vieru about 1 year ago

while working on this I saw that the inString variable is not set correctly when reading the stream:
We have for example the following "text";&
When the read() function from ClearStream reaches ; the inString boolean is still set on True.
As a workaround i put this in text.g:

         // most (but not all) alternative codings that follow (without whitespace) a string literal
         // have a 4GL preproc quirk where the ; is eaten and the following char is left behind
         if (LA(1) == 0x3B                                    &&   // 0x3B is ; 
             ClearStream.isAlternativeCoding(LA(1), LA(2)))
         {
            if (LA(2) != 0x26                                 &&   // 0x26 is &
                LA(2) != 0x27                                 &&   // 0x27 is '
                LA(2) != 0x3F)                                     // 0x3F is ?
            {
                consume();
                text.setLength(text.length() - 1);
            }
            else
            {
                consume();
                consume();
                text.setLength(text.length() - 2);
                if (LA(1) == 0x20)
                {
                    consume();
                    text.setLength(text.length() - 1);
                }
            }
         }

And for & we get the expected output = "text". Will have to check for the other 2 cases.
EDIT: This is more relevant to #6308

#6 Updated by Stefan Vieru about 1 year ago

To explain the current issue, only right now &,when we have the following code:

txt = "text"~;&GLOBAL-DEFINE argname4 9
txt = 'text'~;&GLOBAL-DEFINE argname4 9
txt = "text"~;& GLOBAL-DEFINE argname4 9
txt = 'text'~;& GLOBAL-DEFINE argname4 9

OE preprocesses to:
txt = "text"~;;&GLOBAL-DEFINE argname4 9
txt = 'text'~;;&GLOBAL-DEFINE argname4 9
txt = "text"~;;& GLOBAL-DEFINE argname4 9
txt = 'text'~;;& GLOBAL-DEFINE argname4 9

FWD preprocesses to:

txt = "text"txt = 'text'txt = "text"txt = 'text'

What happens is the preprocessor directives are processed.
In the lexer the following &GLOBAL-DEFINE is tagged with AGLOBAL.
The changes I propose would imply changing this part of the lexing, resulting in
[00046:015] <CODE>                  ~;;
[00046:018] <CODE>                  &
[00046:019] <CODE>                  GLOBAL-DEFINE

and now preprocessing with FWD results:

txt3 = "text3"~;;&GLOBAL-DEFINE argname3 9
txt4 = 'text4'~;;&GLOBAL-DEFINE argname4 9
txt3 = "text3"~;;& GLOBAL-DEFINE argname3 9
txt4 = 'text4'~;;& GLOBAL-DEFINE argname4 9

Which is a match for OE.

#7 Updated by Stefan Vieru about 1 year ago

I have committed this to 9918a/15892.

#8 Updated by Stefan Vieru about 1 year ago

  • % Done changed from 0 to 30

#9 Updated by Stefan Vieru about 1 year ago

  • Related to Bug #6308: post string literal alternative coding quirk in 4GL preprocessor added

#10 Updated by Stefan Vieru about 1 year ago

I have found that when preprocessing the following in OE:

// ~;(
/* ~;( */

The alternative coding in the SLASH_SLASH is converted:

// ~{

/* ~;( */

In FWD we will need to differentiate if we are in a SLASH_SLASH comment or a STAR_COMMENT for this purpose.
What I'm suggesting is adding 2 more flags, inStarComment and inSlashComment, and having inComment = inStarComment || inSlashComment, so that we don't have to make too many changes to the source code.

#11 Updated by Greg Shah about 1 year ago

That seems reasonable.

#12 Updated by Stefan Vieru about 1 year ago

I've created r15902 with the addition of tildeOffset variable to environment.
The behavior would be the following:
  • when we encounter a tilde we check if an alternative coding is placed after it;
  • we then set the offset to 2, meaning that we skip the next 2 characters from being processed;
  • duplicating the ; character when encountered, but only outside of comments and strings;
  • we consume an ASTMT only if the offset is set on 0, for example:
    ~;?GLOBAL-DEFINED arg 1
    

    would need to be:
    ~;;?GLOBAL-DEFINED arg 1
    

    & would also need to be consumed when the offset is 0.

#13 Updated by Stefan Vieru about 1 year ago

  • Status changed from WIP to Review
  • % Done changed from 30 to 100

Greg, if you could please review the changes and let me know if I can make some improvements. Right now with the tests on testcases there are no issues.

#14 Updated by Stefan Vieru about 1 year ago

All changes have been moved to 6859b.

#15 Updated by Greg Shah about 1 year ago

  • reviewer Greg Shah added

#16 Updated by Greg Shah about 1 year ago

#17 Updated by Stefan Vieru 12 months ago

Tests that cover this:
  • alternative_coding_quirk_01
  • alternative_coding_quirk_01_analyze
  • alternative_coding_quirk_01_combined_directives_global
  • alternative_coding_quirk_01_combined_directives_scoped
  • alternative_coding_quirk_01_combined_directives_undefined
  • alternative_coding_quirk_01_else
  • alternative_coding_quirk_01_else_if
  • alternative_coding_quirk_01_endif
  • alternative_coding_quirk_01_if
  • alternative_coding_quirk_01_message
  • alternative_coding_quirk_01_post_string
  • alternative_coding_quirk_01_then
  • alternative_coding_quirk_01_tilde_strings
  • alternative_coding_quirk_01_undefine
  • alternative_coding_quirk_02
  • alternative_coding_quirk_02_left_bracket
  • alternative_coding_quirk_02_right_bracket
  • alternative_coding_quirk_03
  • alternative_coding_quirk_04
  • alternative_coding_quirk_05
  • alternative_coding_quirk_05_left_curly
  • alternative_coding_quirk_05_post_curly
  • alternative_coding_quirk_05_right_curly
  • alternative_coding_quirk_06
  • alternative_coding_quirk_07
  • alternative_coding_quirk_08_global
  • alternative_coding_quirk_08_scoped

#18 Updated by Greg Shah 11 months ago

  • Status changed from Review to Internal Test

I've reviewed this change and all the related change in 6859b. It is difficult to assess by code review alone, if these changes are correct. At this point, we have to carefully test the full range of customer applications to confirm if this is safe.

#19 Updated by Greg Shah 5 months ago

  • topics 4GL Preprocessor added

#20 Updated by Alexandru Lungu 3 months ago

  • Assignee changed from Stefan Vieru to Octavian Adrian Gavril

Also available in: Atom PDF