summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-29 20:43:36 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-29 20:43:36 +0100
commit5f4f507ecf02e580bac2d62253ebf4a6d0a44783 (patch)
tree9643562bd5216d498c19c9b8c4c19dcded36f946 /src
parent9d715fd11cd6da568129e5a3b8657b3e8f4bc37f (diff)
Make shorthand list inspectable
Diffstat (limited to 'src')
-rw-r--r--src/syntax/ast.rs60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index 1d2ebe17..1cc29b04 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -424,35 +424,41 @@ node! {
}
impl Shorthand {
+ /// A list of all shorthands.
+ pub const LIST: &[(&'static str, char)] = &[
+ ("~", '\u{00A0}'),
+ ("--", '\u{2013}'),
+ ("---", '\u{2014}'),
+ ("-?", '\u{00AD}'),
+ ("...", '…'),
+ ("*", '∗'),
+ ("!=", '≠'),
+ ("<<", '≪'),
+ ("<<<", '⋘'),
+ (">>", '≫'),
+ (">>>", '⋙'),
+ ("<=", '≤'),
+ (">=", '≥'),
+ ("<-", '←'),
+ ("->", '→'),
+ ("=>", '⇒'),
+ ("|->", '↦'),
+ ("|=>", '⤇'),
+ ("<->", '↔'),
+ ("<=>", '⇔'),
+ (":=", '≔'),
+ ("[|", '⟦'),
+ ("|]", '⟧'),
+ ("||", '‖'),
+ ];
+
/// Get the shorthanded character.
pub fn get(&self) -> char {
- match self.0.text().as_str() {
- "~" => '\u{00A0}',
- "--" => '\u{2013}',
- "---" => '\u{2014}',
- "-?" => '\u{00AD}',
- "..." => '…',
- "*" => '∗',
- "!=" => '≠',
- "<<" => '≪',
- "<<<" => '⋘',
- ">>" => '≫',
- ">>>" => '⋙',
- "<=" => '≤',
- ">=" => '≥',
- "<-" => '←',
- "->" => '→',
- "=>" => '⇒',
- "|->" => '↦',
- "|=>" => '⤇',
- "<->" => '↔',
- "<=>" => '⇔',
- ":=" => '≔',
- "[|" => '⟦',
- "|]" => '⟧',
- "||" => '‖',
- _ => char::default(),
- }
+ let text = self.0.text().as_str();
+ Self::LIST
+ .iter()
+ .find(|&&(s, _)| s == text)
+ .map_or_else(char::default, |&(_, c)| c)
}
}