From 53ca5a7fc5829d4c5b1cffc6d5a5f1706f8ec3cd Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 27 Jul 2020 13:47:29 +0200 Subject: =?UTF-8?q?Refactor=20parser=20=F0=9F=9A=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/scope.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/syntax/scope.rs') diff --git a/src/syntax/scope.rs b/src/syntax/scope.rs index f7b20b9f..74c64280 100644 --- a/src/syntax/scope.rs +++ b/src/syntax/scope.rs @@ -5,12 +5,10 @@ use std::fmt::{self, Debug, Formatter}; use crate::Pass; use crate::func::ParseFunc; -use super::func::FuncHeader; -use super::parsing::ParseContext; -use super::span::Spanned; +use super::func::FuncCall; +use super::parsing::ParseState; use super::Model; - /// A map from identifiers to function parsers. pub struct Scope { parsers: HashMap>, @@ -50,10 +48,8 @@ impl Scope { } /// Return the parser with the given name if there is one. - pub fn get_parser(&self, name: &str) -> Result<&Parser, &Parser> { - self.parsers.get(name) - .map(|x| &**x) - .ok_or_else(|| &*self.fallback) + pub fn get_parser(&self, name: &str) -> Option<&Parser> { + self.parsers.get(name).map(AsRef::as_ref) } /// Return the fallback parser. @@ -72,16 +68,12 @@ impl Debug for Scope { /// A function which parses the source of a function into a model type which /// implements [`Model`]. -type Parser = dyn Fn( - FuncHeader, - Option>, - ParseContext, -) -> Pass>; +type Parser = dyn Fn(FuncCall, &ParseState) -> Pass>; fn parser(metadata: ::Meta) -> Box where F: ParseFunc + Model + 'static { - Box::new(move |h, b, c| { - F::parse(h, b, c, metadata.clone()) + Box::new(move |f, s| { + F::parse(f, s, metadata.clone()) .map(|model| Box::new(model) as Box) }) } -- cgit v1.2.3