Page 1 of 1

Syntax color: feature, bug or style?

Posted: Thu Sep 04, 2003 5:57 pm
by webmasta
screenshot here

In the above screenshot..
My comment color (red) is going good up to line 151.
Notice that on line 155 the comment color has switched to the string color (purple)

Resaon being that line 153 is a regex with three double quotes> $item =~ /"([^"]+)"/;
TP is thinking that the third " in the regex starts a string and everything until the next " is colored purple..

Look at line 164.. print is a keyword and should be blue... but because its part of the assumed string up to the matching " just after print, it is also colored purple.

At the end of that line (164) is another keyword (if) which should also be blue, but because a " is just in front , TP assumes another string has started and colored it purple.

Everything went out of sync till end of file..

Posted: Thu Sep 04, 2003 6:22 pm
by bbadmin
TextPad's syntax analyser can cope with most programming languages, but some, such as Perl, have constructs that require a full semantic analysis, to determine the context. If regular expressions were always written as /.../ it would be easy, but as Larry Wall is so fond of saying, "There's more than one way to do it". We considered that a semantic analysis would be overkill for a general purpose text editor, and would slow everything else up, so didn't implement it.

You'll often see the following workaround in Perl scripts, to allow for all the text editors that get out of sync when parsing quotes:

$item =~ /"([^"]+)"/; # "

The commented out quote keeps both Perl and TextPad happy.

Keith MacDonald
Helios Software Solutions

Posted: Thu Sep 04, 2003 6:37 pm
by webmasta
Good one Keith, figured that I had to inject a #" somewhere to even the equation..
but as Larry Wall is so fond of saying, "There's more than one way to do it"
Thats true for 99% of Perl .. except that the 1% he didnt figure is the most annoying ...

/#*
the ability
to comment
multiple lines
*#/

What was he thinking? :roll:

Posted: Thu Sep 04, 2003 7:32 pm
by bbadmin
What was he thinking?
<Off topic> That's what I often wonder about his "more than one way to do it" thing. It's OK if you're writing something quick and dirty for yourself, but if you've got to maintain someone else's "my way" Perl code, well rather you than me! </Off topic>

Posted: Fri Sep 05, 2003 6:01 pm
by boldan
I have a similar problem with syntax highlighting for SAS. In SAS, an asterisk can be a multiplication operator and a comment starting character. TextPad can't recognize both, and I have to live with it.

For example:

a = b * c; * This is a comment;

The first asterisk shows multiplication, the second one starts the comment. To make TextPad to display proper colours, I double the comment asterisk:

a = b * c; ** This is a comment;

and define alternate comment starting with 2 asterisks. That's why I asked how to change one asterisk with two a little while back.

is this the latest ver?

Posted: Fri Sep 05, 2003 6:59 pm
by crassius
I see that on line 142, where you get the scalar of your list, that your textpad colors this as a comment. I recall that this was changed (I think in a bug fix) so that a comment starting other than as a newline is not recognized unless preceeded by a <space> char.

I tried your line 142 on my textpad and did not get comment color there unless I put a <space> between the '$' and the '#'.

I'm running 4.7 and was wondering if you're on 4.7.1 or something else.

Posted: Fri Sep 05, 2003 7:48 pm
by webmasta
No Crassius, my comments are exactly how they appear in the shot with or without space.
I have the lastest build of 4.7.1

webM

comment color at $#listvar

Posted: Sat Sep 06, 2003 5:55 pm
by crassius
OK, looks like I better wait to update then.