From 38a24247422ed433a9743e7eacf5037ccf877fa0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 18 Jul 2020 18:02:38 +0200 Subject: =?UTF-8?q?Remove=20duplicate=20spans=20for=20func=20args=20?= =?UTF-8?q?=E2=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/func/mod.rs | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/syntax/func') diff --git a/src/syntax/func/mod.rs b/src/syntax/func/mod.rs index 54d34531..fd516208 100644 --- a/src/syntax/func/mod.rs +++ b/src/syntax/func/mod.rs @@ -42,17 +42,22 @@ impl FuncArgs { } /// Add an argument. - pub fn add(&mut self, arg: FuncArg) { - match arg { - FuncArg::Pos(item) => self.pos.add(item), - FuncArg::Key(pair) => self.key.add(pair), + pub fn add(&mut self, arg: Spanned) { + match arg.v { + FuncArg::Pos(item) => self.pos.add(Spanned::new(item, arg.span)), + FuncArg::Key(pair) => self.key.add(Spanned::new(pair, arg.span)), } } /// Iterate over all arguments. - pub fn into_iter(self) -> impl Iterator { - self.pos.items.into_iter().map(|item| FuncArg::Pos(item)) - .chain(self.key.pairs.into_iter().map(|pair| FuncArg::Key(pair))) + pub fn into_iter(self) -> impl Iterator> { + let pos = self.pos.items.into_iter() + .map(|spanned| spanned.map(|item| FuncArg::Pos(item))); + + let key = self.key.pairs.into_iter() + .map(|spanned| spanned.map(|pair| FuncArg::Key(pair))); + + pos.chain(key) } } @@ -60,7 +65,7 @@ impl FromIterator> for FuncArgs { fn from_iter>>(iter: I) -> Self { let mut args = FuncArgs::new(); for item in iter.into_iter() { - args.add(item.v); + args.add(item); } args } @@ -70,22 +75,9 @@ impl FromIterator> for FuncArgs { #[derive(Debug, Clone, PartialEq)] pub enum FuncArg { /// A positional argument. - Pos(Spanned), + Pos(Expr), /// A keyword argument. - Key(Spanned), -} - -impl FuncArg { - /// The full span of this argument. - /// - /// In case of a positional argument this is just the span of the expression - /// and in case of a keyword argument the combined span of key and value. - pub fn span(&self) -> Span { - match self { - FuncArg::Pos(item) => item.span, - FuncArg::Key(item) => item.span, - } - } + Key(Pair), } /// Extra methods on [`Options`](Option) used for argument parsing. -- cgit v1.2.3