为什么在工具链中可以找到Regex的Swift 5.7?

发布于 2025-02-12 23:52:32 字数 899 浏览 1 评论 0原文

我相信我正在从命令行中运行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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文