Compare commits
4 Commits
3d4d26d07b
...
1b8b505618
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b8b505618 | |||
| e4d6daa8fe | |||
| 333270deee | |||
| 73779d8074 |
@@ -49,4 +49,17 @@ jobs:
|
|||||||
- run: tree-sitter generate
|
- run: tree-sitter generate
|
||||||
working-directory: ./tree-sitter-p4
|
working-directory: ./tree-sitter-p4
|
||||||
- run: ./ci/format.sh
|
- 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
@@ -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
@@ -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")],
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
|
|||||||
@@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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())"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,114 +15,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// 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 {
|
public enum Result<OKT>: Equatable {
|
||||||
case Ok(OKT)
|
case Ok(OKT)
|
||||||
case Error(any Errorable)
|
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())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user