Re: confused constructing a regex
- From: Tad McClellan <tadmc@xxxxxxxxxxxxxx>
- Date: Wed, 1 Jun 2005 11:18:54 -0500
leeg <uk.ac.ox.physics.teaching@xxxxxxxxxxxx> wrote:
> I have an input file of a format that looks something like this:
^^^^^^^^^^^^^^
The devil is in the details with regexes, so "something like" is
likely not good enough to get a useable answer.
Can there be spaces in the already-quoted strings? Your example
has none like that.
Can declarations be broken across lines? eg:
someArray = (value1,
value2);
Can you have values on the RHS that you do NOT what to quote?
etc...
> {
> foo = (
> {
> bar = "baz";
> wibble = WOBBLE;
> },
> {
> bar = "barney";
> wibble = JELLY;
> }
> );
> someKey = someValue;
> someArray = (value1, value2);
> blankDict = {};
> };
That looks pretty Formal (as in Formal Methods).
Is it a "little language"?
If so, then find the grammar for it (or write one for it).
You might be able to get the LHS(s) handled by a simple
s/ = / => /;
and let perl autoquote for you.
You'll need to change (some of?) the parens to squares for
anonymous array elements.
> this is almost a declaration of an anonymous hash and with a little
> tweaking I could eval it as such.
> Could someone offer
> some assistance?
It would become Real Easy if you had a grammar for the data, then
you could simply write a parser for the grammar.
Got a grammar?
--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.
- Follow-Ups:
- Re: confused constructing a regex
- From: leeg
- Re: confused constructing a regex
- References:
- confused constructing a regex
- From: leeg
- confused constructing a regex
- Prev by Date: Re: Editors that use embedded Perl as their macro language?
- Next by Date: Re: Parsing Tracklisting - discussion
- Previous by thread: Re: confused constructing a regex
- Next by thread: Re: confused constructing a regex
- Index(es):
Relevant Pages
|