[m-dev.] ./2

Thomas Conway conway at cs.mu.OZ.AU
Fri Aug 11 16:31:25 AEST 2000


Hi

One of the unintended consequences of using . for qualification is that
you can't use it as a function name anymore.

Consider this case for parsing:

:- type tokens
	--->	tokens(
			curr :: int,
			max  :: int,
			text :: string
		).

:- func (char.tokens) = tokens.
:- mode ((out.out) = in) is semidet.

C.Toks = Toks0 :-
    Toks0^curr < Toks0^max,
    string__unsafe_index(Toks0^text, Toks0^curr, C),
    Toks = Toks0^curr := (Toks0^curr + 1).


skipWs -->
    ( [C], { char__is_whitespace(C) } ->
    	skipWs
    ;
    	[]
    ).

name -->
    [C], { char__is_alpha(C) }, ....

DCG expansion does exactly the right thing and inserts variables in all
the right places, and presto! you can use DCGs with complex parsing states
not just lists. (Credit for this technique to Andrew Bromage, not me - I
just think it's useful.)

-- 
 Thomas Conway              Unicode for terrorists: U+0001 300C
 <conway at cs.mu.oz.au>         "Tie his hands behind his back"
 Mercurian )O+  
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list