Make Formatter Happy

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-03-13 08:27:41 -04:00
parent d323434787
commit 4c63e7f92a
7 changed files with 43 additions and 36 deletions
+3 -4
View File
@@ -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)
}
}
}
+17 -12
View File
@@ -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, EvaluatableExpression?>(node: expression, type: "binaryOperatorExpression")
#SkipUnlessNodeType<Node, EvaluatableExpression?>(
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<Node, EvaluatableExpression?>(nodes: binary_operator_expression_node, type: ["binaryEqualOperatorExpression"], nice_type_names: ["binary equal operator"])
#RequireNodesType<Node, EvaluatableExpression?>(
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))
}
}
}
+2 -1
View File
@@ -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,
+2 -1
View File
@@ -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)
}
+3 -2
View File
@@ -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 {