From 141d69cb60d4f565f06ccd4ebeb353e748fadb7f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 19 Aug 2020 21:12:34 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20some=20obsolete=20stuff=20=E2=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/macros.rs | 18 +----------------- src/prelude.rs | 25 ------------------------- src/syntax/parsing.rs | 4 ++-- src/syntax/tokens.rs | 3 --- 4 files changed, 3 insertions(+), 47 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 2236c4806..3cccfc675 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,21 +1,5 @@ -#![allow(unused)] - -/// Unwrap the result if it is `Ok(T)` or evaluate `$or` if it is `Err(_)`. -/// This fits use cases the `?`-operator does not cover, like: -/// ``` -/// try_or!(result, continue); -/// ``` -macro_rules! try_or { - ($result:expr, $or:expr $(,)?) => { - match $result { - Ok(v) => v, - Err(_) => $or, - } - }; -} - /// Unwrap the option if it is `Some(T)` or evaluate `$or` if it is `None`. -macro_rules! try_opt_or { +macro_rules! try_or { ($option:expr, $or:expr $(,)?) => { match $option { Some(v) => v, diff --git a/src/prelude.rs b/src/prelude.rs index 214b00c8e..7dd6be30f 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -10,28 +10,3 @@ pub use crate::syntax::span::{Pos, Span, SpanVec, Spanned}; pub use crate::syntax::tree::*; pub use crate::{Pass, Feedback}; pub use super::*; - -/// Extra methods on `Option`s used for function argument parsing. -pub trait OptionExt: Sized { - /// Call `f` with `val` if this is `Some(val)`. - fn with(self, f: impl FnOnce(T)); - - /// Report an error about a missing argument with the given name and span if - /// the option is `None`. - fn or_missing(self, span: Span, arg: &str, f: &mut Feedback) -> Self; -} - -impl OptionExt for Option { - fn with(self, f: impl FnOnce(T)) { - if let Some(val) = self { - f(val); - } - } - - fn or_missing(self, span: Span, arg: &str, f: &mut Feedback) -> Self { - if self.is_none() { - error!(@f, span, "missing argument: {}", arg); - } - self - } -} diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 8dd567d35..65e860cf2 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -177,7 +177,7 @@ impl Parser<'_> { self.eat(); self.skip_white(); - (Some(ident), try_opt_or!(self.parse_expr(), { + (Some(ident), try_or!(self.parse_expr(), { self.expected("value"); continue; })) @@ -191,7 +191,7 @@ impl Parser<'_> { _ => (None, ident.map(|id| Expr::Ident(id))) } } else { - (None, try_opt_or!(self.parse_expr(), { + (None, try_or!(self.parse_expr(), { self.expected("value"); continue; })) diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs index a27ef9823..50eea4556 100644 --- a/src/syntax/tokens.rs +++ b/src/syntax/tokens.rs @@ -153,9 +153,6 @@ pub enum TokenMode { impl<'s> Tokens<'s> { /// Create a new token iterator with the given mode. - /// - /// The first token's span starts an the given `offset` position instead of - /// the zero position. pub fn new(src: &'s str, mode: TokenMode) -> Self { Self { src,