[mercury-users] Proposed change to char literal syntax

Nicholas Nethercote njn at csse.unimelb.edu.au
Thu Oct 5 08:28:14 AEST 2006


On Mon, 2 Oct 2006, Ralph Becket wrote:

> The current syntax for char literals has a number of problems and we
> would like to gauge user opinion on making a change.
>
> Currently, the syntax for a character literal is to just type the
> character as is (e.g., a, b, c), except
> - if it's also an operator name (e.g., +, *, /) in which case
>  you need to place it in parentheses (e.g., (+), (*), (/))
> - or if it's otherwise used in Merury programs (e.g., ', ", space)
>  in which case you need to place it in single quotes and possibly
>  escape it (e.g., '\'', '"', ' ')
> - or if it's a non-printable character, in which case you need to
>  quote and use a character escape sequence (e.g., '\n', '\t', '\0234').

I didn't realise all these possibilities, and I recently wrote a lexer in 
Mercury!

It seems that in general you can always put the single quotes around a 
character (eg. 'a') and it will still work, and so you can go by a simpler 
set of rules (what I've been using):

- for most chars, put single quotes around it (eg. 'a', ' ')
- some chars needs parentheses too (eg. ('%'), ('+'))
- newlines, etc, require a backslash as usual (eg. '\n')

Your suggestion about single quotes removing an operator's fixity will fix a 
lot of cases, eg. '+'.  But what about '%'?

Nick
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list