From dbfb3d2ced91e56314dfabbb4df9a338926c0a7a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 3 Aug 2020 16:01:23 +0200 Subject: =?UTF-8?q?Formatting,=20documentation=20and=20small=20improvement?= =?UTF-8?q?s=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/scope.rs | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'src/syntax/scope.rs') diff --git a/src/syntax/scope.rs b/src/syntax/scope.rs index 8fdad6a0..aac2b1b8 100644 --- a/src/syntax/scope.rs +++ b/src/syntax/scope.rs @@ -1,4 +1,4 @@ -//! Scopes containing function parsers. +//! Mapping of function names to function parsers. use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; @@ -15,33 +15,31 @@ pub struct Scope { impl Scope { /// Create a new empty scope with a fallback parser that is invoked when no /// match is found. - pub fn new() -> Scope - where F: ParseCall + DynamicNode + 'static { - Scope { + pub fn new() -> Self + where + F: ParseCall + DynamicNode + 'static + { + Self { parsers: HashMap::new(), fallback: make_parser::(()), } } - /// Create a new scope with the standard functions contained. - pub fn with_std() -> Scope { - crate::library::std() - } - - /// Associate the given name with a type that is parseable into a function. + /// Associate the given function name with a dynamic node type. pub fn add(&mut self, name: &str) - where F: ParseCall + DynamicNode + 'static { + where + F: ParseCall + DynamicNode + 'static + { self.add_with_meta::(name, ()); } - /// Add a parseable type with additional metadata that is given to the - /// parser (other than the default of `()`). + /// Add a dynamic node type with additional metadata that is passed to the + /// parser. pub fn add_with_meta(&mut self, name: &str, metadata: ::Meta) - where F: ParseCall + DynamicNode + 'static { - self.parsers.insert( - name.to_string(), - make_parser::(metadata), - ); + where + F: ParseCall + DynamicNode + 'static + { + self.parsers.insert(name.to_string(), make_parser::(metadata)); } /// Return the parser with the given name if there is one. @@ -57,14 +55,14 @@ impl Scope { impl Debug for Scope { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.debug_set() - .entries(self.parsers.keys()) - .finish() + f.debug_set().entries(self.parsers.keys()).finish() } } fn make_parser(metadata: ::Meta) -> Box -where F: ParseCall + DynamicNode + 'static { +where + F: ParseCall + DynamicNode + 'static, +{ Box::new(move |f, s| { F::parse(f, s, metadata.clone()) .map(|tree| Box::new(tree) as Box) -- cgit v1.2.3