diff --git a/README.md b/README.md index 09570ad..2c51382 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ $ make repl - arithmetic expressions - built-in functions - first-class and higher-order functions • closures -- Unicode identifiers (UAX #31, XID). No Emojis yet. +- Unicode identifiers (UAX #31, XID) plus monetary extensions (`[¥$_]`). No Emojis yet. - Full double-quoted string syntax from Rust-lang. - Ridiculous naming for the Aba-aba. Comparison with Monkey: diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 3adcb43..20d72c9 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -48,27 +48,25 @@ pub fn is_whitespace(c: char) -> bool { } /// True if `c` is valid as a first character of an identifier. -/// See [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html) for -/// a formal definition of valid identifier name. +/// Compared to Rust, we additionally allow $ and ¥. fn is_id_start(c: char) -> bool { - // This is XID_Start OR '_' (which formally is not a XID_Start). - // We also add fast-path for ascii idents ('a'..='z').contains(&c) || ('A'..='Z').contains(&c) || c == '_' + || c == '$' + || c == '¥' || (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c)) } /// True if `c` is valid as a non-first character of an identifier. -/// See [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html) for -/// a formal definition of valid identifier name. +/// Compared to Rust, we additionally allow $ and ¥. fn is_id_continue(c: char) -> bool { - // This is exactly XID_Continue. - // We also add fast-path for ascii idents ('a'..='z').contains(&c) || ('A'..='Z').contains(&c) || ('0'..='9').contains(&c) || c == '_' + || c == '$' + || c == '¥' || (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c)) } diff --git a/web/src/js/editor/monkey-mode.js b/web/src/js/editor/monkey-mode.js index d70cff1..afb78fc 100644 --- a/web/src/js/editor/monkey-mode.js +++ b/web/src/js/editor/monkey-mode.js @@ -16,7 +16,7 @@ CodeMirror.defineSimpleMode('monkey', { { regex: /[-+\/*=<>!]|对齐|联动|差异|倾斜/, token: 'operator' }, { regex: /[\{\[\(]/, indent: true }, { regex: /[\}\]\)]/, dedent: true }, - { regex: /\p{XID_Start}\p{XID_Continue}*|[a-z$][\w$]*/u, token: 'variable' }, + { regex: /[\p{XID_Start}$¥_][\p{XID_Continue}$¥]*/u, token: 'variable' }, ], comment: [], meta: {},