cli: Add Initial Cli Work

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-04 11:30:27 -04:00
parent 73779d8074
commit 333270deee
4 changed files with 127 additions and 75 deletions
+10 -1
View File
@@ -1,6 +1,15 @@
{ {
"originHash" : "3969417c2a67000e225174da55741dc4261b615b990ae4ce381417f06c5e9099", "originHash" : "5d36627594955e7c1e9d5ca6b02c23ee9dc8e0d4ce73dc310b34fa6d1b966434",
"pins" : [ "pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "626b5b7b2f45e1b0b1c6f4a309296d1d21d7311b",
"version" : "1.7.1"
}
},
{ {
"identity" : "swift-docc-plugin", "identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
+89 -74
View File
@@ -5,78 +5,93 @@ import CompilerPluginSupport
import PackageDescription import PackageDescription
let package = Package( let package = Package(
name: "p4rse", name: "p4ce",
platforms: [ .iOS(.v17), .macOS(.v13)], platforms: [.iOS(.v17), .macOS(.v13)],
products: [ products: [
// Products define the executables and libraries a package produces, making them visible to other packages. // Products define the executables and libraries a package produces, making them visible to other packages.
.library( .library(
name: "P4Compiler", name: "P4Compiler",
targets: ["P4Compiler"] targets: ["P4Compiler"]
), ),
.library( .library(
name: "Common", name: "Common",
targets: ["Common"] targets: ["Common"]
), ),
.library( .library(
name: "P4Lang", name: "P4Lang",
targets: ["P4Lang"] targets: ["P4Lang"]
), ),
.library( .library(
name: "P4Runtime", name: "P4Runtime",
targets: ["P4Runtime"] targets: ["P4Runtime"]
), ),
], .executable(
dependencies: [ name: "p4ce",
.package(path: "./tree-sitter-p4"), targets: ["Cli"]
.package(url: "https://github.com/tree-sitter/swift-tree-sitter", revision: "main"), ),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ],
.package(url: "https://github.com/swiftlang/swift-syntax", from: "602.0.0"), dependencies: [
], .package(path: "./tree-sitter-p4"),
targets: [ .package(url: "https://github.com/tree-sitter/swift-tree-sitter", revision: "main"),
.macro( .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
name: "Macros", .package(url: "https://github.com/swiftlang/swift-syntax", from: "602.0.0"),
dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"), ],
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"), targets: [
], .macro(
swiftSettings: [.enableExperimentalFeature("CodeItemMacros")]), name: "Macros",
.target( dependencies: [
name: "P4Compiler", .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
dependencies: [ .product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftTreeSitter", package: "swift-tree-sitter"), ],
.product(name: "SwiftTreeSitterLayer", package: "swift-tree-sitter"), swiftSettings: [.enableExperimentalFeature("CodeItemMacros")]),
.product(name: "TreeSitterP4", package: "tree-sitter-p4"), .target(
.target(name: "TreeSitterExtensions"), name: "P4Compiler",
.target(name: "Common"), dependencies: [
.target(name: "P4Lang"), .product(name: "SwiftTreeSitter", package: "swift-tree-sitter"),
.target(name: "P4Runtime"), .product(name: "SwiftTreeSitterLayer", package: "swift-tree-sitter"),
], .product(name: "TreeSitterP4", package: "tree-sitter-p4"),
swiftSettings: [.enableExperimentalFeature("CodeItemMacros")], .target(name: "TreeSitterExtensions"),
), .target(name: "Common"),
.target( .target(name: "P4Lang"),
name: "TreeSitterExtensions", .target(name: "P4Runtime"),
dependencies: [ ],
.product(name: "SwiftTreeSitter", package: "swift-tree-sitter"), swiftSettings: [.enableExperimentalFeature("CodeItemMacros")],
.product(name: "SwiftTreeSitterLayer", package: "swift-tree-sitter"), ),
], .target(
), name: "TreeSitterExtensions",
.target( dependencies: [
name: "Common", .product(name: "SwiftTreeSitter", package: "swift-tree-sitter"),
dependencies: ["Macros"], .product(name: "SwiftTreeSitterLayer", package: "swift-tree-sitter"),
swiftSettings: [.enableExperimentalFeature("CodeItemMacros")], ],
), ),
.target( .target(
name: "P4Lang", name: "Common",
dependencies: ["Common"] dependencies: ["Macros"],
), swiftSettings: [.enableExperimentalFeature("CodeItemMacros")],
.target( ),
name: "P4Runtime", .target(
dependencies: ["P4Lang", "Common"] name: "P4Lang",
), dependencies: ["Common"]
.testTarget( ),
name: "Tests", .target(
dependencies: ["P4Compiler", "P4Runtime", "P4Lang", "Macros", "TreeSitterExtensions", "Common"], name: "P4Runtime",
swiftSettings: [.enableExperimentalFeature("CodeItemMacros")], dependencies: ["P4Lang", "Common"]
), ),
], .executableTarget(
name: "Cli",
dependencies: [
"Common", "P4Lang", "P4Compiler", "P4Runtime", "Macros",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
swiftSettings: [.enableExperimentalFeature("CodeItemMacros")],
),
.testTarget(
name: "Tests",
dependencies: [
"P4Compiler", "P4Runtime", "P4Lang", "Macros", "TreeSitterExtensions", "Common",
],
swiftSettings: [.enableExperimentalFeature("CodeItemMacros")],
),
],
) )
+1
View File
@@ -90,6 +90,7 @@ where `<component>` is one of:
4. `common`: For any Swift-based components common to the entire project (and macros). 4. `common`: For any Swift-based components common to the entire project (and macros).
5. `documentation`: For any documentation updates. 5. `documentation`: For any documentation updates.
6. `testing`: For Swift-based tests. 6. `testing`: For Swift-based tests.
7. `cli`: For Cli components.
where `<subcomponent>` can be more free-form and `<change>` is a pithy description of the changes in the commit. where `<subcomponent>` can be more free-form and `<change>` is a pithy description of the changes in the commit.
+27
View File
@@ -0,0 +1,27 @@
// p4rse, Copyright 2026, Will Hawkins
//
// This file is part of p4rse.
//
// This file is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import ArgumentParser
import Darwin
import Common
@main
struct Cli: ParsableCommand {
public func run() throws {
let e = ErrorWithLocation(sourceLocation: SourceLocation(1, 5), withError: "Testing")
print(e.format())
}
}