diff options
Diffstat (limited to 'library/src/text')
| -rw-r--r-- | library/src/text/mod.rs | 2 | ||||
| -rw-r--r-- | library/src/text/symbol.rs | 35 |
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()) + } + } + } +} |
