[m-rev.] lex and moose changed

Ralph Becket rbeck at microsoft.com
Thu Aug 2 21:45:28 AEST 2001


> 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
].

:- instance regexp(char) where [
	re(C) = atom(C)
].

:- instance regexp(string) where [
	re(S) = str(S)
].

:- func T1 ++ T2 = regexp <= (regexp(T1), regexp(T2)).

R1 ++ R2 = (re(R1) >> re(R2)).

...similarly for or, +, *, ? mapping to \/, plus, star, opt
respectively.

This would allow us to avoid having to put atom(_) and str(_)
wrappers around chars and strings in compound regexps.

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
...

Any takers?

- 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