summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2020-08-31 12:20:45 +0200
committerMartin Haug <mhaug@live.de>2020-08-31 12:20:45 +0200
commit08433ab79fa8e775c6574b75e1e6222ecdca7ef1 (patch)
tree37917b7c01e5dea5e9ba89fc1f1fecd20a059e7b /src
parentd0e252d11603d0cb3351a03b53df68542e658329 (diff)
Capability to escape the tilde symbol 💨
Diffstat (limited to 'src')
-rw-r--r--src/syntax/parsing.rs12
-rw-r--r--src/syntax/tokens.rs2
2 files changed, 12 insertions, 2 deletions
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index e5873c7c..d48b9ff6 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -109,7 +109,16 @@ impl Parser<'_> {
let mut iter = text.chars();
while let Some(c) = iter.next() {
match c {
- '~' => text_s.push('\u{00A0}'),
+ '~' => {
+ // The escape sequence will separate
+ // the ~ into its own text node, therefore
+ // check the length here.
+ if text.len() == 1 {
+ text_s.push('~');
+ } else {
+ text_s.push('\u{00A0}');
+ }
+ },
_ => text_s.push(c),
}
}
@@ -1017,6 +1026,7 @@ mod tests {
t!("hi_" => T("hi"), I);
t!("hi you" => T("hi"), S, T("you"));
t!("special~name" => T("special\u{00A0}name"));
+ t!("special\\~name" => T("special"), T("~"), T("name"));
t!("\\u{1f303}" => T("🌃"));
t!("\n\n\nhello" => P, T("hello"));
t!(r"a\ b" => T("a"), L, S, T("b"));
diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs
index d566363c..f41babbc 100644
--- a/src/syntax/tokens.rs
+++ b/src/syntax/tokens.rs
@@ -439,7 +439,7 @@ impl<'s> Tokens<'s> {
fn read_escaped(&mut self) -> Token<'s> {
fn is_escapable(c: char) -> bool {
match c {
- '[' | ']' | '\\' | '/' | '*' | '_' | '`' | '"' => true,
+ '[' | ']' | '\\' | '/' | '*' | '_' | '`' | '"' | '~' => true,
_ => false,
}
}