From 75f9f683495cda2983f7434a36f80d7922d93367 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Fri, 13 Mar 2026 09:45:43 -0400 Subject: [PATCH] Make Formatter Happy Signed-off-by: Will Hawkins --- Sources/Common/ProgramTypes.swift | 6 +++--- Sources/P4Compiler/Expression.swift | 14 +++++++++----- Sources/P4Compiler/Program.swift | 11 +++++++---- Sources/P4Lang/Expressions.swift | 2 +- Sources/P4Runtime/Expressions.swift | 2 +- Sources/P4Runtime/Runtime.swift | 15 +++++++++------ 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Sources/Common/ProgramTypes.swift b/Sources/Common/ProgramTypes.swift index d033367..579d9dc 100644 --- a/Sources/Common/ProgramTypes.swift +++ b/Sources/Common/ProgramTypes.swift @@ -279,9 +279,9 @@ public class P4ArrayValue: P4Value { return P4Array() } - let value: Array + let value: [EvaluatableExpression] - public init(withValue value: Array) { + public init(withValue value: [EvaluatableExpression]) { self.value = value } @@ -290,7 +290,7 @@ public class P4ArrayValue: P4Value { } public func eq(rhs: P4Value) -> Bool { - guard let _ = rhs as? P4ArrayValue else { + guard rhs as? P4ArrayValue != nil else { return false } // TODO!! diff --git a/Sources/P4Compiler/Expression.swift b/Sources/P4Compiler/Expression.swift index 768e688..02ec29f 100644 --- a/Sources/P4Compiler/Expression.swift +++ b/Sources/P4Compiler/Expression.swift @@ -110,7 +110,7 @@ struct Expression { let localElementsParsers: [CompilableExpression.Type] = [ P4BooleanValue.self, P4StringValue.self, P4IntValue.self, TypedIdentifier.self, - BinaryOperatorExpression.self, ArrayAccessExpression.self + BinaryOperatorExpression.self, ArrayAccessExpression.self, ] for le_parser in localElementsParsers { @@ -313,7 +313,9 @@ extension BinaryOperatorExpression: CompilableExpression { } extension ArrayAccessExpression: CompilableExpression { - static func compile(node: SwiftTreeSitter.Node, withContext context: CompilerContext) -> Common.Result<(any Common.EvaluatableExpression)?> { + static func compile( + node: SwiftTreeSitter.Node, withContext context: CompilerContext + ) -> Common.Result<(any Common.EvaluatableExpression)?> { let expression = node.child(at: 0)! #SkipUnlessNodeType( @@ -362,16 +364,18 @@ extension ArrayAccessExpression: CompilableExpression { let array_access_indexor_node = currentChild! - let maybe_array_identifier = Expression.Compile(node: array_access_identifier_node, withContext: context) + let maybe_array_identifier = Expression.Compile( + node: array_access_identifier_node, withContext: context) guard case Result.Ok(let array_identifier) = maybe_array_identifier else { return Result.Error(maybe_array_identifier.error()!) } - let maybe_array_indexor = Expression.Compile(node: array_access_indexor_node, withContext: context) + let maybe_array_indexor = Expression.Compile( + node: array_access_indexor_node, withContext: context) guard case Result.Ok(let array_indexor) = maybe_array_indexor else { return Result.Error(maybe_array_indexor.error()!) } return .Ok(ArrayAccessExpression(withName: array_identifier, withIndexor: array_indexor)) } -} \ No newline at end of file +} diff --git a/Sources/P4Compiler/Program.swift b/Sources/P4Compiler/Program.swift index bc41f3c..3bc03bf 100644 --- a/Sources/P4Compiler/Program.swift +++ b/Sources/P4Compiler/Program.swift @@ -27,7 +27,9 @@ public struct Program { return Program.Compile(source, withGlobalTypes: .none) } - public static func Compile(_ source: String, withGlobalTypes globalTypes: LexicalScopes?) -> Result { + public static func Compile( + _ source: String, withGlobalTypes globalTypes: LexicalScopes? + ) -> Result { let maybe_parser = ConfigureP4Parser() guard case .Ok(let p) = maybe_parser else { @@ -194,9 +196,10 @@ public struct Program { } // Any of the types that are in the top-level scope should go into the program! - program.types = Array(compilation_context.names.map() { (_, v) in - v - }) + program.types = Array( + compilation_context.names.map { (_, v) in + v + }) return Result.Ok(program) } } diff --git a/Sources/P4Lang/Expressions.swift b/Sources/P4Lang/Expressions.swift index b880fe6..2589640 100644 --- a/Sources/P4Lang/Expressions.swift +++ b/Sources/P4Lang/Expressions.swift @@ -81,4 +81,4 @@ public struct ArrayAccessExpression { self.name = name self.indexor = indexor } -} \ No newline at end of file +} diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift index 69b92a8..de5b956 100644 --- a/Sources/P4Runtime/Expressions.swift +++ b/Sources/P4Runtime/Expressions.swift @@ -141,4 +141,4 @@ extension ArrayAccessExpression: EvaluatableExpression { public func type() -> any Common.P4Type { return P4Int.create() } -} \ No newline at end of file +} diff --git a/Sources/P4Runtime/Runtime.swift b/Sources/P4Runtime/Runtime.swift index 1f041b4..680187e 100644 --- a/Sources/P4Runtime/Runtime.swift +++ b/Sources/P4Runtime/Runtime.swift @@ -39,7 +39,9 @@ public struct ParserRuntime: CustomStringConvertible { return ParserRuntime.create(program: program, withInitialValues: .none) } - public static func create(program: P4Lang.Program, withInitialValues initial: ValueScopes?) -> Result { + public static func create( + program: P4Lang.Program, withInitialValues initial: ValueScopes? + ) -> Result { return switch program.starting_parser() { case .Ok(let parser): .Ok(P4Runtime.ParserRuntime(parser: parser, withInitialValues: initial)) @@ -50,11 +52,12 @@ public struct ParserRuntime: CustomStringConvertible { /// Run the P4 parser on a given packet public func run() -> Result<(ParserState, ProgramExecution)> { - let pe = if let initial = initialValues { - ProgramExecution(withGlobalValues: initial) - } else { - ProgramExecution() - } + let pe = + if let initial = initialValues { + ProgramExecution(withGlobalValues: initial) + } else { + ProgramExecution() + } let (end_state, execution) = parser.execute(execution: pe) if let error = execution.getError() {