71 lines
1.9 KiB
Swift
71 lines
1.9 KiB
Swift
// 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 protocol P4Type: CustomStringConvertible {
|
|
func eq(rhs: any P4Type) -> Bool
|
|
func def() -> P4DataValue?
|
|
func instantiable() -> Bool
|
|
}
|
|
|
|
extension P4Type {
|
|
public func instantiable() -> Bool {
|
|
return false
|
|
}
|
|
}
|
|
|
|
public protocol P4DataValue: CustomStringConvertible {
|
|
func type() -> any P4Type
|
|
func eq(rhs: P4DataValue) -> Bool
|
|
func lt(rhs: P4DataValue) -> Bool
|
|
func lte(rhs: P4DataValue) -> Bool
|
|
func gt(rhs: P4DataValue) -> Bool
|
|
func gte(rhs: P4DataValue) -> Bool
|
|
}
|
|
|
|
public protocol Errorable: CustomStringConvertible {
|
|
func format(_ formatter: Formattable) -> String
|
|
func format(_ formatter: Formattable, _ sc: SourceCode) -> String
|
|
func msg() -> String
|
|
func append(error: any Errorable) -> any Errorable
|
|
func eq(_ rhs: any Errorable) -> Bool
|
|
}
|
|
|
|
extension Errorable {
|
|
public func eq(_ rhs: any Errorable) -> Bool {
|
|
return self.msg() == rhs.msg()
|
|
}
|
|
public func format(_ formatter: Formattable, _ sc: SourceCode) -> String {
|
|
return self.format(formatter)
|
|
}
|
|
}
|
|
|
|
public protocol Formattable {
|
|
func formatWithStyle(_ value: String, _ style: Style) -> String
|
|
}
|
|
|
|
public protocol P4Statement {
|
|
}
|
|
|
|
public protocol P4Expression {
|
|
}
|
|
|
|
extension P4Expression {
|
|
}
|
|
|
|
extension P4Expression {
|
|
}
|