Skip to content

Commit 1872b6e

Browse files
committed
Support non-ascii identifiers
1 parent 24e47b1 commit 1872b6e

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

macros/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ stylish-style.default-features = false
2525
stylish-style.features = ["alloc"]
2626
stylish-style.version = "=0.1.0"
2727
stylish-style.path = "../style"
28+
unicode-ident.default-features = false
29+
unicode-ident.version = "1.0.3"
2830

2931
[package.metadata.docs.rs]
3032
all-features = true

macros/src/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::str::FromStr;
33
use nom::{
44
branch::alt,
55
bytes::complete::tag,
6-
character::complete::{alpha1, alphanumeric1, anychar, digit1, none_of},
6+
character::complete::{anychar, char, digit1, none_of, satisfy},
77
combinator::{all_consuming, cut, map, map_res, opt, recognize, value},
88
multi::{many0, many1, separated_list0},
99
sequence::{delimited, pair, preceded, terminated},
@@ -13,8 +13,8 @@ use stylish_style::{Background, Color, Foreground, Intensity, Restyle, Style, St
1313

1414
fn identifier(input: &str) -> IResult<&str, &str> {
1515
recognize(pair(
16-
alt((alpha1, tag("_"))),
17-
many0(alt((alphanumeric1, tag("_")))),
16+
alt((satisfy(unicode_ident::is_xid_start), char('_'))),
17+
many0(satisfy(unicode_ident::is_xid_continue)),
1818
))(input)
1919
}
2020

tests/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(uncommon_codepoints)]
2+
13
#[cfg(not(feature = "_tests"))]
24
compile_error!("please test with --all-features");
35

@@ -183,6 +185,14 @@ mod tests {
183185
);
184186
}
185187

188+
#[test]
189+
fn non_ascii_idents() {
190+
let 𓀄 = 5;
191+
assert_eq!(stylish::plain::format!("{𓀄}"), "5");
192+
assert_eq!(stylish::plain::format!("{}", 𓀄), "5");
193+
assert_eq!(stylish::plain::format!("{𓀄}", 𓀄 = 5), "5");
194+
}
195+
186196
#[cfg(stylish_proc_macro_expand)]
187197
#[test]
188198
fn extended_builtin_macros() {

0 commit comments

Comments
 (0)