[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] BBedit 5.0 Function Parsing (Was: Improved Perl Syntax Coloring in BBEdit 5.0)



Jeff at MacTech wrote:
> BBEdit 5.0, which just came out, has improved its perl 
> syntax-coloring,


(ASIDE: Hmmmm... has the list moved to CalTech now? Is a 
digest form eminent... and an update to the footer text?)


I got the CD last night, and I'm loving it :)

There's still a few (old not new) perl parsing problems 
though. The function menu seems to be driving by a much more 
primitive engine. Previously I was too lazy to isolate its 
problems, but lastnight/thismorning I've made a few attempts 
and sent notes to support@bb, so hopefully they'll be fixed 
in an upcoming maintc release.

In case any of you have been running into problems, here's a 
few vague pointers on what you can do to get the function 
popup menu working for you in bbedit (if this is too messy, 
you can just use the marks menu which is now equally 
convenient in 5.0... but marks get lost if your script goes 
to unix and back).

The function parser has trouble knowing to not parse parens 
and braces inside strings. (and maybe regexen... I haven't 
checked). This trouble is less accute in double-quoted 
strings, but is not entirely relieved as I originally 
thought.

Sometimes the parser will see open parens/braces or closing 
parens/braces in strings, and will not recognize that sub, 
or any subsequent sub in your popup funcs menu.

To remedy this, you have to occasionally provide matching 
opening/closing parens/quotes before/after the offending 
string. In some cases, the matching character(s) can be in 
comments, but not all cases. In some cases you have to match 
the type of string of the original false-ly opened/closed 
paren/brace... IE use a HEREDOC if that's where the parser 
spoted the other half of the pair.


I've got a bunch of scripts that need to go back and forth 
from unix/mac so using the marks option isn't as attractive 
as it would otherwise be. These scripts automate the 
creation of all sorts of Rich Text Format documents, so 
there are mismatched braces all over the place.

Below is a short sub which requires four separate hacks 
(using a global $nul set asside for this sort of thing) to 
play nice with the function pop up menu. Hopefully the above 
clues and the example below will be of use to any of you 
experiencing mysterious frustrations with the function popup 
menu. In previous versions it also had problems with regexen 
(like having a quote character in one) so you may need to 
look there too...

-matt

EXAMPLE SUB:

sub make_envelope_rtf_file {
	# takes array ref and returns string to be written as some file.rtf
	# ref'ed array has one string per envelope... each string needs to
	# be tweaked a bit as it gets added to the big rtf file
	# (newlines need to be made into rtf newparagraphs)
	$nul = "{";
	my $joiner = "\\sect }\\sectd \\linemod0\\linex0\\cols1\\endnhere
\\pard\\plain \\li5040 \\f22\n{\\f20 ";
	$nul = "}";
	my $rtf = <<'END_OF_HEREDOC';
{\rtf1\mac\deff2
{\fonttbl {\f20\froman Times;}{\f22\fmodern Courier;}}
{\colortbl\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;}
{\stylesheet {\f22 \sbasedon222\snext0
Normal;}}\paperw15840\paperh12240\margl900\margr2880\margt6030\margb0\widowctrl\ftnbj\fracwidth 
\sectd \linemod0\linex0\cols1\endnhere \pard\plain \li5040 \f22
{\f20 
END_OF_HEREDOC
	$nul = <<'NUL';
}}
NUL
	my @adr = @{$_[0]};
	for (@adr) {
		m/\n$/ or $_ .= "\n";
		s/\n/\\par \n/g;
		$rtf .= $_;
		$rtf .= $joiner;
	}
	$nul = "{{";
	$rtf .= "}}\n";
	return $rtf;
}

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch