summaryrefslogtreecommitdiff
path: root/src/model/methods.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/methods.rs')
-rw-r--r--src/model/methods.rs76
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)],
_ => &[],
}
}