diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-07-29 17:46:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-29 17:46:57 +0200 |
| commit | f34ba3dcda182d9b9c14cc94fdb48810bf18bef0 (patch) | |
| tree | 667a7aba2f26996c7ada8ce85952c384a1dbd5a1 /src/syntax/scope.rs | |
| parent | e7ffdde43d09f60238590723c2829554806e23d5 (diff) | |
| parent | 9672d4320052d08b67d497febed4a0ad78bf9252 (diff) | |
Merge pull request #7 from typst/parser-update
Parser update
Diffstat (limited to 'src/syntax/scope.rs')
| -rw-r--r-- | src/syntax/scope.rs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/syntax/scope.rs b/src/syntax/scope.rs index f7b20b9f..74c64280 100644 --- a/src/syntax/scope.rs +++ b/src/syntax/scope.rs @@ -5,12 +5,10 @@ use std::fmt::{self, Debug, Formatter}; use crate::Pass; use crate::func::ParseFunc; -use super::func::FuncHeader; -use super::parsing::ParseContext; -use super::span::Spanned; +use super::func::FuncCall; +use super::parsing::ParseState; use super::Model; - /// A map from identifiers to function parsers. pub struct Scope { parsers: HashMap<String, Box<Parser>>, @@ -50,10 +48,8 @@ impl Scope { } /// Return the parser with the given name if there is one. - pub fn get_parser(&self, name: &str) -> Result<&Parser, &Parser> { - self.parsers.get(name) - .map(|x| &**x) - .ok_or_else(|| &*self.fallback) + pub fn get_parser(&self, name: &str) -> Option<&Parser> { + self.parsers.get(name).map(AsRef::as_ref) } /// Return the fallback parser. @@ -72,16 +68,12 @@ impl Debug for Scope { /// A function which parses the source of a function into a model type which /// implements [`Model`]. -type Parser = dyn Fn( - FuncHeader, - Option<Spanned<&str>>, - ParseContext, -) -> Pass<Box<dyn Model>>; +type Parser = dyn Fn(FuncCall, &ParseState) -> Pass<Box<dyn Model>>; fn parser<F>(metadata: <F as ParseFunc>::Meta) -> Box<Parser> where F: ParseFunc + Model + 'static { - Box::new(move |h, b, c| { - F::parse(h, b, c, metadata.clone()) + Box::new(move |f, s| { + F::parse(f, s, metadata.clone()) .map(|model| Box::new(model) as Box<dyn Model>) }) } |
