From 30f16bbf6431ca0c174ca0a1abaa6a13ef50ab06 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 16 Aug 2020 22:14:27 +0200 Subject: =?UTF-8?q?Add=20Value=20type=20and=20replace=20dyn-nodes=20with?= =?UTF-8?q?=20call-exprs=20=F0=9F=8F=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - In addition to syntax trees there are now `Value`s, which syntax trees can be evaluated into (e.g. the tree is `5+5` and the value is `10`) - Parsing is completely pure, function calls are not parsed into nodes, but into simple call expressions, which are resolved later - Functions aren't dynamic nodes anymore, but simply functions which receive their arguments as a table and the layouting context - Functions may return any `Value` - Layouting is powered by functions which return the new `Commands` value, which informs the layouting engine what to do - When a function returns a non-`Commands` value, the layouter simply dumps the value into the document in monospace --- src/syntax/scope.rs | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 src/syntax/scope.rs (limited to 'src/syntax/scope.rs') diff --git a/src/syntax/scope.rs b/src/syntax/scope.rs deleted file mode 100644 index c17ff64d..00000000 --- a/src/syntax/scope.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Mapping of function names to function parsers. - -use std::collections::HashMap; -use std::fmt::{self, Debug, Formatter}; - -use super::parsing::CallParser; - -/// A map from identifiers to function parsers. -pub struct Scope { - parsers: HashMap>, - fallback: Box, -} - -impl Scope { - /// Create a new empty scope with a fallback parser that is invoked when no - /// match is found. - pub fn new(fallback: Box) -> Self { - Self { - parsers: HashMap::new(), - fallback, - } - } - - /// Associate the given function name with a dynamic node type. - pub fn insert(&mut self, name: impl Into, parser: Box) { - self.parsers.insert(name.into(), parser); - } - - /// Return the parser with the given name if there is one. - 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) -> &CallParser { - &*self.fallback - } -} - -impl Debug for Scope { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.debug_set().entries(self.parsers.keys()).finish() - } -} -- cgit v1.2.3