All these options are not the same as the question. I need to match the right bracket as part of a character set. I need to match all types of brackets, and so am using the glob "[()[]{}]", which of course doesn't work.
Does Tcl have fall-through handling of cases? As a workaround I could match the string with the character class containing all the other types, and then match this one specific case separately and fall through.
> All these options are not the same as the question. I need to match the right bracket as part of a character set. I need to match all types of brackets, and so am using the glob "[()[]{}]", which of course doesn't work.
> Does Tcl have fall-through handling of cases? As a workaround I could match the string with the character class containing all the other types, and then match this one specific case separately and fall through.
Your question was not clear. Have you looked at the manual of switch?
On Sunday, June 3, 2012 10:01:42 PM UTC+3, George Petasis wrote:
> Στις 3/6/2012 21:23, ο/η bmburst...@gmail.com έγραψε:
> > On Sunday, June 3, 2012 8:04:01 PM UTC+3, Uwe Klein wrote:
> >> bmburst...@gmail.com wrote:
> >>> Can anyone answer my question that I posted here: http://stackoverflow.com/questions/10871855/tcl-match-closing-bracket...
> > All these options are not the same as the question. I need to match the right bracket as part of a character set. I need to match all types of brackets, and so am using the glob "[()[]{}]", which of course doesn't work.
> > Does Tcl have fall-through handling of cases? As a workaround I could match the string with the character class containing all the other types, and then match this one specific case separately and fall through.
> Your question was not clear. Have you looked at the manual of switch?
Thank you. I don't know why I didn't think of using regex instead of glob. But this seems to be a bug in Tcl that the ']' can't be escaped in a glob pattern character set.
> I need to match the right bracket as part of a character set. I need to match all types of brackets, and so am using the glob "[()[]{}]", which of course doesn't work.
To my knowledge, this is not possible directly with glob matching.
However, it is easy with regexp matching: just put the "]" as first in
range:
regexp {[][(){}]} $x
See the "BRACKET EXPRESSIONS" section in the re_syntax manpage.
Στις 3/6/2012 22:11, ο/η bmburst...@gmail.com έγραψε:
> Thank you. I don't know why I didn't think of using regex instead of glob. But this seems to be a bug in Tcl that the ']' can't be escaped in a glob pattern character set.
I am not sure I understand. Why can't ] be escaped?
\] is a normal character, and can be used in any glob pattern.
On Jun 3, 10:10 pm, George Petasis <petas...@yahoo.gr> wrote:
> Στις 3/6/2012 22:11, ο/η bmburst...@gmail.com έγραψε:
> > Thank you. I don't know why I didn't think of using regex instead of glob. But this seems to be a bug in Tcl that the ']' can't be escaped in a glob pattern character set.
> I am not sure I understand. Why can't ] be escaped?
> \] is a normal character, and can be used in any glob pattern.
Alexandre Ferrieux <alexandre.ferri...@gmail.com> wrote:
> On Jun 3, 8:23 pm, bmburst...@gmail.com wrote:
>> I need to match the right bracket as part of a character set.
>> I need to match all types of brackets, and so am using the
>> glob "[()[]{}]", which of course doesn't work.
> To my knowledge, this is not possible directly with glob matching.
On Jun 4, 12:37 pm, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
wrote:
> Alexandre Ferrieux <alexandre.ferri...@gmail.com> wrote:
> > On Jun 3, 8:23 pm, bmburst...@gmail.com wrote:
> >> I need to match the right bracket as part of a character set.
> >> I need to match all types of brackets, and so am using the
> >> glob "[()[]{}]", which of course doesn't work.
> > To my knowledge, this is not possible directly with glob matching.
(and the lack of special casing nor comments to that regard)
... it seems that this Day One limitation comes from the fact that
nobody cared (nor cares, to be frank) about strict compatibility with
shell globbing. In hindsight, 99% compat is okay if the 1% has a
noticeable complexity cost.
Alexandre Ferrieux <alexandre.ferri...@gmail.com> wrote:
>> FWIW, in unix-shell (bash - probably others, too):
>> $ touch 'abc[def]ghi'
>> $ echo *[]]*
>> abc[def]ghi
>> Was it an oversight in the specification of Tcl's glob, or was it
>> deliberately left out?
> From a 'fossil annotate' on tclUtil.c, function Tcl_StringCaseMatch:
> 16f0a0d493 1999-12-04 hobbs: while (1) {
> 16f0a0d493 1999-12-04 hobbs: if ((*pattern == ']') || (*pattern
>== '\0')) {
> 16f0a0d493 1999-12-04 hobbs: return 0;
> 16f0a0d493 1999-12-04 hobbs: }
> (and the lack of special casing nor comments to that regard)
> ... it seems that this Day One limitation comes from the fact that
> nobody cared (nor cares, to be frank) about strict compatibility with
> shell globbing.
I wouldn't care about []], if at least there was [\]] in glob patterns.
"Strict compatibility with shell-globbing" surely isn't all that important,
but being able to include close-brackets in character sets would be really
neat, and the implementation would be quite trivial:
change (in the quoted fossil snippet)
if ((*pattern == ']') || (*pattern == '\0')) {
to
if ( (*pattern == '\0') ||
( (*pattern == ']') && pattern > firstsetcharpos ) ) {
and set firstsetcharpos to pattern+1 where the open '[' is hit.
Actually, there is another dirty hack for the OP:
glob {*{[[{}()],]}*}
but that finds a file with both [ and ] in its name twice. ;-)
> In hindsight, 99% compat is okay if the 1% has a
> noticeable complexity cost.
Agree, but does it?
I figure you'll point out documentation now:
"A ] may be matched by including it as the first character in the set."
That's how bash describes it.