Expand description
What may spell a variable name.
A name is an identifier under UAX #31 — XID_Start then XID_Continue,
plus _ — widened with emoji, and closed against characters that do not
show themselves.
The rule behind all three parts is that a reader must be able to see what
the name is. café and 名前 are visible. 😁 is visible. A non-breaking
space is not: a\u{a0}b renders as a b and is one name that looks like
two words. A zero-width space is worse — a\u{200b}b renders as ab and is
a different variable from ab. A right-to-left override reorders the text
around it, so the source shows an order the parser does not see. Each of
those is rejected, and the error names the character.
A name that mixes scripts is a different problem: every character shows
itself, and the name still reads as something it is not. PАTH — with
CYRILLIC CAPITAL LETTER A where Latin A belongs — binds a second variable
and leaves $PATH alone. That one is a warning, not a refusal (mixed_script),
because refusing it would refuse 変数x and every other name a writing
system spells in two scripts.
Structs§
- Mixed
Script - A name spelled in more than one script, and the character that shows it.
- Name
Error - Why a name was refused, carrying the character that caused it.
Enums§
- Name
Error Kind - The class of character that made a name unreadable.
Functions§
- is_
name_ continue - May this character continue a name? Joiners are accepted here and checked
for context by
validate— a character class alone cannot see what came before it. - is_
name_ start - May this character begin a name?
- mixed_
script - Is this name spelled in more than one script?
- validate
- Check a whole name, returning the first character that makes it unreadable.