mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-17 20:31:47 +02:00
jinja : support dot property integer literals (#28817)
This commit is contained in:
@@ -842,6 +842,12 @@ value member_expression::execute_impl(context & ctx) {
|
|||||||
} else {
|
} else {
|
||||||
property = this->property->execute(ctx);
|
property = this->property->execute(ctx);
|
||||||
}
|
}
|
||||||
|
} else if (is_stmt<integer_literal>(this->property)) {
|
||||||
|
// syntax: obj.index
|
||||||
|
property = mk_val<value_int>(cast_stmt<integer_literal>(this->property)->val);
|
||||||
|
if (property->as_int() < 0) {
|
||||||
|
throw std::runtime_error("Static member property cannot be negative");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// syntax: obj.prop
|
// syntax: obj.prop
|
||||||
if (!is_stmt<identifier>(this->property)) {
|
if (!is_stmt<identifier>(this->property)) {
|
||||||
|
|||||||
@@ -398,6 +398,18 @@ static void test_expressions(testing & t) {
|
|||||||
"Bob"
|
"Bob"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_template(t, "dot notation (integer property)",
|
||||||
|
"{{ {10: 'Bob'}.10 }}",
|
||||||
|
json::object(),
|
||||||
|
"Bob"
|
||||||
|
);
|
||||||
|
|
||||||
|
test_template(t, "dot notation (array index)",
|
||||||
|
"{{ user.10 }}",
|
||||||
|
{{"user", json::array({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"})}},
|
||||||
|
"k"
|
||||||
|
);
|
||||||
|
|
||||||
test_template(t, "negative float (not dot notation)",
|
test_template(t, "negative float (not dot notation)",
|
||||||
"{{ -1.0 }}",
|
"{{ -1.0 }}",
|
||||||
json::object(),
|
json::object(),
|
||||||
|
|||||||
Reference in New Issue
Block a user