switch -regexp $current_net {
[^\[]+\Z {
# first case: <net_name> (1bit width)
switch [llength $pins($module_name,$k)] {
.....
The first "switch" saying that I want to parse any regexp with no '['
and going to the end of string $current_net.
Then Tcl says :
couldn't compile regular expression pattern: parentheses () not
balanced
while executing
"switch -regexp $current_net {
etc.
How can I get rid of this message? And it's not the first time I have
such odd problems :-)
Thanks.
> switch -regexp $current_net {
> [^\[]+\Z {
> # first case: <net_name> (1bit width)
> switch [llength $pins($module_name,$k)] {
> couldn't compile regular expression pattern: parentheses () not
> balanced
What you show is not the source for this error (except that
it is a fragment with obviously mismatched delimiters).
> The first "switch" saying that I want to parse any regexp with no '['
> and going to the end of string $current_net.
No, it says (or tries to say) match any string in which "[" is not
the last character. But because of lack-of-quoting, it says even worse:
match any string which does not contain "[Z".
You need to anchor the start (with \A or ^) to force matching the
entire string, and therefore forbid all "[". You should have
luck with:
switch -regexp $current_net {
{\A[^[]+\Z} {
But why don't you reverse the cases
switch -regexp $current_net {
{\[} {
}
default {
#
}
--
Donald Arseneau as...@triumf.ca
try doubing the first backslash: [^\\[]+\Z
It may have to do with one extra "half" round
of substitution that happens inside the switch
body, namely parsing it as a list:
This will treat backslashes, but not square-brackets,
thus the RE was seen by switch as: [^[]+Z
Btw, you'll likely also need a leading '^', or it might then
match things like "[[[[[[[[[[[[[[[[42", (matching successfully
the substring made of the last two characters).
> How can I get rid of this message? And it's not the first time I have
> such odd problems :-)
The problems in the past may be just like this one due to
insufficient protection.
PS: Of course, the content of the switch body is *not*
subject to substitution *before* switch sees it (due to
the braces), but switch itself *then* causes that extra
round - just before it interprets the pattern.
because when you place it in the body of the switch statement
it is NOT a comment - it is a series of pattern action pairs -
and if it is not an even number, you have problems. (Actually
even if you have even numbers you can still have problems, just
of a different kind).
For a detailed explanation see http://wiki.tcl.tk/comment
Bruce
Well, this being Tcl -- write your own switch:
proc myswitch {args} {
set body [lindex $args end]
regsub -all -line {[^\\]?#.*$} $body { } body
uplevel 1 switch [lreplace $args end end $body]
}
myswitch -regexp -- $url {
# Comment in a switch body...
{http://(.*)} { puts "HTTP URL" }
default { puts "Unknown" }
}
Now you can put comments wherever you want in the switch body. The
regexp could be improved to take proper care of the # character. For
instance, something like:
\\# this is a comment
will be missed. But I don't expect this will be a common situation.
-- Neil