From bbcdeb128cce04cd95714b7bc7af5a23a7e38bd2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 29 Jul 2020 18:09:51 +0200 Subject: =?UTF-8?q?Move,=20rename=20and=20switch=20some=20things=20(boring?= =?UTF-8?q?)=20=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Problems -> Diagnostics - Position -> Pos - offset_spans -> Offset trait - Size -> Length (and some more size types renamed) - Paper into its own module - scope::Parser -> parsing::CallParser - Create `Decorations` alias - Remove lots of double newlines - Switch from f32 to f64 --- src/syntax/scope.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/syntax/scope.rs') diff --git a/src/syntax/scope.rs b/src/syntax/scope.rs index 74c64280..c6350836 100644 --- a/src/syntax/scope.rs +++ b/src/syntax/scope.rs @@ -3,16 +3,14 @@ use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; -use crate::Pass; use crate::func::ParseFunc; -use super::func::FuncCall; -use super::parsing::ParseState; +use super::parsing::CallParser; use super::Model; /// A map from identifiers to function parsers. pub struct Scope { - parsers: HashMap>, - fallback: Box, + parsers: HashMap>, + fallback: Box, } impl Scope { @@ -22,7 +20,7 @@ impl Scope { where F: ParseFunc + Model + 'static { Scope { parsers: HashMap::new(), - fallback: parser::(()), + fallback: make_parser::(()), } } @@ -43,17 +41,17 @@ impl Scope { where F: ParseFunc + Model + 'static { self.parsers.insert( name.to_string(), - parser::(metadata), + make_parser::(metadata), ); } /// Return the parser with the given name if there is one. - pub fn get_parser(&self, name: &str) -> Option<&Parser> { + pub fn get_parser(&self, name: &str) -> Option<&CallParser> { self.parsers.get(name).map(AsRef::as_ref) } /// Return the fallback parser. - pub fn get_fallback_parser(&self) -> &Parser { + pub fn get_fallback_parser(&self) -> &CallParser { &*self.fallback } } @@ -66,11 +64,7 @@ impl Debug for Scope { } } -/// A function which parses the source of a function into a model type which -/// implements [`Model`]. -type Parser = dyn Fn(FuncCall, &ParseState) -> Pass>; - -fn parser(metadata: ::Meta) -> Box +fn make_parser(metadata: ::Meta) -> Box where F: ParseFunc + Model + 'static { Box::new(move |f, s| { F::parse(f, s, metadata.clone()) -- cgit v1.2.3