为什么在工具链中可以找到Regex的Swift 5.7?
我相信我正在从命令行中运行Swift 5.7,并且Swift 5.7应该具有新的Regex类和/... /语法。但这似乎不是。
我有以下迅速的来源“ parse.swift”。但是Swift似乎并不了解Swift 5.7 /.../语法指示正则(生成的错误,它不应该用于合法的Regex模式),因此我尝试了另一种方法,发现它无法识别新的Regex类本身。
let pattern = #"^ ,([A-Z][A-Z])([0-9][0-9]),(.*?),(.*?) "#
let regex = try! Regex(pattern)
$ swift parse.swift<某些文件
parse.swift:3:18: error: cannot find 'Regex' in scope let regex = try! Regex(pattern) ^~~~~
我需要导入或做不同的事情吗?
这是它说我正在运行的版本:
$ swift - version
Apple Swift version 5.7-dev (LLVM eecf02df5133efe, Swift ad06e7d7251311a) Target: arm64-apple-macosx12.0
我通过从〜/.zshrc导出以下内容,选择了Swift的5.7版本
export TOOLCHAINS=org.swift.57202206261a
export TOOLCHAIN_DIR=/Library/Developer/Toolchains/swift-5.7-DEVELOPMENT-SNAPSHOT-2022-06-26-a.xctoolchain
I believe I'm running Swift 5.7 from the command line, and that Swift 5.7 should have the new Regex class and /.../ syntax. But It doesn't seem to.
I have the following Swift source "parse.swift". But Swift didn't seem to understand the Swift 5.7 /.../ syntax to indicate Regex (generated errors it shouldn't for legitimate regex pattern), so I tried a different approach and discovered it doesn't recognize the new Regex class itself.
let pattern = #"^ ,([A-Z][A-Z])([0-9][0-9]),(.*?),(.*?) "#
let regex = try! Regex(pattern)
$ swift parse.swift < somefile
parse.swift:3:18: error: cannot find 'Regex' in scope let regex = try! Regex(pattern) ^~~~~
Is there something I need to import or do differently?
This is the version it says I'm running:
$ swift --version
Apple Swift version 5.7-dev (LLVM eecf02df5133efe, Swift ad06e7d7251311a) Target: arm64-apple-macosx12.0
I selected the 5.7 version of Swift by exporting the following from ~/.zshrc
export TOOLCHAINS=org.swift.57202206261a
export TOOLCHAIN_DIR=/Library/Developer/Toolchains/swift-5.7-DEVELOPMENT-SNAPSHOT-2022-06-26-a.xctoolchain
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论