[m-rev.] lex and moose changed

Holger Krug hkrug at rationalizer.com
Fri Aug 3 02:34:03 AEST 2001


On Thu, Aug 02, 2001 at 04:45:28AM -0700, Ralph Becket wrote:
> > From: Ralph Becket [mailto:rbeck at microsoft.com] 
> > Sent: 02 August 2001 10:41
> > 
> > While we're at it, I suggest changing the regex operator names
> > {/\, \/, star, plus, opt} to {++, or, *, +, ?} respectively.
> 
> Another idea that occurs to me would be to add something like the
> following:
> 
> :- typeclass regexp(T) where [
> 	func re(T) = regexp
> ].
> 
> Unfortunately, the wrappers would still be required for
> regexps consisting of a single char or string.  Rats.  That's
> something of a wart.  Unless all regexps are enclosed in a
> call to re/1 anyway...
> 
> A partial Mercury lexer description would then look like
> 
> re(('#') ++ nat)                      - line number directive
> re(('"') ++ ... ++ ('"'))             - string
> re(lower ++ +(ident))                 - name
> re(('''') ++ ... ++ (''''))           - quoted name
> re((upper or ('_')) ++ *(ident))      - variable
> re(nat or ...)                        - integer
> re(real)                              - float
> re((quoted) name ++ ('('))            - open_ct
> re('('))                              - open
> re(')'))                              - close
> ...

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
('''') ++ ... ++ ('''')            op quoted name
(upper or ('_')) ++ *(ident)       op variable
nat or ...                         op integer
real)                              op float
(quoted) name ++ ('(')             op open_ct
'('                                op open
')'                                op close
..
 
How to choose `op', maybe even `:-' ? (Excuse, if that's stupid, I have
no experience with operators in mercury.)

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 ?

-- 
Holger Krug
hkrug at rationalizer.com
--------------------------------------------------------------------------
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