#128 Line comment rules incorrect

jflex bug
open
nobody
None
5
2015-02-15
2014-04-04
Elliott
No

I've seen a matching rule like this in many places (the jflex manual, the source of Cup, ..?):
EndOfLineComment = "//" {InputCharacter}* {LineTerminator}

If I'm not mistaken this is broken if the line comment is on the last line. By either removing {LineTerminator} or making it {LineTerminator}? it seems to work as expected. Might be good to fix so the bug doesn't spread further.

Related

Bugs: #128

Discussion

  • Régis Décamps

    Régis Décamps - 2014-05-17

    But if we remove it, it could consume all input characters until the end of file, including non comment.
    The best practice is to append an empty line to the input document, before parsing.

     
    • Elliott

      Elliott - 2014-05-17

      To clarify, I was thinking InputCharacter could be something like [^\r\n].
      On May 17, 2014 9:40 AM, Régis Décamps decamps@users.sf.net wrote:

      But if we remove it, it could consume all input characters until the end
      of file, including non comment.
      The best practice is to append an empty line to the input document, before
      parsing.


      Status: open
      Group: jflex bug
      Created: Fri Apr 04, 2014 05:19 AM UTC by Elliott
      Last Updated: Fri Apr 04, 2014 05:19 AM UTC
      Owner: nobody

      I've seen a matching rule like this in many places (the jflex manual, the
      source of Cup, ..?):
      EndOfLineComment = "//" {InputCharacter}* {LineTerminator}

      If I'm not mistaken this is broken if the line comment is on the last
      line. By either removing {LineTerminator} or making it {LineTerminator}? it
      seems to work as expected. Might be good to fix so the bug doesn't spread
      further.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/jflex/bugs/128/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #128

      • Régis Décamps

        Régis Décamps - 2014-05-18

        I though further about it, and I think you are correct.

         
  • Régis Décamps

    Régis Décamps - 2014-05-18

    In java.flex example, we already have

    EndOfLineComment = "//" {InputCharacter}* {LineTerminator}?
    

    I've updated the JFlex manual.

    In, LexScan.flex, we only have

    EndOfLineComment = "//".*{NL}
    

    But for some reason, Jflex parses the grammar correctly even if it ends with a single EndOfLineComment.

     
    • Gerwin Klein

      Gerwin Klein - 2014-05-18

      In LexScan.flex this is correct, because EndOfLineComment isn't used in the last section of specs (REGEXP/REGEXPSTART). In this last section, the expression is

      {WSP}* "//" {NNL}*
      

      and newline is matched/ignored separately.

      So if it's Ok in the examples, we only need to update the manual.

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks