[m-dev.] Proposal: parsing module for the library.
Ralph Becket
rafe at csse.unimelb.edu.au
Tue Jan 27 11:30:10 AEDT 2009
Julien Fischer, Monday, 19 January 2009:
>
> On Fri, 16 Jan 2009, Ralph Becket wrote:
>
> ...
>
> > % Parse a float literal matching [-][0-9]+[.][0-9]+([Ee][-][0-9]+)?
> >+ % followed by any whitespace.
> > %
> >-:- pred float_literal(src::in)
> >- : parser(float) `with_inst` parser.
> >+:- pred float_literal(src::in, float::out,
> >+ ps::in, ps::out) is semidet.
>
> You should return the float literal as a string rather than a float.
> The implicit conversion you are preforming while parsing the float may
> not be what the user requires.
>
> >
> >- % Parse an int literal matching [-][0-9]+, not followed by [.][0-9]+.
> >+ % Parse an int literal matching [-][0-9]+, not followed by [.][0-9]+
> >+ % followed by any whitespace.
> > %
> >-:- pred int_literal(src::in)
> >- : parser(int) `with_inst` parser.
> >+:- pred int_literal(src::in, int::out,
> >+ ps::in, ps::out) is semidet.
>
> You would be better off returning ints as either strings or arbitrary
> precision integers, i.e. the integer type, rather than as machine sized
> ints.
I've amended both of these. float_literal now also returns the matched string
in case the user is concerned with the precision of string.to_float/1.
int_literal also returns the matched string and a maybe(int) result,
depending upon whether string.to_int/1 succeeds or not.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list