summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2020-08-31 12:11:34 +0200
committerMartin Haug <mhaug@live.de>2020-08-31 12:11:34 +0200
commitd0e252d11603d0cb3351a03b53df68542e658329 (patch)
treefff083a3f48a692e0d07ad2bc65a34e121c9208b /src/syntax
parent696560622d52e0e8c7a09df4851d25f9ea022899 (diff)
Add non-breaking space 🔒
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/parsing.rs37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index ae9cfdb1..e5873c7c 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -104,7 +104,17 @@ impl Parser<'_> {
self.with_span(SyntaxNode::Code(Code { lang, lines, block }))
}
- Token::Text(text) => self.with_span(SyntaxNode::Text(text.to_string())),
+ Token::Text(text) => {
+ let mut text_s = String::with_capacity(text.len());
+ let mut iter = text.chars();
+ while let Some(c) = iter.next() {
+ match c {
+ '~' => text_s.push('\u{00A0}'),
+ _ => text_s.push(c),
+ }
+ }
+ self.with_span(SyntaxNode::Text(text_s.to_string()))
+ },
Token::UnicodeEscape { sequence, terminated } => {
if !terminated {
@@ -1001,18 +1011,19 @@ mod tests {
#[test]
fn test_parse_simple_nodes() {
- t!("" => );
- t!("hi" => T("hi"));
- 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"]);
- t!("`hi\nyou" => R!["hi", "you"]);
- e!("`hi\nyou" => s(1,3, 1,3, "expected backtick"));
- t!("`hi\\`du`" => R!["hi`du"]);
+ t!("" => );
+ t!("hi" => T("hi"));
+ t!("*hi" => B, T("hi"));
+ t!("hi_" => T("hi"), I);
+ t!("hi you" => T("hi"), S, T("you"));
+ t!("special~name" => T("special\u{00A0}name"));
+ 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"]);
+ t!("`hi\nyou" => R!["hi", "you"]);
+ e!("`hi\nyou" => s(1,3, 1,3, "expected backtick"));
+ t!("`hi\\`du`" => R!["hi`du"]);
t!("```java System.out.print```" => C![Some("java"), "System.out.print"]);
t!("``` console.log(\n\"alert\"\n)" => C![None, "console.log(", "\"alert\"", ")"]);