Created
June 3, 2014 03:13
-
-
Save moriyoshi/b1b950b03735a70bb7a7 to your computer and use it in GitHub Desktop.
Allow symbol characters for identifier names.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 5bf1a8b3aeea src/cmd/gc/lex.c | |
--- a/src/cmd/gc/lex.c Thu May 29 13:47:31 2014 -0400 | |
+++ b/src/cmd/gc/lex.c Tue Jun 03 12:11:38 2014 +0900 | |
@@ -1309,7 +1313,7 @@ | |
ungetc(c); | |
rune = getr(); | |
// 0xb7 · is used for internal names | |
- if(!isalpharune(rune) && !isdigitrune(rune) && (importpkg == nil || rune != 0xb7)) | |
+ if(!isalpharune(rune) && !isdigitrune(rune) && !isothersymrune(rune) && (importpkg == nil || rune != 0xb7)) | |
yyerror("invalid identifier character U+%04x", rune); | |
cp += runetochar(cp, &rune); | |
} else if(!yy_isalnum(c) && c != '_') | |
diff -r 5bf1a8b3aeea src/lib9/utf/mkrunetype.c | |
--- a/src/lib9/utf/mkrunetype.c Thu May 29 13:47:31 2014 -0400 | |
+++ b/src/lib9/utf/mkrunetype.c Tue Jun 03 12:11:38 2014 +0900 | |
@@ -76,6 +76,7 @@ | |
static char myisupper[NRUNES]; | |
static char myislower[NRUNES]; | |
static char myistitle[NRUNES]; | |
+static char myisothersym[NRUNES]; | |
static int mytoupper[NRUNES]; | |
static int mytolower[NRUNES]; | |
@@ -192,6 +193,9 @@ | |
if(strcmp(p, "Nd") == 0) | |
myisdigit[code] = 1; | |
+ if(strcmp(p, "So") == 0) | |
+ myisothersym[code] = 1; | |
+ | |
/* | |
* when finding conversions, also need to mark | |
* upper/lower case, since some chars, like | |
@@ -603,6 +607,7 @@ | |
mkis("upper", myisupper, usepairs); | |
mkis("lower", myislower, usepairs); | |
mkis("title", myistitle, usepairs); | |
+ mkis("othersym", myisothersym, usepairs); | |
mkto("upper", mytoupper, usepairs); | |
mkto("lower", mytolower, usepairs); | |
diff -r 5bf1a8b3aeea src/lib9/utf/runetypebody-6.3.0.h | |
--- a/src/lib9/utf/runetypebody-6.3.0.h Thu May 29 13:47:31 2014 -0400 | |
+++ b/src/lib9/utf/runetypebody-6.3.0.h Tue Jun 03 12:11:38 2014 +0900 | |
@@ -1076,6 +1076,180 @@ | |
return 0; | |
} | |
+static Rune __isothersymr[] = { | |
+ 0x060e, 0x060f, | |
+ 0x06fd, 0x06fe, | |
+ 0x0bf3, 0x0bf8, | |
+ 0x0f01, 0x0f03, | |
+ 0x0f15, 0x0f17, | |
+ 0x0f1a, 0x0f1f, | |
+ 0x0fbe, 0x0fc5, | |
+ 0x0fc7, 0x0fcc, | |
+ 0x0fce, 0x0fcf, | |
+ 0x0fd5, 0x0fd8, | |
+ 0x109e, 0x109f, | |
+ 0x1390, 0x1399, | |
+ 0x19de, 0x19ff, | |
+ 0x1b61, 0x1b6a, | |
+ 0x1b74, 0x1b7c, | |
+ 0x2100, 0x2101, | |
+ 0x2103, 0x2106, | |
+ 0x2108, 0x2109, | |
+ 0x2116, 0x2117, | |
+ 0x211e, 0x2123, | |
+ 0x213a, 0x213b, | |
+ 0x214c, 0x214d, | |
+ 0x2195, 0x2199, | |
+ 0x219c, 0x219f, | |
+ 0x21a1, 0x21a2, | |
+ 0x21a4, 0x21a5, | |
+ 0x21a7, 0x21ad, | |
+ 0x21af, 0x21cd, | |
+ 0x21d0, 0x21d1, | |
+ 0x21d5, 0x21f3, | |
+ 0x2300, 0x2307, | |
+ 0x230c, 0x231f, | |
+ 0x2322, 0x2328, | |
+ 0x232b, 0x237b, | |
+ 0x237d, 0x239a, | |
+ 0x23b4, 0x23db, | |
+ 0x23e2, 0x23f3, | |
+ 0x2400, 0x2426, | |
+ 0x2440, 0x244a, | |
+ 0x249c, 0x24e9, | |
+ 0x2500, 0x25b6, | |
+ 0x25b8, 0x25c0, | |
+ 0x25c2, 0x25f7, | |
+ 0x2600, 0x266e, | |
+ 0x2670, 0x26ff, | |
+ 0x2701, 0x2767, | |
+ 0x2794, 0x27bf, | |
+ 0x2800, 0x28ff, | |
+ 0x2b00, 0x2b2f, | |
+ 0x2b45, 0x2b46, | |
+ 0x2b50, 0x2b59, | |
+ 0x2ce5, 0x2cea, | |
+ 0x2e80, 0x2e99, | |
+ 0x2e9b, 0x2ef3, | |
+ 0x2f00, 0x2fd5, | |
+ 0x2ff0, 0x2ffb, | |
+ 0x3012, 0x3013, | |
+ 0x3036, 0x3037, | |
+ 0x303e, 0x303f, | |
+ 0x3190, 0x3191, | |
+ 0x3196, 0x319f, | |
+ 0x31c0, 0x31e3, | |
+ 0x3200, 0x321e, | |
+ 0x322a, 0x3247, | |
+ 0x3260, 0x327f, | |
+ 0x328a, 0x32b0, | |
+ 0x32c0, 0x32fe, | |
+ 0x3300, 0x33ff, | |
+ 0x4dc0, 0x4dff, | |
+ 0xa490, 0xa4c6, | |
+ 0xa828, 0xa82b, | |
+ 0xa836, 0xa837, | |
+ 0xaa77, 0xaa79, | |
+ 0xffed, 0xffee, | |
+ 0xfffc, 0xfffd, | |
+ 0x10137, 0x1013f, | |
+ 0x10179, 0x10189, | |
+ 0x10190, 0x1019b, | |
+ 0x101d0, 0x101fc, | |
+ 0x1d000, 0x1d0f5, | |
+ 0x1d100, 0x1d126, | |
+ 0x1d129, 0x1d164, | |
+ 0x1d16a, 0x1d16c, | |
+ 0x1d183, 0x1d184, | |
+ 0x1d18c, 0x1d1a9, | |
+ 0x1d1ae, 0x1d1dd, | |
+ 0x1d200, 0x1d241, | |
+ 0x1d300, 0x1d356, | |
+ 0x1f000, 0x1f02b, | |
+ 0x1f030, 0x1f093, | |
+ 0x1f0a0, 0x1f0ae, | |
+ 0x1f0b1, 0x1f0be, | |
+ 0x1f0c1, 0x1f0cf, | |
+ 0x1f0d1, 0x1f0df, | |
+ 0x1f110, 0x1f12e, | |
+ 0x1f130, 0x1f16b, | |
+ 0x1f170, 0x1f19a, | |
+ 0x1f1e6, 0x1f202, | |
+ 0x1f210, 0x1f23a, | |
+ 0x1f240, 0x1f248, | |
+ 0x1f250, 0x1f251, | |
+ 0x1f300, 0x1f320, | |
+ 0x1f330, 0x1f335, | |
+ 0x1f337, 0x1f37c, | |
+ 0x1f380, 0x1f393, | |
+ 0x1f3a0, 0x1f3c4, | |
+ 0x1f3c6, 0x1f3ca, | |
+ 0x1f3e0, 0x1f3f0, | |
+ 0x1f400, 0x1f43e, | |
+ 0x1f442, 0x1f4f7, | |
+ 0x1f4f9, 0x1f4fc, | |
+ 0x1f500, 0x1f53d, | |
+ 0x1f540, 0x1f543, | |
+ 0x1f550, 0x1f567, | |
+ 0x1f5fb, 0x1f640, | |
+ 0x1f645, 0x1f64f, | |
+ 0x1f680, 0x1f6c5, | |
+ 0x1f700, 0x1f773, | |
+}; | |
+ | |
+static Rune __isothersymp[] = { | |
+ 0x00ae, 0x00b0, | |
+ 0x0f34, 0x0f38, | |
+ 0x2125, 0x2129, | |
+}; | |
+ | |
+static Rune __isothersyms[] = { | |
+ 0x00a6, | |
+ 0x00a9, | |
+ 0x0482, | |
+ 0x06de, | |
+ 0x06e9, | |
+ 0x07f6, | |
+ 0x09fa, | |
+ 0x0b70, | |
+ 0x0bfa, | |
+ 0x0c7f, | |
+ 0x0d79, | |
+ 0x0f13, | |
+ 0x1940, | |
+ 0x2114, | |
+ 0x212e, | |
+ 0x214a, | |
+ 0x214f, | |
+ 0x21d3, | |
+ 0x3004, | |
+ 0x3020, | |
+ 0x3250, | |
+ 0xa839, | |
+ 0xfdfd, | |
+ 0xffe4, | |
+ 0xffe8, | |
+ 0x1d245, | |
+ 0x1f440, | |
+}; | |
+ | |
+int | |
+isothersymrune(Rune c) | |
+{ | |
+ Rune *p; | |
+ | |
+ p = rbsearch(c, __isothersymr, nelem(__isothersymr)/2, 2); | |
+ if(p && c >= p[0] && c <= p[1]) | |
+ return 1; | |
+ p = rbsearch(c, __isothersymp, nelem(__isothersymp)/2, 2); | |
+ if(p && c >= p[0] && c <= p[1] && !((c - p[0]) & 1)) | |
+ return 1; | |
+ p = rbsearch(c, __isothersyms, nelem(__isothersyms), 1); | |
+ if(p && c == p[0]) | |
+ return 1; | |
+ return 0; | |
+} | |
+ | |
static Rune __toupperr[] = { | |
0x0061, 0x007a, 1048544, | |
0x00e0, 0x00f6, 1048544, | |
diff -r 5bf1a8b3aeea src/lib9/utf/utf.h | |
--- a/src/lib9/utf/utf.h Thu May 29 13:47:31 2014 -0400 | |
+++ b/src/lib9/utf/utf.h Tue Jun 03 12:11:38 2014 +0900 | |
@@ -229,6 +229,11 @@ | |
int isspacerune(Rune r); | |
+// isothersymrune tests for other symbols, including "Emoji" and other | |
+// symbol characters. | |
+ | |
+int isothersymrune(Rune r); | |
+ | |
// (The comments in this file were copied from the manpage files rune.3, | |
// isalpharune.3, and runestrcat.3. Some formatting changes were also made | |
// to conform to Google style. /JRM 11/11/05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment