Skip to content

Commit 0870d21

Browse files
authored
Merge pull request #3082 from Shopify/non-ascii-identifiers
Support non-ASCII identifiers
2 parents e054ee0 + b3d16a3 commit 0870d21

11 files changed

Lines changed: 1958 additions & 1641 deletions

File tree

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/lexer.c linguist-generated

‎docs/syntax.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ _proc_ ::= `^` _parameters?_ _self-type-binding?_ _block?_ `->` _type_
4848
| `^` `(` `?` `)` `->` _type_ # Proc type with untyped parameter
4949
```
5050

51+
`\w` above, and everywhere else in this document, is `[a-zA-Z0-9_]` together
52+
with every character outside ASCII -- the same set Ruby takes into an
53+
identifier. So `ServicioÚltimaVez` is a class name and `nombre_único` is an
54+
alias name.
55+
56+
The leading character is the exception. RBS reads it to tell a class name from
57+
an interface name from an alias name, so where it makes that distinction it has
58+
to be ASCII: `class 日本語` is a class in Ruby but not a name RBS can write.
59+
Nowhere else is restricted -- a method name, a variable name, an instance
60+
variable name and a class variable name may all open with any character Ruby
61+
accepts.
62+
5163
### Class instance type
5264

5365
Class instance type denotes _an instance of a class_.

‎include/rbs/lexer.h‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ enum RBSTokenType {
7272
kRETURN, /* return */
7373
kMODULESELF, /* module-self */
7474

75-
tLIDENT, /* Identifiers starting with lower case */
76-
tUIDENT, /* Identifiers starting with upper case */
77-
tULIDENT, /* Identifiers starting with `_` followed by upper case */
78-
tULLIDENT, /* Identifiers starting with `_` followed by lower case */
79-
tGIDENT, /* Identifiers starting with `$` */
80-
tAIDENT, /* Identifiers starting with `@` */
81-
tA2IDENT, /* Identifiers starting with `@@` */
82-
tBANGIDENT, /* Identifiers ending with `!` */
83-
tEQIDENT, /* Identifiers ending with `=` */
84-
tQIDENT, /* Quoted identifier */
85-
pAREF_OPR, /* [] */
86-
tOPERATOR, /* Operator identifier */
75+
tLIDENT, /* Identifiers starting with lower case */
76+
tUIDENT, /* Identifiers starting with upper case */
77+
tULIDENT, /* Identifiers starting with `_` followed by upper case */
78+
tULLIDENT, /* Identifiers starting with `_` followed by lower case */
79+
tNONASCIIIDENT, /* Identifiers starting with a character outside ASCII */
80+
tGIDENT, /* Identifiers starting with `$` */
81+
tAIDENT, /* Identifiers starting with `@` */
82+
tA2IDENT, /* Identifiers starting with `@@` */
83+
tBANGIDENT, /* Identifiers ending with `!` */
84+
tEQIDENT, /* Identifiers ending with `=` */
85+
tQIDENT, /* Quoted identifier */
86+
pAREF_OPR, /* [] */
87+
tOPERATOR, /* Operator identifier */
8788

8889
tCOMMENT, /* Comment */
8990
tLINECOMMENT, /* Comment of all line */

0 commit comments

Comments
 (0)