[m-rev.] lex and moose changed

Ralph Becket rbeck at microsoft.com
Fri Aug 3 02:55:50 AEST 2001


> From: Holger Krug [mailto:hkrug at rationalizer.com]
> Sent: 02 August 2001 17:34
> 
> On Thu, Aug 02, 2001 at 04:45:28AM -0700, Ralph Becket wrote:
> >
> > Another idea that occurs to me would be to add something like the
> > following:
> >
> > :- typeclass regexp(T) where [
> > 	func re(T) = regexp
> > ].
> >
> > A partial Mercury lexer description would then look like
> >
> > re(('#') ++ nat)                      - line number directive
> > re(('"') ++ ... ++ ('"'))             - string
> > re(lower ++ +(ident))                 - name
> 
> Wouldn't it be possible to use an operator `op/2' defined by:
> op(T,TOK) = re(T) - TOK
> and to write:
> 
> ('#') ++ nat                       op line number directive
> ('"') ++ ... ++ ('"')              op string
> lower ++ +(ident)                  op name
> 
> How to choose `op', maybe even `:-' ? (Excuse, if that's stupid, I
have
> no experience with operators in mercury.)

You could overload is/2, I suppose, but that doesn't quite sound right.
Wrapping regexps in re/1 adds very little in terms of verbiage and has
some documentation value.  It's also not used elsewhere, so there's
less opportunity for ambiguity.

> What about a function
> 
> :- func common_regexp(string) = regexp.
> :- mode common_regexp(in) = out is semidet.
> :- mode common_regexp(out) = in is det.
> 
> which converts from regular expressions as used in perl, egrep etc.
> to Lex's regexp ?

I've got something to do that hidden away.  It isn't tested,
but I'd be happy to pass it on to you.

I actually quite like the lex syntax with the typeclass extension as
I find it more readable.

NB: it occurs to me that with the extension it's cheaper to just 
write "x" for  single char regexps rather than ('x').

- Ralph
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list