comp.lang.ada
 help / color / mirror / Atom feed
* GNAT.Regexp: Am I missing something?
@ 2001-04-20 18:04 Marc A. Criley
  2001-04-22 14:48 ` Jacob Sparre Andersen
  0 siblings, 1 reply; 5+ messages in thread
From: Marc A. Criley @ 2001-04-20 18:04 UTC (permalink / raw)


I wanted to use GNAT.Regexp to assist with some filename filtering on
Linux, and seeing the following documentation in the package spec made
me optimistic:

   --  A second kind of regular expressions is provided. This one is
more
   --  like the wild card patterns used in file names by the Unix shell
(or
   --  DOS prompt) command lines. The grammar is the following:

      <grammar provided>

Then the function that compiles the regular expression string says:

   function Compile
     (Pattern        : String;
      Glob           : Boolean := False;
      Case_Sensitive : Boolean := True)
      return           Regexp;
   --  Compiles a regular expression S. If the syntax of the given
   --  expression is invalid (does not match above grammar,
Error_In_Regexp
   --  is raised. If Glob is True, the pattern is considered as a
'globbing
   --  pattern', that is a pattern as given by the second grammar above

So, I anticipated that by doing:

   File_Regexp := Compile("*.log", Glob => True);

I would end up with a regular expression that would match filenames
ending in ".log".  However, that's not what's happening, none of my
".log" files get matched with that expression.

If I use a regular expression that leads with a character, like "l*",
that will match all filenames starting with 'l', but of course that's
not what I want.  The behavior I'm seeing with the "Glob" mode is more
like DOS wildcard file matching rather than Unix.

I know that GNAT.Regexp can work any way its creator want, but the
behavior doesn't jive with my expectations based on its documentation
claiming support for "wild card patterns used in file names by the Unix
shell".

Am I overlooking something?  I don't want "true" regular expressions,
I'm just using this to filter filenames based on a user-supplied
pattern, and their expectation would obviously be to use the
filename-matching kind of pattern.

Thanks for any assistance,

Marc



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT.Regexp: Am I missing something?
  2001-04-20 18:04 GNAT.Regexp: Am I missing something? Marc A. Criley
@ 2001-04-22 14:48 ` Jacob Sparre Andersen
  2001-04-23  5:33   ` Simon Wright
  0 siblings, 1 reply; 5+ messages in thread
From: Jacob Sparre Andersen @ 2001-04-22 14:48 UTC (permalink / raw)


Marc:

> So, I anticipated that by doing:
> 
>    File_Regexp := Compile("*.log", Glob => True);
> 
> I would end up with a regular expression that would match filenames
> ending in ".log".  However, that's not what's happening, none of my
> ".log" files get matched with that expression.

I would guess that the problem is that the function actually expects
"true" regular expressions. I.e. "^.*[.]log$" and not "*.log".

> I know that GNAT.Regexp can work any way its creator want, but the
> behavior doesn't jive with my expectations based on its documentation
> claiming support for "wild card patterns used in file names by the Unix
> shell".

Hmm??? That is something else than regular expressions. Have you
tried with "true" regular expressions.
 
> Am I overlooking something?  I don't want "true" regular expressions,
> I'm just using this to filter filenames based on a user-supplied
> pattern, and their expectation would obviously be to use the
> filename-matching kind of pattern.

Would it be problematic to substitute "." with "[.]", "?" with "."
and "*" with ".*"? Enclosed between "^" and "$" your file name
pattern should then be transformed to a regular expression with
the same effect.

Jacob
-- 
"Any, sufficiently advanced, technology is indistinguishable from magic."



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT.Regexp: Am I missing something?
  2001-04-22 14:48 ` Jacob Sparre Andersen
@ 2001-04-23  5:33   ` Simon Wright
  2001-04-23 21:42     ` Marius Amado Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Wright @ 2001-04-23  5:33 UTC (permalink / raw)


Jacob Sparre Andersen <sparre@nbi.dk> writes:

> > So, I anticipated that by doing:
> > 
> >    File_Regexp := Compile("*.log", Glob => True);
> > 
> > I would end up with a regular expression that would match filenames
> > ending in ".log".  However, that's not what's happening, none of my
> > ".log" files get matched with that expression.
> 
> I would guess that the problem is that the function actually expects
> "true" regular expressions. I.e. "^.*[.]log$" and not "*.log".

No, the clue's in the "Glob => True"; given that, the function's
expecting glob-stype regular expressions, as OP expected.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT.Regexp: Am I missing something?
  2001-04-23  5:33   ` Simon Wright
@ 2001-04-23 21:42     ` Marius Amado Alves
  2001-04-26 19:52       ` Simon Wright
  0 siblings, 1 reply; 5+ messages in thread
From: Marius Amado Alves @ 2001-04-23 21:42 UTC (permalink / raw)
  To: comp.lang.ada

> > >    File_Regexp := Compile("*.log", Glob => True);
> > > 
> > > I would end up with a regular expression that would match filenames
> > > ending in ".log".  However, that's not what's happening, none of my
> > > ".log" files get matched with that expression.
> > 
> > I would guess that the problem is that the function actually expects
> > "true" regular expressions. I.e. "^.*[.]log$" and not "*.log".
> 
> No, the clue's in the "Glob => True"; given that, the function's
> expecting glob-stype regular expressions, as OP expected.

Not clear.

The familiar types are exactly two:

  1. regular expression (perhaps of an "extended" strand like PERL's)

  2. Unix filename matching expression (with characters '*' and '?')

Please match Glob, "glob-stype", "OP" and any other strange names to the
familiar domain.

-- 
Marius Amado Alves
 alves@systran.lu
Project Tradaut-Pt
Systran Luxembourg
12, Rue de Vianden
L-2680  LUXEMBOURG
Tel 352 + 45 46 53
Fax 352 + 45 74 75
Mob 351 +939354002





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT.Regexp: Am I missing something?
  2001-04-23 21:42     ` Marius Amado Alves
@ 2001-04-26 19:52       ` Simon Wright
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Wright @ 2001-04-26 19:52 UTC (permalink / raw)


Marius Amado Alves <alves@systran.lu> writes:

> > > >    File_Regexp := Compile("*.log", Glob => True);
> > > > 
> > > > I would end up with a regular expression that would match filenames
> > > > ending in ".log".  However, that's not what's happening, none of my
> > > > ".log" files get matched with that expression.
> > > 
> > > I would guess that the problem is that the function actually expects
> > > "true" regular expressions. I.e. "^.*[.]log$" and not "*.log".
> > 
> > No, the clue's in the "Glob => True"; given that, the function's
> > expecting glob-stype regular expressions, as OP expected.
> 
> Not clear.
> 
> The familiar types are exactly two:
> 
>   1. regular expression (perhaps of an "extended" strand like PERL's)
> 
>   2. Unix filename matching expression (with characters '*' and '?')
> 
> Please match Glob, "glob-stype", "OP" and any other strange names to the
> familiar domain.

Given the context I thought they would be familiar. Sorry.

For some arcane reason, 'glob' was the word chosen by the early Unix
implementers to describe the shell style of pattern matching.

"glob-stype" is a typo for "glob-type".

OP means "original poster", ie the person who started the thread.

HTH (hope that helps)

-Simon



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-04-26 19:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-20 18:04 GNAT.Regexp: Am I missing something? Marc A. Criley
2001-04-22 14:48 ` Jacob Sparre Andersen
2001-04-23  5:33   ` Simon Wright
2001-04-23 21:42     ` Marius Amado Alves
2001-04-26 19:52       ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox