[cduce-users] default match policy not working in sequences

Alain Frisch Alain.Frisch at inria.fr
Wed Nov 3 22:03:33 CET 2004


Matthias Radestock wrote:
> [<current-state>state
> <next-state>TicketState?
> <next-days>String?
> ((<next-date>[(date::Char* 'UTC' Char*)]) | (date := "Unknown"))
> <subscription-code>subscriptionCode
> <machine-name>machineName]
>
 >which I had expected to match sequences with or without a valid 
next-date element, returning a date value of "Unknown" in the latter case.

How could this be ?  Without the specific semantics for default value 
patterns in regexp, the (date := "Unknown") would always match an 
element, even if there is not <next-date> element at all.

What's wrong with

<current-state>state
   <next-state>TicketState?
   <next-days>String?
   (<next-date>([date::Char* 'UTC' Char*] | (date := "Unknown"))
   |(date := "Unknown"))
   <subscription-code>subscriptionCode
   <machine-name>machineName]

?

Anyway, we all agree the semantic for defaut value patterns in regexps 
is problematic. I propose to use two different syntaxes for the two 
semantics (consume an element or not). Actually, I propose to add
a "guard" construction /p in regexps; the pattern p must match
the tail of the sequence, and the regexp /p itself does not consume 
anything.


So we can write:

[ (A | /(x:=1)) B ]   which accepts [ A? B ] and binds x->1 when A is 
not matched.

[ A /(x:=1) | B /(x:=2) ] which accepts [ A B ] and binds x->1 or x->2 
according to the case.

[ (x:=1) /(y:=2) ] which accepts any sequence with one element


Comments on this proposal ?


-- Alain



More information about the Cduce-users mailing list