Skip to content

Commit f22c227

Browse files
author
matteo
committed
implement jinja slice step syntax
1 parent 7d3af70 commit f22c227

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

common/minja/minja.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,9 +1200,9 @@ class DictExpr : public Expression {
12001200

12011201
class SliceExpr : public Expression {
12021202
public:
1203-
std::shared_ptr<Expression> start, end;
1204-
SliceExpr(const Location & loc, std::shared_ptr<Expression> && s, std::shared_ptr<Expression> && e)
1205-
: Expression(loc), start(std::move(s)), end(std::move(e)) {}
1203+
std::shared_ptr<Expression> start, end, step;
1204+
SliceExpr(const Location & loc, std::shared_ptr<Expression> && s, std::shared_ptr<Expression> && e, std::shared_ptr<Expression> && st = nullptr)
1205+
: Expression(loc), start(std::move(s)), end(std::move(e)), step(std::move(st)) {}
12061206
Value do_evaluate(const std::shared_ptr<Context> &) const override {
12071207
throw std::runtime_error("SliceExpr not implemented");
12081208
}
@@ -2084,8 +2084,14 @@ class Parser {
20842084
if (!consumeToken("[").empty()) {
20852085
std::shared_ptr<Expression> index;
20862086
if (!consumeToken(":").empty()) {
2087-
auto slice_end = parseExpression();
2088-
index = std::make_shared<SliceExpr>(slice_end->location, nullptr, std::move(slice_end));
2087+
if (!consumeToken(":").empty()) { //case [::N]
2088+
auto step = parseExpression();
2089+
index = std::make_shared<SliceExpr>(step->location, nullptr, nullptr, std::move(step));
2090+
}
2091+
else {
2092+
auto slice_end = parseExpression();
2093+
index = std::make_shared<SliceExpr>(slice_end->location, nullptr, std::move(slice_end));
2094+
}
20892095
} else {
20902096
auto slice_start = parseExpression();
20912097
if (!consumeToken(":").empty()) {

0 commit comments

Comments
 (0)