Compare commits

...

4 Commits

Author SHA1 Message Date
Will Hawkins 1b8b505618 Testing Gitea Ubuntu Runner
Continuous Integration / Explore-Gitea-Actions (push) Successful in 25s
Continuous Integration / Library Tests (push) Has been cancelled
Continuous Integration / Library Format Tests (push) Has been cancelled
Continuous Integration / Grammar Tests (push) Failing after 5s
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 16:13:06 -04:00
Will Hawkins e4d6daa8fe Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 11:31:50 -04:00
Will Hawkins 333270deee cli: Add Initial Cli Work
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 11:31:44 -04:00
Will Hawkins 73779d8074 common, testing: Add Formatting of Error Messages
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 11:30:05 -04:00
8 changed files with 302 additions and 184 deletions
+14 -1
View File
@@ -49,4 +49,17 @@ jobs:
- run: tree-sitter generate
working-directory: ./tree-sitter-p4
- run: ./ci/format.sh
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
+10 -1
View File
@@ -1,6 +1,15 @@
{
"originHash" : "3969417c2a67000e225174da55741dc4261b615b990ae4ce381417f06c5e9099",
"originHash" : "5d36627594955e7c1e9d5ca6b02c23ee9dc8e0d4ce73dc310b34fa6d1b966434",
"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",
"kind" : "remoteSourceControl",
+17 -2
View File
@@ -5,7 +5,7 @@ import CompilerPluginSupport
import PackageDescription
let package = Package(
name: "p4rse",
name: "p4ce",
platforms: [.iOS(.v17), .macOS(.v13)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
@@ -25,12 +25,17 @@ let package = Package(
name: "P4Runtime",
targets: ["P4Runtime"]
),
.executable(
name: "p4ce",
targets: ["Cli"]
),
],
dependencies: [
.package(path: "./tree-sitter-p4"),
.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"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
],
targets: [
.macro(
@@ -73,9 +78,19 @@ let package = Package(
name: "P4Runtime",
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"],
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).
5. `documentation`: For any documentation updates.
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.
+28
View File
@@ -0,0 +1,28 @@
// 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 Common
import Darwin
@main
struct Cli: ParsableCommand {
public func run() throws {
let e = ErrorWithLocation(sourceLocation: SourceLocation(1, 5), withError: "Testing")
print(e.format())
}
}
+126
View File
@@ -0,0 +1,126 @@
// 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/>.
public struct Error: Errorable, Equatable, CustomStringConvertible {
public func format() -> String {
return self.description
}
public func msg() -> String {
return self._msg
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self, error)
}
let _msg: String
public init(withMessage msg: String) {
self._msg = msg
}
public var description: String {
return self._msg
}
}
public struct ErrorWithLocation: Errorable, Equatable, CustomStringConvertible {
let startFormat: String = "\u{1B}[31;1;4m"
let endFormat: String = "\u{1B}[0m"
public func format() -> String {
return startFormat + "\(self.location)" + endFormat + ": \(self._msg)"
}
public func msg() -> String {
return self.description
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self, error)
}
let _msg: String
let location: SourceLocation
public init(sourceLocation location: SourceLocation, withError msg: String) {
self._msg = msg
self.location = location
}
public var description: String {
return "\(self.location): \(self._msg)"
}
}
public struct Errors: Errorable, CustomStringConvertible {
public func format() -> String {
return self.description
}
public func msg() -> String {
return self.description
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self.errors + [error])
}
public var description: String {
return self.errors.map { error in
return error.msg()
}.joined(separator: ";")
}
public let errors: [any Errorable]
init(_ errors: [any Errorable]) {
self.errors = errors
}
public init(_ e1: any Errorable, _ e2: any Errorable) {
self.errors = [e1, e2]
}
}
public struct ErrorWithLabel: Errorable {
let label: String
let error: any Errorable
public init(_ label: String, _ error: any Errorable) {
self.label = label
self.error = error
}
public func format() -> String {
return self.description
}
public func msg() -> String {
return self.description
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self, error)
}
public var description: String {
return "\(self.label): \(self.error.msg())"
}
}
-108
View File
@@ -15,114 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
public struct Error: Errorable, Equatable, CustomStringConvertible {
public func format() -> String {
return self.description
}
public func msg() -> String {
return self._msg
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self, error)
}
let _msg: String
public init(withMessage msg: String) {
self._msg = msg
}
public var description: String {
return self._msg
}
}
public struct ErrorWithLocation: Errorable, Equatable, CustomStringConvertible {
public func format() -> String {
return self.description
}
public func msg() -> String {
return self.description
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self, error)
}
let _msg: String
let location: SourceLocation
public init(sourceLocation location: SourceLocation, withError msg: String) {
self._msg = msg
self.location = location
}
public var description: String {
return "\(self.location): \(self._msg)"
}
}
public struct Errors: Errorable, CustomStringConvertible {
public func format() -> String {
return self.description
}
public func msg() -> String {
return self.description
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self.errors + [error])
}
public var description: String {
return self.errors.map { error in
return error.msg()
}.joined(separator: ";")
}
public let errors: [any Errorable]
init(_ errors: [any Errorable]) {
self.errors = errors
}
public init(_ e1: any Errorable, _ e2: any Errorable) {
self.errors = [e1, e2]
}
}
public struct ErrorWithLabel: Errorable {
let label: String
let error: any Errorable
public init(_ label: String, _ error: any Errorable) {
self.label = label
self.error = error
}
public func format() -> String {
return self.description
}
public func msg() -> String {
return self.description
}
public func append(error: any Errorable) -> any Errorable {
return Errors(self, error)
}
public var description: String {
return "\(self.label): \(self.error.msg())"
}
}
public enum Result<OKT>: Equatable {
case Ok(OKT)
case Error(any Errorable)
@@ -0,0 +1,34 @@
// 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 Common
import Foundation
import Macros
import P4Runtime
import P4Lang
import SwiftTreeSitter
import Testing
import TreeSitter
import TreeSitterP4
@testable import P4Compiler
@Test func test_error_with_location_formatting() async throws {
let e = ErrorWithLocation(sourceLocation: SourceLocation(1, 5), withError: "There was an error")
print(e.format())
}