From 5a8f2fb73ddafba9fdbe952385ae2676126183ae Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 2 Aug 2020 22:21:58 +0200 Subject: =?UTF-8?q?Replace=20body!=20macro=20with=20functions=20?= =?UTF-8?q?=F0=9F=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/scope.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/syntax/scope.rs') diff --git a/src/syntax/scope.rs b/src/syntax/scope.rs index d3092944..8fdad6a0 100644 --- a/src/syntax/scope.rs +++ b/src/syntax/scope.rs @@ -3,8 +3,7 @@ use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; -use crate::func::ParseFunc; -use super::parsing::CallParser; +use super::parsing::{CallParser, ParseCall}; use super::tree::DynamicNode; /// A map from identifiers to function parsers. @@ -17,7 +16,7 @@ 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: ParseFunc + DynamicNode + 'static { + where F: ParseCall + DynamicNode + 'static { Scope { parsers: HashMap::new(), fallback: make_parser::(()), @@ -31,14 +30,14 @@ impl Scope { /// Associate the given name with a type that is parseable into a function. pub fn add(&mut self, name: &str) - where F: ParseFunc + 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 `()`). - pub fn add_with_meta(&mut self, name: &str, metadata: ::Meta) - where F: ParseFunc + DynamicNode + 'static { + 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), @@ -64,8 +63,8 @@ impl Debug for Scope { } } -fn make_parser(metadata: ::Meta) -> Box -where F: ParseFunc + DynamicNode + 'static { +fn make_parser(metadata: ::Meta) -> Box +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