No announcement yet.

Python missing leading space compare

  • Time
  • Show
Clear All
new posts

  • Python missing leading space compare

    Correct me if I'm wrong, but I think this element should be in the default python file format:
    Leading White Space=Text matching ^\s*[^\s]

    Didn't see this anywhere else in the forum when I searched, but maybe I missed it. The defaults for Python show changes in leading space as unimportant, but as any Python programmer knows that isn't the case.


  • #2

    We wouldn't want to make the first character match as part of the whitespace. What do you think of:
    Aaron P Scooter Software


    • #3

      Thank you for pointing out this error in the File Format. We'll have this fixed in our next release of BC3 (3.0.16).
      Chris K Scooter Software


      • #4
        Continuing issue with Python whitespace

        There's still a Python whitespace problem in the current BC version 3.1.4.

        If two lines contain nothing but whitespace and comments, then they should not be considered significantly different from each other, no matter what the indentation level.

        In contrast, BC thinks that leading whitespace differences on lines with no code are important.

        If it were possible to strip all trailing whitespace (including comments) before considering leading whitespace, then all such lines would simply be read as empty, and it seems that this problem would disappear.


        • #5
          If the whitespace is within the definition of Comment, then it will be considered the level of Importance used for Comment.

          It sounds like you want the Comment to be Important and the whitespace to be Unimportant. In this case, you could delete the definition of Comment and let it use the default Everything Else and Whitespace rules.

          It is on our wishlist to add more whitespace handling to our grammar elements.
          Aaron P Scooter Software


          • #6
            Perhaps I wasn't clear enough in my description of the problem.

            1. The problem occurs even if no comment is involved. The simplest example is that a line with only whitespace is (wrongly) considered to have important differences from an empty line. So an editor which cleans up trailing whitespace can cause BC to see lots of spurious "significant differences."

            2. Actually, I have both comment and white space as not important, which means that all lines containing only whitespace and comments should be only unimportantly different from each other. Yet BC thinks they are not.


            • #7

              Thanks for the clarification.

              Would you be able to email in your support package (Help menu -> Support; Export) and a pair of sample files to [email protected]

              Please include a link back to this forum post as well.
              Aaron P Scooter Software


              • #8
                Support package and sample files emailed. Thanks.


                • #9

                  We are looking at making lines with only whitespace a new grammar element:
                  and including optional leading whitespace in the comment definition:
                  \s*# to end of line
                  Aaron P Scooter Software


                  • #10
                    Thanks, Aaron, that seems to work -- and now I see how cleanly grammar and importance are specified in BC... nice!