summaryrefslogtreecommitdiff
path: root/library/src/text
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-05 12:25:37 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-05 12:25:37 +0100
commitc2e458a133772a94009733040b39d58e781af977 (patch)
tree9404ef8f4982a068f046cb772166fdb8af7c3a0b /library/src/text
parent1d324235bd80fe8d1fb21b1e73ae9e3dfe918078 (diff)
Symbol notation
Diffstat (limited to 'library/src/text')
-rw-r--r--library/src/text/mod.rs2
-rw-r--r--library/src/text/symbol.rs35
2 files changed, 37 insertions, 0 deletions
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 47aaba36..5466637e 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -6,6 +6,7 @@ mod quotes;
mod raw;
mod shaping;
mod shift;
+mod symbol;
pub use self::deco::*;
pub use self::misc::*;
@@ -13,6 +14,7 @@ pub use self::quotes::*;
pub use self::raw::*;
pub use self::shaping::*;
pub use self::shift::*;
+pub use self::symbol::*;
use std::borrow::Cow;
diff --git a/library/src/text/symbol.rs b/library/src/text/symbol.rs
new file mode 100644
index 00000000..cc12afb9
--- /dev/null
+++ b/library/src/text/symbol.rs
@@ -0,0 +1,35 @@
+use crate::prelude::*;
+use crate::text::TextNode;
+
+/// A symbol identified by symmie notation.
+#[derive(Debug, Hash)]
+pub struct SymbolNode(pub EcoString);
+
+#[node(Show)]
+impl SymbolNode {
+ fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
+ Ok(Self(args.expect("notation")?).pack())
+ }
+
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "notation" => Some(Value::Str(self.0.clone().into())),
+ _ => None,
+ }
+ }
+}
+
+impl Show for SymbolNode {
+ fn show(&self, _: &mut Vt, this: &Content, _: StyleChain) -> SourceResult<Content> {
+ match symmie::get(&self.0) {
+ Some(c) => Ok(TextNode::packed(c)),
+ None => {
+ if let Some(span) = this.span() {
+ bail!(span, "unknown symbol");
+ }
+
+ Ok(Content::empty())
+ }
+ }
+ }
+}