No announcement yet.

Text compare

  • Filter
  • Time
  • Show
Clear All
new posts

  • Text compare

    Comparison for bash files/scripts does not understand the heredoc syntax.
    If there is a SINGLE QUOTE character, inside a heredoc, beyond compare treats it as an opening quote, and the remainder of the file (or up to the next quote - what would look like a closing quote).

    Therefore, the comparison shows diff where there is none:

    (Attaching the two files used to create this screenshot. Please rename the files to have .sh extension, so beyondcompare recognizes them as shell scripts.)

    Click image for larger version

Name:	image.png
Views:	121
Size:	55.1 KB
ID:	88619
    Attached Files

  • #2

    Correct, the Bash Script File Format does not have a grammar defined for HEREDOC, so the single quote is likely detecting as the String definition. You can click the cursor into the text area and the bottom status bar will show the element name detected that the cursor is currently residing in, on the left and the right panes.

    You can define a new Grammar Element, type delimited, to match on HEREDOC << E0TXT to E0TXT (disable end at end of line) and that looks like it would work for these files. BC4's RegEx within grammar element definitions does not support back references, however, so masking for specific ExTXT pairings isn't possible. You could define E\dTXT, but this can potentially activate on any number, not a specific (correct) pairing.

    Edit: Sorry, I forgot the link to the KB article that goes into detail on defining grammar elements, here:
    Last edited by Aaron; 29-Aug-2022, 02:16 PM. Reason: Update: adding link to KB article
    Aaron P Scooter Software


    • #3
      Thank for the the quick response Aaron

      I will play with the grammar, and see if I can get something to work.
      I'm new to creating grammars in BC4, and what I tried based on your instructions didn't work (see screenshot at the end of this message).

      Just a point of clarification:

      The start/end of the heredoc can be ANY text - FOO, BAR, EOTEXT, E0TEXT.
      (Minor note: In the above example, I used an abbreviation of EndOfText - EOTEXT - and not E-Zero-Text/E0TEXT. Thus, E\dTEXT is not a regex that would match.)
      So, you are correct, without back references, I don't think it's possible to define a general grammar rule.

      It is interesting to have a reason to play with BC4's grammars.

      But, we can live without this. There are many ways to write English without apostrophes. :-)

      Thank you again.

      Click image for larger version

Name:	image.png
Views:	87
Size:	128.0 KB
ID:	88633


      • #4

        I thought that might be the case. It's on our wishlist to expand our regex support for grammar elements, but for now you would have to define the delimited element more literally. Similarly to having multiple "String" grammars defined: one as " to " and one as ' to '
        By giving them the same name, there is a single toggle in the Session Settings, Importance tab. Toggling on or off String then marks all String elements as Important or Unimportant.

        Similarly here, you could define each as HEREDOC E0TEXT to E0TEXT, and HEREDOC FOO to FOO, but name the element a common "heredoc" name.

        Alternatively, you could delete the String grammar, which would make that text revert to Everything Else (as ' to ' would no longer be a string).
        Aaron P Scooter Software