Project

General

Profile

Bug #9886

Double slashes should produce a new line during preprocessing

Added by Stefan Vieru over 1 year ago. Updated 5 months ago.

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

100%

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

Related issues

Related to Testing - Support #6859: preprocessor tests Test

History

#1 Updated by Stefan Vieru over 1 year ago

During preprocessing, the following:

// outside of comments and strings there is a quirk of the "alternative codings" 
// - the ;) alternative coding construct will be converted by the preproc to the } character
// - this occurs in comments and in regular code
// - no conversion occurs inside strings (either '' or "" style)
// - the quirk is that any ;) in code that immediately follows a string literal (either '' or "" style) will NOT con    vert but will emit as a single ) char
// - no whitespace or other chars can be between the string literal and the ;), the quirk only happens if it is dire    ctly following
// - this quirk does not manifest in comments
// - since alternative codings don't convert in strings, this quirk also doesn't appear in strings

Should preprocess to:
// outside of comments and strings there is a quirk of the "alternative codings" 

// - the } alternative coding construct will be converted by the preproc to the } character

// - this occurs in comments and in regular code

// - no conversion occurs inside strings (either '' or "" style)

// - the quirk is that any } in code that immediately follows a string literal (either '' or "" style) will NOT convert but will emit as a single ) char

// - no whitespace or other chars can be between the string literal and the }, the quirk only happens if it is directly following

// - this quirk does not manifest in comments

// - since alternative codings don't convert in strings, this quirk also doesn't appear in strings


But FWD preprocesses to:
// outside of comments and strings there is a quirk of the "alternative codings" 
// - the } alternative coding construct will be converted by the preproc to the } character
// - this occurs in comments and in regular code
// - no conversion occurs inside strings (either '' or "" style)
// - the quirk is that any } in code that immediately follows a string literal (either '' or "" style) will NOT convert but will emit as a single ) char
// - no whitespace or other chars can be between the string literal and the }, the quirk only happens if it is directly following
// - this quirk does not manifest in comments
// - since alternative codings don't convert in strings, this quirk also doesn't appear in strings

#2 Updated by Stefan Vieru over 1 year ago

#3 Updated by Stefan Vieru over 1 year ago

  • Status changed from New to WIP
  • Assignee set to Stefan Vieru

#4 Updated by Stefan Vieru over 1 year ago

Created branch 9886a with revision 15851.
The added changes fix the issue that when preprocessing with FWD a file, if a // (double slash) comment is present, a NL is not appended after the message.

#5 Updated by Stefan Vieru over 1 year ago

  • Status changed from WIP to Review
  • % Done changed from 0 to 100
  • reviewer Alexandru Lungu, Greg Shah added

#6 Updated by Greg Shah over 1 year ago

Code Review Task Branch 9886a Revisions 15850 and 15851

1. Could the problem here be something related to the Windows platform? On Windows, the platform newline is the CR (carriage return '\r' a.k.a. 0x0D) + LF (line feed '\n' a.k.a. 0x0A) where Linux just has the LF. What do the binary bytes look like at the end of the // lines?

2. If we go ahead with these changes:

  • Please change the Environment.get|setNewLine() to Environment.is|setNeedsNewLine(). getNewLine() doesn't explain the purpose clearly enough.
  • text.g needs a history entry.

#7 Updated by Stefan Vieru over 1 year ago

Greg Shah wrote:

Code Review Task Branch 9886a Revisions 15850 and 15851

1. Could the problem here be something related to the Windows platform? On Windows, the platform newline is the CR (carriage return '\r' a.k.a. 0x0D) + LF (line feed '\n' a.k.a. 0x0A) where Linux just has the LF. What do the binary bytes look like at the end of the // lines?

To clarify further:
  • in OE with /* */ comments we don't have two /r/n, but with // we do. The following processes as it is.
    /* outside of comments and strings there is a quirk of the "alternative codings" */
    message "test".
    /* - the ;) alternative coding construct will be converted by the preproc to the } character */
    
  • if we have // instead of /* */, the output is:
    // outside of comments and strings there is a quirk of the "alternative codings" 
    
    message "test".
    // - the ;) alternative coding construct will be converted by the preproc to the } character
    
    
  • in OE we have \r\n when we have a NL; Meaning when we have a // comment, we have two /r/n after it.
  • in FWD whether we use Preprocessor on windows or unix we have ONLY \n, due to the following I think
             // normalize new lines
             if (nextChar == '\r')
             {
                int pastNextChar = mread();
                if (pastNextChar != '\n')
                {
                   super.unread(pastNextChar);
                }
                nextChar = '\n';
             }
             if (nextChar == '\n')
             {
                return nextChar;
             }
    

#8 Updated by Stefan Vieru over 1 year ago

I updated the branch, new rev 15852.

#9 Updated by Greg Shah over 1 year ago

Code Review Task Branch 9886a Revision 15852

I'm good with the changes.

#10 Updated by Greg Shah over 1 year ago

in FWD whether we use Preprocessor on windows or unix we have ONLY \n, due to the following I think

Please register a bug for this. I think we can defer that work, but eventually we may need to match the line endings to the platform. The question is whether we need to do that to match the legacy platform that was used or to the runtime platform on which we execute.

#11 Updated by Greg Shah over 1 year ago

  • Status changed from Review to Internal Test

#12 Updated by Stefan Vieru about 1 year ago

I have rebased and tested this with a customer application. The "deploy" step passed.

#13 Updated by Greg Shah about 1 year ago

I have rebased and tested this with a customer application. The "deploy" step passed.

Was this an application that normally runs on Windows?

Please also check conversion of ChUI regression testing.

#14 Updated by Stefan Vieru about 1 year ago

Will start the CHUI regression tests after #5586. I have added another rev, 15911. The changes:
  • flag is not initialized at the beggining of the SLASH_SLASH
  • in ClearStream we look at the flag and check if it's followed by a WS or EOF, if so we unread it and return a \n
  • if we are at the EOF and have the flag set on true, we have to return \n

#15 Updated by Stefan Vieru about 1 year ago

All changes have been moved to 6859b.

#16 Updated by Stefan Vieru about 1 year ago

  • Status changed from Internal Test to Review

I updated this so I will need an review on 6859b regarding my changes:
I've added

             }
          }
       }
+      (
+         {$getText.equals("&THEN") || $getText.equals("&ENDIF")}?
+            (
+                  {!(LA(2) >= 'a' && LA(2) <= 'z') &&
+                   !(LA(2) >= 'A' && LA(2) <= 'Z') &&
+                   !(LA(2) >= '0' && LA(2) <= '9')}? ' '!
+               |  // nothing
+            )
+            {
+               if (LA(1) == '/' && LA(2) == '/')
+               {
+                  env.setNeedsNewLine(true);
+                  env.setInStatement(false);
+               }
+            }
+         |  // nothing
+      )
    ;

At the end of ASTMT.

And also in the Parser added:

text
    :
       textBlock
+      {
+         if (env.isNeedsNewLine())
+         {
+            env.setNeedsNewLine(false);
+            env.print("\n");
+         }
+      }
       EOF
    ;

To fix a bug that occurred with the previous solution.
Had to remove some stuff from ClearStream too.

#17 Updated by Stefan Vieru 12 months ago

Testcases that cover this:
  • comments

And the other tests have this checking for SLASH_SLASH creating a NL, but comments is dedicated to SLASH_SLASH and STAR_COMMENT.

#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

Also available in: Atom PDF