From 1099330988da78c82c6e155fab88d81fb2f1d4c0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 6 Dec 2019 13:26:44 +0100 Subject: =?UTF-8?q?Finish=20consistent=20map=20and=20add=20two=20further?= =?UTF-8?q?=20convenience=20maps=20=F0=9F=97=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/parsing.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 8245904c..9fe6c584 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -1,7 +1,7 @@ //! Parsing of token streams into syntax trees. use crate::TypesetResult; -use crate::func::{LayoutFunc, Scope}; +use crate::func::Scope; use crate::size::Size; use super::*; @@ -104,7 +104,7 @@ impl<'s> Parser<'s> { _ => error!("expected arguments or closing bracket"), }; - let func = FuncCall(self.parse_func_call(name, args)?); + let func = self.parse_func_call(name, args)?; span.end = self.tokens.string_index(); // Finally this function is parsed to the end. @@ -132,16 +132,15 @@ impl<'s> Parser<'s> { /// Parse the arguments to a function. fn parse_func_args(&mut self) -> ParseResult { - let mut pos = Vec::new(); - let mut key = Vec::new(); + let mut args = FuncArgs::new(); loop { self.skip_white(); match self.parse_func_arg()? { - Some(DynArg::Pos(arg)) => pos.push(arg), - Some(DynArg::Key(arg)) => key.push(arg), - _ => {}, + Some(DynArg::Pos(arg)) => args.add_pos(arg), + Some(DynArg::Key(arg)) => args.add_key(arg), + None => {}, } match self.tokens.next().map(Spanned::value) { @@ -151,7 +150,7 @@ impl<'s> Parser<'s> { } } - Ok(FuncArgs { pos, key }) + Ok(args) } /// Parse one argument to a function. @@ -198,8 +197,7 @@ impl<'s> Parser<'s> { } /// Parse a function call. - fn parse_func_call(&mut self, name: Spanned, args: FuncArgs) - -> ParseResult> { + fn parse_func_call(&mut self, name: Spanned, args: FuncArgs) -> ParseResult { // Now we want to parse this function dynamically. let parser = self .ctx @@ -210,7 +208,7 @@ impl<'s> Parser<'s> { let has_body = self.tokens.peek().map(Spanned::value) == Some(Token::LeftBracket); // Do the parsing dependent on whether the function has a body. - Ok(if has_body { + Ok(FuncCall(if has_body { self.advance(); // Find out the string which makes the body of this function. @@ -235,7 +233,7 @@ impl<'s> Parser<'s> { body } else { parser(args, None, self.ctx)? - }) + })) } /// Parse an expression. -- cgit v1.2.3