Re: confused constructing a regex



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
.



Relevant Pages

  • Re: [Long, historical] Re: Var* b or Var *b
    ... I suggest that all declarations in this style come ... Another idea is a compiler warning, ... > language's grammar. ... is just inconsistent with the second definition above and the spirit ...
    (alt.comp.lang.learn.c-cpp)
  • Re: K&R2 variable definition
    ... Clausfor said: ... beginning of a compound statement. ... Now look for other places in the grammar ... where declarations *may* occur, and look at... ...
    (comp.lang.c)
  • Re: Am I a crank?
    ... even when grammatically sentences, are not declarations, and only ... delarations need be either true or false. ... If you can't figure that out for yourself, sport, you are too dim to ... Whereas you prefer to comment on grammar instead. ...
    (sci.math)