> no, you didn't really catch my problem. I'll try it again:

Actually I do. But thats ok.

> option : optlist(s)
> optlist: ip | pw 
> ip     : 'ipaddr' '=' value
> pw     : 'passw'  '=' value
> value  : /".*?"/
> 
> then the input:
> ipaddr = "10.0.0.1";
> passw  = "private";
> 
> or
> 
> ipaddr = "10.0.0.1";
> 
> or
> 
> passw = "private";
> 
> should succeed but not
> 
> ipaddr = "10.0.0.1";
> passw  = "private";
> ipaddr = "192.168.10.1"

Why should this _necessarily_ fail.  This could be a backup machine right?
(The point here is that you have a bunch of contextual constraints that
derive from the fact that these symbols (words) have meaning.  P::RD does
not understand meaning, all it looks for is patterns, and then translates
them into actions/data structures)

> and I see no chance to do this without {action code}.

As i said in my earlier post this is correct, but (sorry) trivial.  Modify
the sub I gave you there to suit your needs and plug it in where you need
contextual considerations.  

> It could be done with:
> 
> option : optlist(s)
> optlist: ip ^ pw 
> ip     : 'ipaddr' '=' value
> pw     : 'passw'  '=' value
> value  : /".*?"/

I dont think that this would generalize well.  Tell me what the following
should do

toplevel : rule(s)
rule     : A ^ B ^ C | A ^ C | A | B

(Dont forget that your addition to the syntax needs to handle all the cases)
> 
> that means any of the options ip or pw but not any option more than
> one time. The wish is not so strange, you will stumble over it when
> you try for example to write a parser for named or dhcp cfg files,
> and of course in my config files for network management.

I agree. The wish is not strange. It is precisely what happens when a
compiler flags a dual declaration as being incorrect.

But it also misses the point.  Its not context free and IMO not
generallizable.

But more importantly you have identified the location of the problem
incorrectly. Its not the alternation that is the problem.  Its the (s) that
is causing the trouble. It and only it are why you can have any selection of
items. Remove it and the language matched will be one or the other, but
_not_ both.

Consider how you would vocalize what you want:

I want a name and or an email, in addition to an optional phone number and
fax number

which is not 

I want a list of items that may be an email, a name a phone number or a fax
number.

which is what the rule "contact: statement(s)" means (expanding statement(s)
out).

Yves

Reply via email to