Remove some obsolete stuff

This commit is contained in:
Laurenz 2020-08-19 21:12:34 +02:00
parent fd9959fd04
commit 141d69cb60
4 changed files with 3 additions and 47 deletions

View File

@ -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`. /// 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 $(,)?) => { ($option:expr, $or:expr $(,)?) => {
match $option { match $option {
Some(v) => v, Some(v) => v,

View File

@ -10,28 +10,3 @@ pub use crate::syntax::span::{Pos, Span, SpanVec, Spanned};
pub use crate::syntax::tree::*; pub use crate::syntax::tree::*;
pub use crate::{Pass, Feedback}; pub use crate::{Pass, Feedback};
pub use super::*; 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
}
}

View File

@ -177,7 +177,7 @@ impl Parser<'_> {
self.eat(); self.eat();
self.skip_white(); self.skip_white();
(Some(ident), try_opt_or!(self.parse_expr(), { (Some(ident), try_or!(self.parse_expr(), {
self.expected("value"); self.expected("value");
continue; continue;
})) }))
@ -191,7 +191,7 @@ impl Parser<'_> {
_ => (None, ident.map(|id| Expr::Ident(id))) _ => (None, ident.map(|id| Expr::Ident(id)))
} }
} else { } else {
(None, try_opt_or!(self.parse_expr(), { (None, try_or!(self.parse_expr(), {
self.expected("value"); self.expected("value");
continue; continue;
})) }))

View File

@ -153,9 +153,6 @@ pub enum TokenMode {
impl<'s> Tokens<'s> { impl<'s> Tokens<'s> {
/// Create a new token iterator with the given mode. /// 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 { pub fn new(src: &'s str, mode: TokenMode) -> Self {
Self { Self {
src, src,