summaryrefslogtreecommitdiff
path: root/src/syntax/scope.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-03 16:01:23 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-03 16:04:55 +0200
commitdbfb3d2ced91e56314dfabbb4df9a338926c0a7a (patch)
tree678264cb18f8abc81ebe28077f5aef2df4e5a4bd /src/syntax/scope.rs
parent5a8f2fb73ddafba9fdbe952385ae2676126183ae (diff)
Formatting, documentation and small improvements 🧽
Diffstat (limited to 'src/syntax/scope.rs')
-rw-r--r--src/syntax/scope.rs42
1 files changed, 20 insertions, 22 deletions
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<F>() -> Scope
- where F: ParseCall<Meta=()> + DynamicNode + 'static {
- Scope {
+ pub fn new<F>() -> Self
+ where
+ F: ParseCall<Meta = ()> + DynamicNode + 'static
+ {
+ Self {
parsers: HashMap::new(),
fallback: make_parser::<F>(()),
}
}
- /// 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<F>(&mut self, name: &str)
- where F: ParseCall<Meta=()> + DynamicNode + 'static {
+ where
+ F: ParseCall<Meta = ()> + DynamicNode + 'static
+ {
self.add_with_meta::<F>(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<F>(&mut self, name: &str, metadata: <F as ParseCall>::Meta)
- where F: ParseCall + DynamicNode + 'static {
- self.parsers.insert(
- name.to_string(),
- make_parser::<F>(metadata),
- );
+ where
+ F: ParseCall + DynamicNode + 'static
+ {
+ self.parsers.insert(name.to_string(), make_parser::<F>(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<F>(metadata: <F as ParseCall>::Meta) -> Box<CallParser>
-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<dyn DynamicNode>)