carlynorama / Arduino-BBEdit

New location for the Codeless Language Module
14 stars 6 forks source link

Weird interaction comments to code folding? #1

Open michthom opened 10 years ago

michthom commented 10 years ago

Hi there - love this CLM, though I only found it recently. I've noticed that if I include comments with any of the characters ' " or { (but not &close curly brace - } ) then BBEdit can't find the current function boundary any more, and starts reporting for / if blocks as new functions. I'm guessing it's somewhere in the Function Pattern, but my regex analysis isn't up to finding the culprit.

So this parses correctly. and the functions are both shown in the browser:

void setup() {
  int i = 0;
  int j = 0;
}

void loop() {
  j = 0;
  for ( i = 0; i < 10; i++ ) {
    j = j + i;
  }
}

Name  Line
setup 1
loop  6

But these don't, and only the first function appears, the second gets mistaken for a loop:

void setup() {
  int i = 0;
  int j = 0;
}

void loop() {
  j = 0;
  // ' " { << BOGUS COMMENT
  for ( i = 0; i < 10; i++ ) {
    j = j + i;
  }
}

Name  Line
setup 1
for   9
michthom commented 10 years ago

Yay. Fixed it, I think.

I nested the non-comment options one level lower so comments take priority, and the function parsing works as expected.

So from this:

<string>(?x: (?P&lt;function&gt; (?P&lt;function_name&gt; (?&gt; _* [A-Za-z] [A-Za-z0-9_]* ) (?: (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* :: (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* ~? _* [A-Za-z] [A-Za-z0-9_]* )? ) (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* (?P&lt;parens&gt; \( (?: (?&gt; (?&gt; [^'"()]+ ) | (?: / (?![/*]) ) | (?P&gt;comment) | (?P&gt;string) | (?P&gt;parens) ) )* \) ) (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* (?: : (?: (?&gt; (?&gt; [^'"{]+ ) | (?: / (?![/*]) ) | (?P&gt;comment) | (?P&gt;string) ) )* )? (?P&lt;braces&gt; { (?: (?&gt; (?P&gt;comment) | (?&gt; [^{}]+ ) | (?: / (?![/*]) ) | (?P&gt;string) | (?P&gt;braces) ) )* } ) ) )</string>

To this:

<string>(?x: (?P&lt;function&gt; (?P&lt;function_name&gt; (?&gt; _* [A-Za-z] [A-Za-z0-9_]* ) (?: (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* :: (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* ~? _* [A-Za-z] [A-Za-z0-9_]* )? ) (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* (?P&lt;parens&gt; \( (?: (?&gt; (?&gt; [^'"()]+ ) | (?: / (?![/*]) ) | (?P&gt;comment) | (?P&gt;string) | (?P&gt;parens) ) )* \) ) (?: (?&gt; (?&gt; \s+ ) | (?P&gt;comment) | (?P&gt;string) ) )* (?: : (?: (?&gt; (?&gt; [^'"{]+ ) | (?: / (?![/*]) ) | (?P&gt;comment) | (?P&gt;string) ) )* )? (?P&lt;braces&gt; { (?: (?&gt; (?P&gt;comment) | ( (?&gt; [^{}]+ ) | (?: / (?![/*]) ) | (?P&gt;string) | (?P&gt;braces) ) ) )* } ) ) )</string>