summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/macros.rs18
-rw-r--r--src/prelude.rs25
-rw-r--r--src/syntax/parsing.rs4
-rw-r--r--src/syntax/tokens.rs3
4 files changed, 3 insertions, 47 deletions
diff --git a/src/macros.rs b/src/macros.rs
index 2236c480..3cccfc67 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 214b00c8..7dd6be30 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<T>: 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<T> OptionExt<T> for Option<T> {
- 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 8dd567d3..65e860cf 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 a27ef982..50eea455 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,