Skip to content

Commit

Permalink
Rename ifCondition in For to test
Browse files Browse the repository at this point in the history
  • Loading branch information
DePasqualeOrg committed Jan 14, 2025
1 parent c1a95c9 commit b2b5aa3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/Ast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct For: Statement {
var iterable: Expression
var body: [Statement]
var defaultBlock: [Statement]
var ifCondition: Expression?
var test: Expression?
}

struct MemberExpression: Expression {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,10 @@ func parse(tokens: [Token]) throws -> Program {
try expect(type: .in, error: "Expected `in` keyword following loop variable")
let iterable = try parseExpression()
// Handle optional if condition for filtering
var ifCondition: Expression? = nil
var test: Expression? = nil
if typeof(.if) {
current += 1 // consume if token
ifCondition = try parseExpression()
test = try parseExpression()
}
try expect(type: .closeStatement, error: "Expected closing statement token")
var body: [Statement] = []
Expand All @@ -530,7 +530,7 @@ func parse(tokens: [Token]) throws -> Program {
iterable: iterable,
body: body,
defaultBlock: defaultBlock,
ifCondition: ifCondition
test: test
)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ struct Interpreter {
throw JinjaError.runtime("Invalid loop variable(s): \(type(of: node.loopvar))")
}
// Evaluate the test before adding the item
if let test = test {
if let test {
try scopeUpdateFunction(loopScope)
let testValue = try self.evaluate(statement: test, environment: loopScope)
if !testValue.bool() {
Expand Down

0 comments on commit b2b5aa3

Please sign in to comment.