Curly Braces Issue Solved

I’ve been carrying this issue around since v0.2, basically what it means is when you have curly braces ({,}) which are not related to your code’s structure (stuff like private string _foo = “lala}la”;) it tips the balance of the rest of the structural brackets.

So if the following class was declared

   1:  public class Foo
   2:  {
   3:        string bar = “}”;
   4:  }

Regionerate would have identified this as the entire class

   1:  public class Foo
   2:  {
   3:        string bar=”}

Pretty annoying, I agree, but now I have found a solution for it.

Prior to construction, all curly braces which are inside string literals are replaced to {?} where ? is an angle bracket pointing at the original bracket.

For example,

   1:  private string _foo = “{”;

would turn into

   1:  private string _foo = “{<}”;

and

   1:  private string _bar = “}”;

would turn into

   1:  private string _bar = “{>}”;

 

This helps to keep the balance at all situations. After layout is applied the original code is fully restored.

This seems like a hack, but I don’t think of it as one, as it does not interfere with anything else and Regionerate will never get around to constructing string literals so this will not impose any limitations in the future.

 

This entry was posted on Thursday, November 8th, 2007at 8:02 am and is filed under Bug Fixes, Public Beta, v0.6, v0.6.6.5. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response or trackback from your own site.

 

5 Responses to “Curly Braces Issue Solved”

  1. It is a hack, but this bug was so annoying that I really don’t care. I’m just plain happy that you managed to fix that :).

    ps what if I have a string like
    string pies = “kot{< }knur{>}”;
    will this not get broken?

    Posted by Krzysztof on November 8th, 2007 11:02 am

  2. Xtoff,

    string pies = “kot{< }knur{>}”;

    will turn into

    string pies = “kot{< }<{>}knur{< }>{>}”;

    Which will restore to the original value correctly.

    Posted by Omer Rauchwerger on November 8th, 2007 11:05 am

  3. I admit ignorance/laziness in not looking at the source code here and not trying it myself, but wouldn’t a lot of these issues be easier to solve using System.CodeDom sorts of things? The CodeDom would know about string literals.

    Might also be worthwhile looking at the DevExpress DXCore engine for Visual Studio. Free, and it has a much easier to use language parser that allows for things like this.

    Posted by Travis Illig on November 9th, 2007 10:56 pm

  4. Travis,

    It’s nice to know you are a reader. I really like CR_Documentor.

    About CodeDom - correct me if I’m wrong, but isn’t it more of a generator instead of a parser?

    And about the DxCore - I agree it would make life much easier, but I didn’t like its distribution terms so I continued with my painful home-grown solution.

    Posted by Omer Rauchwerger on November 10th, 2007 10:03 am

  5. What about using the VisualStudio Automation Code Model? granted it’s COM base and it’s rather ugly :)

    I would go with something like the Antlr parser…

    Posted by Firefly on May 25th, 2008 4:00 pm

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>