Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitHub actions #10

Merged
merged 4 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,33 @@ on:

jobs:
build:
name: Swift ${{ matrix.swift }}
name: Swift ${{ matrix.swift }} on Xcode ${{ matrix.xcode }}
strategy:
matrix:
swift: ["5.8", "5.9", "5.10"]
include:
- swift: "5.9"
xcode: "15.2"
- swift: "5.10"
xcode: "15.2"
runs-on: macos-14

steps:
- uses: actions/checkout@v4

- name: Setup Swift
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app

Comment on lines +27 to +29
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove Select Xcode? Previously, it was needed to specify xcode for version 5.8. @DePasqualeOrg

- name: Set up Swift
uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}

- if: ${{ matrix.swift == '5.8' }}
name: Xcode Select
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
- name: Install swift-format
run: brew install swift-format

- name: Run swift-format
if: ${{ matrix.swift == '5.9' }}
run: swift-format lint --recursive . --strict

- name: Build
run: swift build -v
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/slessans/pre-commit-swift-format
rev: ""
hooks:
- id: swift-format
args: ["--configuration", ".swift-format"]
23 changes: 11 additions & 12 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"version": 1,
"indentation": {
"spaces": 4
},
"lineLength" : 120,
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeControlFlowKeywords": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
}
"version": 1,
"indentation": {
"spaces": 4
},
"lineLength": 120,
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
}
12 changes: 4 additions & 8 deletions Sources/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ class Environment {
args in
if let arg = args.first as? NumericValue {
return arg.value as! Int % 2 != 0
}
else {
} else {
throw JinjaError.runtime("Cannot apply test 'odd' to type: \(type(of:args.first))")
}
},
"even": { args in
if let arg = args.first as? NumericValue {
return arg.value as! Int % 2 == 0
}
else {
} else {
throw JinjaError.runtime("Cannot apply test 'even' to type: \(type(of:args.first))")
}
},
Expand Down Expand Up @@ -209,12 +207,10 @@ class Environment {
do {
if let value = try self.resolve(name: name).variables[name] {
return value
}
else {
} else {
return UndefinedValue()
}
}
catch {
} catch {
return UndefinedValue()
}
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ enum JinjaError: Error, LocalizedError {
case todo(String)
case syntaxNotSupported(String)

var errorDescription: String? {
switch self {
case .syntax(let message): return "Syntax error: \(message)"
case .parser(let message): return "Parser error: \(message)"
case .runtime(let message): return "Runtime error: \(message)"
case .todo(let message): return "Todo error: \(message)"
case .syntaxNotSupported(let string): return "Syntax not supported: \(string)"
var errorDescription: String? {
switch self {
case .syntax(let message): return "Syntax error: \(message)"
case .parser(let message): return "Parser error: \(message)"
case .runtime(let message): return "Runtime error: \(message)"
case .todo(let message): return "Todo error: \(message)"
case .syntaxNotSupported(let string): return "Syntax not supported: \(string)"
}
}
}
}
3 changes: 1 addition & 2 deletions Sources/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ func tokenize(_ source: String, options: PreprocessOptions = PreprocessOptions()
if type == .in, tokens.last?.type == .not {
_ = tokens.popLast()
tokens.append(Token(value: "not in", type: .notIn))
}
else {
} else {
tokens.append(Token(value: word, type: type))
}

Expand Down
15 changes: 5 additions & 10 deletions Sources/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func parse(tokens: [Token]) throws -> Program {
if let identifier = argument as? Identifier {
let value = try parseExpression()
argument = KeywordArgumentExpression(key: identifier, value: value as! Expression)
}
else {
} else {
throw JinjaError.syntax("Expected identifier for keyword argument")
}
}
Expand Down Expand Up @@ -89,8 +88,7 @@ func parse(tokens: [Token]) throws -> Program {
slices.append(nil)
current += 1
isSlice = true
}
else {
} else {
try slices.append(parseExpression())
if typeof(.colon) {
current += 1
Expand Down Expand Up @@ -131,8 +129,7 @@ func parse(tokens: [Token]) throws -> Program {
if computed {
property = try parseMemberExpressionArgumentsList()
try expect(type: .closeSquareBracket, error: "Expected closing square bracket")
}
else {
} else {
property = try parsePrimaryExpression()
if !(property is Identifier) {
throw JinjaError.syntax("Expected identifier following dot operator")
Expand Down Expand Up @@ -252,8 +249,7 @@ func parse(tokens: [Token]) throws -> Program {

if let right {
return right
}
else {
} else {
return try parseComparisonExpression()
}
}
Expand Down Expand Up @@ -345,8 +341,7 @@ func parse(tokens: [Token]) throws -> Program {
if typeof(.elseIf) {
try expect(type: .elseIf, error: "Expected elseif token")
try alternate.append(parseIfStatement())
}
else {
} else {
try expect(type: .else, error: "Expected else token")
try expect(type: .closeStatement, error: "Expected closing statement token")

Expand Down
Loading