diff options
| author | Martin Haug <mhaug@live.de> | 2020-08-30 13:21:07 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2020-08-30 13:21:07 +0200 |
| commit | 7041e0938dd17e9a1777857459df4e8ad29b6c4a (patch) | |
| tree | 431d3c983e70bf0a0f9fbb36796a7197f8e64861 /src/syntax/parsing.rs | |
| parent | 2a6cde72726c057e2166fb4277b8fe53c398b3f9 (diff) | |
Added Unicode Escaping for body text 👙
Diffstat (limited to 'src/syntax/parsing.rs')
| -rw-r--r-- | src/syntax/parsing.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 0d12f6e1..95c88c6e 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -110,6 +110,20 @@ impl Parser<'_> { self.with_span(SyntaxNode::Text(text.to_string())) } + Token::UnicodeEscape(ues) => { + if let Some(c) = std::char::from_u32( + u32::from_str_radix(ues, 16) + .expect("Unicode escape string not convertible to int") + ) { + let mut s = String::with_capacity(1); + s.push(c); + self.with_span(SyntaxNode::Text(s)) + } else { + error!(@self.feedback, token.span, "invalid unicode codepoint"); + self.with_span(SyntaxNode::Text("".to_string())) + } + } + unexpected => { self.eat(); error!( @@ -944,6 +958,7 @@ mod tests { t!("*hi" => B, T("hi")); t!("hi_" => T("hi"), I); t!("hi you" => T("hi"), S, T("you")); + t!("\\u{1f303}" => T("🌃")); t!("\n\n\nhello" => P, T("hello")); t!(r"a\ b" => T("a"), L, S, T("b")); t!("`py`" => R!["py"]); @@ -960,8 +975,9 @@ mod tests { t!("```typst \r\n Typst uses `\\`` to indicate code blocks" => C![ Some("typst"), " Typst uses ``` to indicate code blocks" ]); - e!("``` hi\nyou" => s(1,3, 1,3, "expected backticks")); - e!("```🌍 hi\nyou```" => s(0,3, 0,4, "invalid identifier")); + e!("``` hi\nyou" => s(1,3, 1,3, "expected backticks")); + e!("```🌍 hi\nyou```" => s(0,3, 0,4, "invalid identifier")); + e!("\\u{d421c809}" => s(0,0, 0,12, "invalid unicode codepoint")); t!("💜\n\n 🌍" => T("💜"), P, T("🌍")); ts!("hi" => s(0,0, 0,2, T("hi"))); |
