Suggestion, the Replacements feature should allow replaced-with-empty-string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chjfth
    Journeyman
    • Aug 2008
    • 15

    Suggestion, the Replacements feature should allow replaced-with-empty-string

    I'm using BC3.0.4 .

    Sometimes, people just want to replace something to empty then carry on the compare. Don't you think so?

    Check this image to get a hint:

  • Michael Bulgrien
    Carpal Tunnel
    • Oct 2007
    • 1772

    #2
    Typically Replacements in Session Settings require a 1-to-1 match. In other words, unless the "Replace with" text is found on the right, the "Text to find" on the left is not logically replaced while comparing the two sides. Since you can't detect an empty string on the right (there is nothing to find) the logical replacement on the left would never get triggered (with the current logic, anyways).

    What you propose has interesting implications, however. Replacing with an empty string, if it were supported, would simply render that text as unimportant wherever it appears in the left-hand pane without regard to the content of the right-hand side. I don't know what it would take to implement...but it does sound like it would be a useful option.
    BC v4.0.7 build 19761
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Comment

    • Michael Bulgrien
      Carpal Tunnel
      • Oct 2007
      • 1772

      #3
      FYI - I'm not sure what you were trying to accomplish by defining a replacement with empty text, but you could probably accomplish the same thing by creating a new grammar element using the same regular expression, and setting the grammar element to unimportant.
      BC v4.0.7 build 19761
      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

      Comment

      • chjfth
        Journeyman
        • Aug 2008
        • 15

        #4
        Well, I still can't figure out how to define a grammar element to accomplish my goal.

        Check my concrete example below:



        My text files is in attachment.

        Comment

        • Michael Bulgrien
          Carpal Tunnel
          • Oct 2007
          • 1772

          #5
          Watch this screencast...

          Basically create a RegEx grammar defined as: ^[[][A-Z][\]]

          Make it case insensitive and unimportant.

          If you don't know regular expressions, the grammer can be broken down as follows:

          ^[[][A-Z][\]]

          ^ = Start at beginning of line
          [[] = Opening Square Bracket
          [A-Z] = Alphabetic Character
          [\]] = Closing Square Bracket

          Square brackets define a class of valid characters for each position of the grammer. The "]" in the last character class had to be preceeded by a "\" to indicated that it represents the "]" character, and not the closing bracket of the character class.
          BC v4.0.7 build 19761
          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

          Comment

          • chjfth
            Journeyman
            • Aug 2008
            • 15

            #6
            Thank you for your answer, Michael. I tried your way using ^[[][A-Z][\]] , and that works(grammer category=basic). Suprisingly, it works even I don't append a space after ^[[][A-Z][\]] . I thought a trailing space should be required because there is a space after my [C] line prefix.

            But why can't I use ^\[[A-Z]\] instead. It also matches, say, [C] at start of a line.

            Comment

            • Michael Bulgrien
              Carpal Tunnel
              • Oct 2007
              • 1772

              #7
              ^\[[A-Z]\] should work fine. There is no need to define a class for a single character.
              BC v4.0.7 build 19761
              ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

              Comment

              • chjfth
                Journeyman
                • Aug 2008
                • 15

                #8
                Thank you. I confirmed it, ^\[[A-Z]\] is OK.

                Comment

                • Michael Bulgrien
                  Carpal Tunnel
                  • Oct 2007
                  • 1772

                  #9
                  Originally posted by chjfth
                  Suprisingly, it works even I don't append a space after ^\[[A-Z]\]. I thought a trailing space should be required because there is a space after my [C] line prefix.
                  If you look at the Importance tab under Session Settings, you will see that the checkbox for "Leading whitespace" is unchecked. So is "Embedded whitespace" and "Trailing whitespace" for that matter. This means that extra tabs and/or spaces will always be considered as unimportant in the C file format. Since the space is already unimportant, it does not need to be appended to the replacement regular expression that you've defined to make the initial bracketed character unimportant.
                  BC v4.0.7 build 19761
                  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                  Comment

                  Working...