GNAT.Regexp: Am I missing something? 
Author Message
 GNAT.Regexp: Am I missing something?

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



Wed, 08 Oct 2003 02:04:43 GMT  
 GNAT.Regexp: Am I missing something?
Marc:

Quote:
> 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".

Quote:
> 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.

Quote:
> 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."



Thu, 09 Oct 2003 22:48:11 GMT  
 GNAT.Regexp: Am I missing something?

Quote:
> > 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.


Fri, 10 Oct 2003 13:33:36 GMT  
 GNAT.Regexp: Am I missing something?

Quote:
> > >    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

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



Sat, 11 Oct 2003 05:42:12 GMT  
 GNAT.Regexp: Am I missing something?

Quote:
> > > >    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



Tue, 14 Oct 2003 03:52:24 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Am i missing something with CW5Pe?

2. Am I missing something here?

3. Am I missing something here?

4. Clarion 4 Scroll Bars - Am I Missing Something

5. Am I missing something in forth!

6. Haskell: am I missing something?

7. Am I missing something?

8. re bug, or am I missing something?

9. itk::Toplevel and -menu - am I missing something

10. am i missing something ?

11. output buffering--am I missing something obvious?

12. clock scan problem, am I missing something

 

 
Powered by phpBB® Forum Software