diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-28 15:35:56 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-28 15:36:32 +0100 |
| commit | 4809e685a231a3ade2c78b75685ee859196c38c1 (patch) | |
| tree | e3141236cca536c31c6ef4a6df6d218c16ba5a94 /src/model/methods.rs | |
| parent | 28c554ec2185a15e22f0408ce485ed4afe035e03 (diff) | |
More capable math calls
Diffstat (limited to 'src/model/methods.rs')
| -rw-r--r-- | src/model/methods.rs | 76 |
1 files changed, 51 insertions, 25 deletions
diff --git a/src/model/methods.rs b/src/model/methods.rs index 1671a5c4..5da64fa2 100644 --- a/src/model/methods.rs +++ b/src/model/methods.rs @@ -107,7 +107,7 @@ pub fn call( "at" => dict.at(&args.expect::<Str>("key")?).cloned().at(span)?, "keys" => Value::Array(dict.keys()), "values" => Value::Array(dict.values()), - "pairs" => Value::Array(dict.map(vm, args.expect("function")?)?), + "pairs" => Value::Array(dict.pairs()), _ => return missing(), }, @@ -211,35 +211,61 @@ fn missing_method(type_name: &str, method: &str) -> String { format!("type {type_name} has no method `{method}`") } -/// List the available methods for a type. -pub fn methods_on(type_name: &str) -> &[&'static str] { +/// List the available methods for a type and whether they take arguments. +pub fn methods_on(type_name: &str) -> &[(&'static str, bool)] { match type_name { - "color" => &["lighten", "darken", "negate"], + "color" => &[("lighten", true), ("darken", true), ("negate", false)], "string" => &[ - "len", - "at", - "contains", - "ends-with", - "find", - "first", - "last", - "match", - "matches", - "position", - "replace", - "slice", - "split", - "starts-with", - "trim", + ("len", false), + ("at", true), + ("contains", true), + ("ends-with", true), + ("find", true), + ("first", false), + ("last", false), + ("match", true), + ("matches", true), + ("position", true), + ("replace", true), + ("slice", true), + ("split", true), + ("starts-with", true), + ("trim", true), ], "array" => &[ - "all", "any", "at", "contains", "filter", "find", "first", "flatten", "fold", - "insert", "join", "last", "len", "map", "pop", "position", "push", "remove", - "rev", "slice", "sorted", + ("all", true), + ("any", true), + ("at", true), + ("contains", true), + ("filter", true), + ("find", true), + ("first", false), + ("flatten", false), + ("fold", true), + ("insert", true), + ("join", true), + ("last", false), + ("len", false), + ("map", true), + ("pop", false), + ("position", true), + ("push", true), + ("remove", true), + ("rev", false), + ("slice", true), + ("sorted", false), ], - "dictionary" => &["at", "insert", "keys", "len", "pairs", "remove", "values"], - "function" => &["where", "with"], - "arguments" => &["named", "pos"], + "dictionary" => &[ + ("at", true), + ("insert", true), + ("keys", false), + ("len", false), + ("pairs", false), + ("remove", true), + ("values", false), + ], + "function" => &[("where", true), ("with", true)], + "arguments" => &[("named", false), ("pos", false)], _ => &[], } } |
