Syntax color: feature, bug or style?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
webmasta
Posts: 169
Joined: Mon Jul 28, 2003 8:16 pm
Location: Toronto

Syntax color: feature, bug or style?

Post 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..
User avatar
bbadmin
Site Admin
Posts: 820
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post 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
User avatar
webmasta
Posts: 169
Joined: Mon Jul 28, 2003 8:16 pm
Location: Toronto

Post 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:
User avatar
bbadmin
Site Admin
Posts: 820
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post 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>
User avatar
boldan
Posts: 31
Joined: Tue Jul 22, 2003 2:47 pm
Location: Toronto
Contact:

Post 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.
crassius
Posts: 24
Joined: Fri Jul 18, 2003 7:08 pm

is this the latest ver?

Post 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.
User avatar
webmasta
Posts: 169
Joined: Mon Jul 28, 2003 8:16 pm
Location: Toronto

Post 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
crassius
Posts: 24
Joined: Fri Jul 18, 2003 7:08 pm

comment color at $#listvar

Post by crassius »

OK, looks like I better wait to update then.
Post Reply