[m-dev.] Comma charecter constant
Julien Fischer
jfischer at opturion.com
Mon May 5 16:27:13 AEST 2014
On Mon, 5 May 2014, Paul Bone wrote:
>
> Hi.
>
> I've noticed that a comma character constant can sometimes confuse the
> parser.
>
> :- pred delimeter(delimeter, char).
> :- mode delimeter(in, in) is semidet.
>
> delimeter(D, C) :-
> D = d_comma,
> C = ','.
>
> :- func comma = char.
>
> comma = ','.
>
> In both these cases the character constant creates a syntax error:
>
> parse_comma_bug.m:011: Error: no clauses for predicate `delimeter'/2.
> parse_comma_bug.m:018: Syntax error at token ',': operator precedence error.
> parse_comma_bug.m:020: Error: no clauses for function `comma'/0.
> parse_comma_bug.m:022: Syntax error at token ',': operator precedence error.
>
> Replacing the comma constant with something else, eg 'x' fixes the issue. So
> does placing the constant in parens. It seems that the parser sees this as
> an unquoted comma that is part of the syntax, rather than a constant like
> any other. I beleive this is a problem, and possibly a bug, because it
> violates the rule of least surprise (I didn't expect ',' to be special).
>
> Is this something that we can feasabily avoid, or is this a pitfall of
> Mercury's Prolog-like syntax?
Potentially, and yes. See:
<http://www.mercurylang.org/list-archives/developers/1999-December/007460.html>
<http://www.mercurylang.org/list-archives/users/2006-October/003945.html>
<http://www.mercurylang.org/list-archives/users/2011-November/005482.html>
Cheers,
Julien.
More information about the developers
mailing list