package-syntax-parser
is a temporary substitute for the proposed frontend parser for the new @package
syntax in Swift, based on SwiftSyntax
. This package is a part of Google Summer of Code 2021 project SwiftPM support for Swift scripts.
NOTE: This tool is supposed to be deprecated once the corresponding frontend implementation is available.
USAGE: package-syntax-parser <file>
ARGUMENTS:
<file>
OPTIONS:
-h, --help Show help information.
For test.swift
:
@package(url: "https://github.com/apple/swift-log.git", from: "1.0.0")
import Logging
@package(path: "swift-argument-parser")
import ArgumentParser
struct Count: ParsableCommand {
@Argument var inputFile: String
@Argument var outputFile: String
func run() throws {
let logger = Logger(label: "com.example.Script.main")
logger.info("""
Counting words in '\(inputFile)' \
and writing the result into '\(outputFile)'.
""")
// Read 'inputFile', count the words, and save to 'outputFile'.
}
}
Count.main()
The output is:
{
"dependencies" : [
{
"package" : {
"raw" : "url:\"https:\/\/github.com\/apple\/swift-log.git\",from:\"1.0.0\"",
"url" : "https:\/\/github.com\/apple\/swift-log.git"
},
"modules" : [
"Logging"
]
},
{
"package" : {
"raw" : "path:\"\/Users\/stavapple\/Developer\/swift-argument-parser\"",
"path" : "\/Users\/stavapple\/Developer\/swift-argument-parser"
},
"modules" : [
"ArgumentParser"
]
}
],
"sourceFile" : "\/Users\/stavapple\/Developer\/test.swift"
}