From ae110878f278d6f23f2fabca96e5a0a94a450fb4 Mon Sep 17 00:00:00 2001 From: Jan Krukowski Date: Wed, 30 Oct 2024 21:11:56 +0100 Subject: [PATCH 1/2] Added support for Swift 6 --- Package@swift-6.0.swift | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Package@swift-6.0.swift diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift new file mode 100644 index 0000000..081975c --- /dev/null +++ b/Package@swift-6.0.swift @@ -0,0 +1,29 @@ +// swift-tools-version: 6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "Jinja", + platforms: [.iOS(.v16), .macOS(.v13)], + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .library( + name: "Jinja", + targets: ["Jinja"] + ) + ], + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .target( + name: "Jinja", + path: "Sources" + ), + .testTarget( + name: "JinjaTests", + dependencies: ["Jinja"], + path: "Tests" + ) + ] +) From 170814079f11c7b1d18fac277e42cbda543ee399 Mon Sep 17 00:00:00 2001 From: Jan Krukowski Date: Thu, 31 Oct 2024 15:10:51 +0100 Subject: [PATCH 2/2] Review feedback --- Package@swift-6.0.swift | 29 ----------------------------- Sources/Lexer.swift | 16 ++++++++-------- 2 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 Package@swift-6.0.swift diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift deleted file mode 100644 index 081975c..0000000 --- a/Package@swift-6.0.swift +++ /dev/null @@ -1,29 +0,0 @@ -// swift-tools-version: 6.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "Jinja", - platforms: [.iOS(.v16), .macOS(.v13)], - products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. - .library( - name: "Jinja", - targets: ["Jinja"] - ) - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .target( - name: "Jinja", - path: "Sources" - ), - .testTarget( - name: "JinjaTests", - dependencies: ["Jinja"], - path: "Tests" - ) - ] -) diff --git a/Sources/Lexer.swift b/Sources/Lexer.swift index c96373a..35df5c7 100644 --- a/Sources/Lexer.swift +++ b/Sources/Lexer.swift @@ -141,23 +141,23 @@ func preprocess(template: String, options: PreprocessOptions = PreprocessOptions template.removeLast() } - template = template.replacing(/{#.*?#}/, with: "{##}") + template = template.replacing(#/{#.*?#}/#, with: "{##}") if options.lstripBlocks == true { - template = template.replacing(/(?m)^[ \t]*({[#%])/, with: { $0.output.1 }) + template = template.replacing(#/(?m)^[ \t]*({[#%])/#, with: { $0.output.1 }) } if options.trimBlocks == true { - template = template.replacing(/([#%]})\n/, with: { $0.output.1 }) + template = template.replacing(#/([#%]})\n/#, with: { $0.output.1 }) } return template - .replacing(/{##}/, with: "") - .replacing(/-%}\s*/, with: "%}") - .replacing(/\s*{%-/, with: "{%") - .replacing(/-}}\s*/, with: "}}") - .replacing(/\s*{{-/, with: "{{") + .replacing(#/{##}/#, with: "") + .replacing(#/-%}\s*/#, with: "%}") + .replacing(#/\s*{%-/#, with: "{%") + .replacing(#/-}}\s*/#, with: "}}") + .replacing(#/\s*{{-/#, with: "{{") } func tokenize(_ source: String, options: PreprocessOptions = PreprocessOptions()) throws -> [Token] {