#9: adding character literals
-------------------------+--------------------------------------------------
Reporter: erickt | Owner:
Type: enhancement | Status: new
Priority: minor | Milestone:
Component: syntax | Version:
Keywords: |
-------------------------+--------------------------------------------------
Right now we don't have an easy way to directly create a character
literal. We have to do `char 'x'`, which is just essentially `'x'.[0]`.
Unfortunately, we're low on keywords to represent this. One option I've
run across is to do what [
http://www.bitc-lang.org/docs/bitc/spec.html
bitc] does, and use `#\`''printable-character'' as a prefix to a printable
character. For non-printable characters, they're either named:
{{{
#\space
#\linefeed
#\return
#\tab
#\backspace
#\lbrace
#\rbrace
}}}
Or you could use unicode characters via a couple mechanisms, based off of
[
http://docs.python.org/ref/strings.html python]'s string literals. First,
you can use numbers to look up the character value:
8-bit octal:
{{{
#\o77
}}}
8-bit hex:
{{{
#\xFF
}}}
16-bit hex:
{{{
#\uFFFF
}}}
32-bit hex:
{{{
#\UFFFFFFFF
}}}
Or you could use `\N{`''name''`}` to look up the unicode name in the
unicode database.
To deal with typing of the character, we'll add support to use the
coercing syntax. This would be used like this:
{{{
val x = #\a : char;
val x = #\a : wchar;
val x = #\a : uchar;
val x:char = #\a;
val x:wchar = #\a;
val x:uchar = #\a;
}}}
The compiler should detect if we're trying to coerce a character too large
to fit in the type requested. This should be a compile-time error:
{{{
val x = \u1234 : char;
}}}
--
Ticket URL: <http://code.felix-lang.org/ticket/9>
felix <http://code.felix-lang.org>
The advanced scripting language