From f3e461b27c70d34e12f3bcb11cc340a88fc7f102 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 15 Dec 2019 15:09:09 +0100 Subject: =?UTF-8?q?Paper=20styles=20and=20scalable+default=20margins=20?= =?UTF-8?q?=F0=9F=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/mod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/syntax') diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 57488121..bf395c2b 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -235,13 +235,17 @@ debug_display!(Expression); pub struct Ident(pub String); impl Ident { - fn new(string: String) -> ParseResult { + pub fn new(string: String) -> ParseResult { if is_identifier(&string) { Ok(Ident(string)) } else { error!("invalid identifier: `{}`", string); } } + + pub fn as_str(&self) -> &str { + self.0.as_str() + } } impl Display for Ident { @@ -317,3 +321,18 @@ impl ExpressionKind for Spanned where T: ExpressionKind { .map(|v| Spanned::new(v, span)) } } + +impl ExpressionKind for Option where T: ExpressionKind { + const NAME: &'static str = T::NAME; + + fn from_expr(expr: Spanned) -> ParseResult> { + if let Expression::Ident(ident) = &expr.v { + match ident.as_str() { + "default" | "none" => return Ok(None), + _ => {}, + } + } + + T::from_expr(expr).map(|v| Some(v)) + } +} -- cgit v1.2.3