[m-dev.] Comma charecter constant

Paul Bone paul at bone.id.au
Mon May 5 12:31:28 AEST 2014


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?

Thanks.


-- 
Paul Bone



More information about the developers mailing list