Implement Binary Operators and Grouping (in Expressions)

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-03-23 07:55:11 -04:00
parent 7c35b2b6e5
commit 2861a82777
7 changed files with 420 additions and 15 deletions
+57 -1
View File
@@ -63,6 +63,34 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible {
}
}
public func lt(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let other as ParserState: self.state < other.state
default: false
}
}
public func lte(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let other as ParserState: self.state <= other.state
default: false
}
}
public func gt(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let other as ParserState: self.state > other.state
default: false
}
}
public func gte(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let other as ParserState: self.state >= other.state
default: false
}
}
public private(set) var state: Identifier
public private(set) var statements: [EvaluatableStatement]
@@ -184,7 +212,35 @@ public struct Parser: P4Type, P4Value {
public func eq(rhs: any Common.P4Type) -> Bool {
return switch rhs {
case is Parser: true
case let parser_rhs as Parser: self.name == parser_rhs.name
default: false
}
}
public func lt(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let parser_rhs as Parser: self.name < parser_rhs.name
default: false
}
}
public func lte(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let parser_rhs as Parser: self.name <= parser_rhs.name
default: false
}
}
public func gt(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let parser_rhs as Parser: self.name > parser_rhs.name
default: false
}
}
public func gte(rhs: any Common.P4Value) -> Bool {
return switch rhs {
case let parser_rhs as Parser: self.name >= parser_rhs.name
default: false
}
}