From 4c63e7f92ac4aaf8627eb7427656ce9c88e3dd1e Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Fri, 13 Mar 2026 08:27:41 -0400 Subject: [PATCH] Make Formatter Happy Signed-off-by: Will Hawkins --- Sources/P4Compiler/Compiler.swift | 7 +++---- Sources/P4Compiler/Expression.swift | 29 ++++++++++++++++------------ Sources/P4Compiler/Parser.swift | 3 ++- Sources/P4Compiler/Program.swift | 3 ++- Sources/P4Compiler/Statement.swift | 5 +++-- Sources/P4Lang/Expressions.swift | 2 +- Sources/P4Runtime/Expressions.swift | 30 ++++++++++++++--------------- 7 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Sources/P4Compiler/Compiler.swift b/Sources/P4Compiler/Compiler.swift index ff50cdd..68d752a 100644 --- a/Sources/P4Compiler/Compiler.swift +++ b/Sources/P4Compiler/Compiler.swift @@ -58,7 +58,7 @@ public struct CompilerContext { /// Update a compiler context /// /// Create a new compiler context based on the current with the same types and new names. - /// + /// /// - Parameter names: a ``LexicalScopes`` with the updated names for the newly created compiler context. /// - Returns: A new compiler context based on the current with the same types and new names. public func update(newNames names: LexicalScopes) -> CompilerContext { @@ -68,12 +68,11 @@ public struct CompilerContext { /// Update a compiler context /// /// Create a new compiler context based on the current with the same names and new types. - /// + /// /// - Parameter types: a ``LexicalScopes`` with the updated types for the newly created compiler context. /// - Returns: A new compiler context based on the current with the same names and new types. public func update(newTypes types: LexicalScopes) -> CompilerContext { return CompilerContext(withNames: self.names, withTypes: types) } - -} \ No newline at end of file +} diff --git a/Sources/P4Compiler/Expression.swift b/Sources/P4Compiler/Expression.swift index 1052131..8f329a3 100644 --- a/Sources/P4Compiler/Expression.swift +++ b/Sources/P4Compiler/Expression.swift @@ -17,9 +17,9 @@ import Common import P4Lang +import P4Runtime import SwiftTreeSitter import TreeSitterP4 -import P4Runtime protocol CompilableExpression { static func compile( @@ -109,7 +109,8 @@ struct Expression { } let localElementsParsers: [CompilableExpression.Type] = [ - P4BooleanValue.self, P4StringValue.self, P4IntValue.self, TypedIdentifier.self, BinaryOperatorExpression.self + P4BooleanValue.self, P4StringValue.self, P4IntValue.self, TypedIdentifier.self, + BinaryOperatorExpression.self, ] for le_parser in localElementsParsers { @@ -250,7 +251,8 @@ extension BinaryOperatorExpression: CompilableExpression { ) -> Result<(EvaluatableExpression)?> { let expression = node.child(at: 0)! - #SkipUnlessNodeType(node: expression, type: "binaryOperatorExpression") + #SkipUnlessNodeType( + node: expression, type: "binaryOperatorExpression") var currentChildIdx = 0 var currentChildIdxSafe = 1 @@ -263,7 +265,9 @@ extension BinaryOperatorExpression: CompilableExpression { currentChild = expression.child(at: currentChildIdx) let binary_operator_expression_node = currentChild! - #RequireNodesType(nodes: binary_operator_expression_node, type: ["binaryEqualOperatorExpression"], nice_type_names: ["binary equal operator"]) + #RequireNodesType( + nodes: binary_operator_expression_node, type: ["binaryEqualOperatorExpression"], + nice_type_names: ["binary equal operator"]) if binary_operator_expression_node.childCount < currentChildIdxSafe { return Result.Error( @@ -272,20 +276,21 @@ extension BinaryOperatorExpression: CompilableExpression { currentChild = binary_operator_expression_node.child(at: currentChildIdx) let left_hand_side_raw = currentChild! - currentChildIdx = currentChildIdx + 1 - currentChildIdxSafe = currentChildIdxSafe + 1 + currentChildIdx = currentChildIdx + 1 + currentChildIdxSafe = currentChildIdxSafe + 1 if binary_operator_expression_node.childCount < currentChildIdxSafe { return Result.Error( - ErrorOnNode(node: node, withError: "Missing binary operator for binary operator expression")) + ErrorOnNode(node: node, withError: "Missing binary operator for binary operator expression") + ) } currentChild = binary_operator_expression_node.child(at: currentChildIdx) - - currentChildIdx = currentChildIdx + 1 - currentChildIdxSafe = currentChildIdxSafe + 1 + currentChildIdx = currentChildIdx + 1 + currentChildIdxSafe = currentChildIdxSafe + 1 if binary_operator_expression_node.childCount < currentChildIdxSafe { return Result.Error( - ErrorOnNode(node: node, withError: "Missing binary operator for binary operator expression")) + ErrorOnNode(node: node, withError: "Missing binary operator for binary operator expression") + ) } currentChild = binary_operator_expression_node.child(at: currentChildIdx) let right_hand_side_raw = currentChild! @@ -305,4 +310,4 @@ extension BinaryOperatorExpression: CompilableExpression { withEvaluator: ("Binary Equal", P4Boolean.create(), binary_equal_operator_evaluator), withLhs: left_hand_side, withRhs: right_hand_side)) } -} \ No newline at end of file +} diff --git a/Sources/P4Compiler/Parser.swift b/Sources/P4Compiler/Parser.swift index 17ed0ad..326b577 100644 --- a/Sources/P4Compiler/Parser.swift +++ b/Sources/P4Compiler/Parser.swift @@ -54,7 +54,8 @@ extension ParserAssignmentStatement: CompilableStatement { guard case .Ok(let lvalue_identifier) = maybe_parsed_lvalue else { return Result.Error(maybe_parsed_lvalue.error()!) } - guard case Result.Ok(let lvalue_type) = context.names.lookup(identifier: lvalue_identifier) else { + guard case Result.Ok(let lvalue_type) = context.names.lookup(identifier: lvalue_identifier) + else { return Result.Error( ErrorOnNode( node: lvalue_node, diff --git a/Sources/P4Compiler/Program.swift b/Sources/P4Compiler/Program.swift index 4b826cb..4391e1b 100644 --- a/Sources/P4Compiler/Program.swift +++ b/Sources/P4Compiler/Program.swift @@ -168,7 +168,8 @@ public struct Program { { case Result.Ok((let parser, let updated_context)): // Create a new context with the name of the parser that was just compiled in scope. - compilation_context = compilation_context.update(newNames: updated_context.names.declare(identifier: parser.name, withValue: parser)) + compilation_context = compilation_context.update( + newNames: updated_context.names.declare(identifier: parser.name, withValue: parser)) case Result.Error(let error): errors.append(error) } diff --git a/Sources/P4Compiler/Statement.swift b/Sources/P4Compiler/Statement.swift index 660655a..7fbac14 100644 --- a/Sources/P4Compiler/Statement.swift +++ b/Sources/P4Compiler/Statement.swift @@ -220,8 +220,9 @@ extension VariableDeclarationStatement: CompilableStatement { VariableDeclarationStatement( identifier: parsed_variablename, withInitializer: parsed_rvalue), // Context with updated names to include the newly declared name. - context.update(newNames: context.names.declare( - identifier: parsed_variablename, withValue: declaration_p4_type)) + context.update( + newNames: context.names.declare( + identifier: parsed_variablename, withValue: declaration_p4_type)) )) } else { diff --git a/Sources/P4Lang/Expressions.swift b/Sources/P4Lang/Expressions.swift index 6fc5c6e..b9b1691 100644 --- a/Sources/P4Lang/Expressions.swift +++ b/Sources/P4Lang/Expressions.swift @@ -71,4 +71,4 @@ public struct BinaryOperatorExpression { self.left = lhs self.right = rhs } -} \ No newline at end of file +} diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift index a55f2c4..878ec26 100644 --- a/Sources/P4Runtime/Expressions.swift +++ b/Sources/P4Runtime/Expressions.swift @@ -95,21 +95,21 @@ public func binary_equal_operator_evaluator(left: P4Value, right: P4Value) -> P4 } extension BinaryOperatorExpression: EvaluatableExpression { - public func evaluate(execution: Common.ProgramExecution) -> Common.Result { - let maybe_evaluated_left = self.left.evaluate(execution: execution) - guard case Result.Ok(let evaluated_left) = maybe_evaluated_left else { - return maybe_evaluated_left - } - - let maybe_evaluated_right = self.right.evaluate(execution: execution) - guard case Result.Ok(let evaluated_right) = maybe_evaluated_right else { - return maybe_evaluated_right - } - - return Result.Ok(self.evaluator.2(evaluated_left, evaluated_right)) + public func evaluate(execution: Common.ProgramExecution) -> Common.Result { + let maybe_evaluated_left = self.left.evaluate(execution: execution) + guard case Result.Ok(let evaluated_left) = maybe_evaluated_left else { + return maybe_evaluated_left } - public func type() -> any Common.P4Type { - return self.evaluator.1 + let maybe_evaluated_right = self.right.evaluate(execution: execution) + guard case Result.Ok(let evaluated_right) = maybe_evaluated_right else { + return maybe_evaluated_right } -} \ No newline at end of file + + return Result.Ok(self.evaluator.2(evaluated_left, evaluated_right)) + } + + public func type() -> any Common.P4Type { + return self.evaluator.1 + } +}