You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2020/03/23 02:55:13 UTC

[GitHub] [groovy] moaxcp commented on a change in pull request #1203: Changing SH_COMMENT to allow multiple shell directives

moaxcp commented on a change in pull request #1203: Changing SH_COMMENT to allow multiple shell directives
URL: https://github.com/apache/groovy/pull/1203#discussion_r396190818
 
 

 ##########
 File path: src/antlr/GroovyLexer.g4
 ##########
 @@ -948,7 +948,7 @@ SL_COMMENT
 // Script-header comments.
 // The very first characters of the file may be "#!".  If so, ignore the first line.
 SH_COMMENT
-    :   '#!' { require(0 == this.tokenIndex, "Shebang comment should appear at the first line", -2, true); } ~[\r\n\uFFFF]* -> skip
+    : '#!' { require(0 == this.tokenIndex, "Shebang comment should appear at the first line", -2, true); } ~[\r\n\uFFFF]* LineTerminator ('#!' ~[\r\n\uFFFF]* LineTerminator)* -> skip
 
 Review comment:
   This change worked for antlr4 but I'm having trouble with antlr2.
   
   ```
   SH_COMMENT
   options {
       paraphrase="a script header";
   }
       :   {getLine() == 1 && getColumn() == 1}?  "#!"
           (
               options {  greedy = true;  }:
               // '\uffff' means the EOF character.
               // This will fix the issue GROOVY-766 (infinite loop).
               ~('\n'|'\r'|'\uffff')
           )*
           (ONE_NL[true] "#!"
             (
                 options {  greedy = true;  }:
                 // '\uffff' means the EOF character.
                 // This will fix the issue GROOVY-766 (infinite loop).
                 ~('\n'|'\r'|'\uffff')
             )*
           )*
           { if (!whitespaceIncluded)  $setType(Token.SKIP); }
       ;
   ```
   
   I'm getting this error in the test
   
   ```
   org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
   subprojects/parser-antlr4/src/test/resources/core/Comments_03.groovy: 4: expecting '#', found '/' @ line 4, column 1.
      /*
      ^
   
   1 error
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services