comp.lang.ada
 help / color / mirror / Atom feed
From: Ray Blaak <blaak@infomatch.com>
Subject: Re: Regular expressions???
Date: 29 Jun 2001 09:13:50 -0700
Date: 2001-06-29T09:13:50-07:00	[thread overview]
Message-ID: <ug0cjz2kh.fsf@infomatch.com> (raw)
In-Reply-To: 3B3C48FB.E40ECFA9@ida.his.se

Michael Andersson <michael@ida.his.se> writes:


> I'm trying to write a simple XML-parser and I wonder how regular
> expressions in Ada works. Can I use variables as in Pearl so that these
> are assigned a value according to the values found in the string. Say
> for example that I have a file looking like this:
> <Name="Michael" Phone="7980438" Age="22"/>
> I want to extract Michael, 7989438 and 22 from the string above and
> assign these to some variables. Is it possible to use regular
> expressions in Ada to do this or do I have to use procedure/functions
> from the Ada.Strings package?

For this problem, it is in fact easier and faster to parse the XML properly to
extract the relevant bits. That is, make a pseudo-state machine that looks for
<, >, =, ", />, etc, performing callbacks or inserting into an XML tree
structure when the relevant bits are recognized.

If you are going to hunt around for a RE package in Ada, you can also hunt
around for an XML package. 

Otherwise, writing an XML parser is a lot easier than writing a RE processor.

Regular expressions are often mismused where a real parser would be more
appropriate. Consider an RE that can extract bits from this line:

  <Person Name="Michael" Phone="7980438" Age="22"/>

Fine. Now, would that RE work for this:

  <Person
     Name="Michael" 
     Phone="7980438"
     Age="22"/>

or this:

  <Person Age="22" Phone="7980438" Name="Michael" />

which are both equivalent semantically?

REs work best with line oriented fix-formatted data. Free-form data tends to
break REs.

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@infomatch.com                            The Rhythm has my soul.



  parent reply	other threads:[~2001-06-29 16:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-29  9:23 Regular expressions??? Michael Andersson
2001-06-29 10:05 ` David C. Hoos, Sr.
2001-06-29 16:13 ` Ray Blaak [this message]
2001-07-02  9:54   ` M. A. Alves
2001-07-03  8:25     ` Emmanuel Briot
2001-07-04  4:53       ` Ray Blaak
2001-06-30 14:49 ` Florian Weimer
2001-06-30 20:38 ` R. Srinivasan
replies disabled

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