diff options
| author | Martin Haug <mhaug@live.de> | 2022-05-27 16:39:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-27 16:39:06 +0200 |
| commit | 73086b5a7c1b0f9f638165803c237901499adb64 (patch) | |
| tree | c120a2449aaf325cb675ea3363ee69758a734d86 /src/eval/methods.rs | |
| parent | 99cb655832161d4ebec73273a15453a8f6acc1b7 (diff) | |
| parent | 8ba11b0722599892499337b3272cec38945d11de (diff) | |
Merge pull request #71 from typst/pins
Diffstat (limited to 'src/eval/methods.rs')
| -rw-r--r-- | src/eval/methods.rs | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/eval/methods.rs b/src/eval/methods.rs index f6de614f..e8296d23 100644 --- a/src/eval/methods.rs +++ b/src/eval/methods.rs @@ -2,6 +2,7 @@ use super::{Args, Machine, Regex, StrExt, Value}; use crate::diag::{At, TypResult}; +use crate::model::{Content, Group}; use crate::syntax::Span; use crate::util::EcoString; @@ -66,18 +67,32 @@ pub fn call( _ => missing()?, }, - Value::Dyn(dynamic) => { - if let Some(regex) = dynamic.downcast::<Regex>() { - match method { - "matches" => { - Value::Bool(regex.matches(&args.expect::<EcoString>("text")?)) - } - _ => missing()?, + Value::Dyn(dynamic) => match method { + "matches" => { + if let Some(regex) = dynamic.downcast::<Regex>() { + Value::Bool(regex.matches(&args.expect::<EcoString>("text")?)) + } else { + missing()? } - } else { - missing()? } - } + "entry" => { + if let Some(group) = dynamic.downcast::<Group>() { + Value::Content(Content::Locate( + group.entry(args.expect("recipe")?, args.named("value")?), + )) + } else { + missing()? + } + } + "all" => { + if let Some(group) = dynamic.downcast::<Group>() { + Value::Content(Content::Locate(group.all(args.expect("recipe")?))) + } else { + missing()? + } + } + _ => missing()?, + }, _ => missing()?, }; |
