From 5abaac2816ec3a2b793906f25de63ced7da0f164 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Fri, 27 Mar 2026 01:42:25 -0400 Subject: [PATCH] Add Some Coding Style Guidelines Signed-off-by: Will Hawkins --- README.md | 12 ++++++++++++ Sources/P4Compiler/Expression.swift | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ec785f2..f32997a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,18 @@ With that caveat noted, building can be done with `swift build`: $ swift build ``` +### Contributing + +We would _love_ your help! Contributions are very welcome! + +#### Coding Style + +Here are the style guidelines that we are _trying_ to maintain: +- variables are in `snake_case`. +- types are in `CamelCase`. + +Of course, we want to follow the formatter, too: see [below](#checking-format). + #### Testing To run the P4RSE tests: diff --git a/Sources/P4Compiler/Expression.swift b/Sources/P4Compiler/Expression.swift index 523c872..262b23f 100644 --- a/Sources/P4Compiler/Expression.swift +++ b/Sources/P4Compiler/Expression.swift @@ -145,7 +145,7 @@ extension KeysetExpression: CompilableExpression { struct Expression { public static func Compile( - node: Node, withContext: CompilerContext + node: Node, withContext context: CompilerContext ) -> Result { #RequireNodeType( node: node, type: "expression", nice_type_name: "expression") @@ -157,17 +157,17 @@ struct Expression { // If this is a grouped expression, recurse! if expression_node.nodeType == "grouped_expression" { - return Expression.Compile(node: expression_node.child(at: 1)!, withContext: withContext) + return Expression.Compile(node: expression_node.child(at: 1)!, withContext: context) } - let localElementsParsers: [CompilableExpression.Type] = [ + let expression_parsers: [CompilableExpression.Type] = [ P4BooleanValue.self, P4StringValue.self, P4IntValue.self, TypedIdentifier.self, BinaryOperatorExpression.self, ArrayAccessExpression.self, FieldAccessExpression.self, ] - for le_parser in localElementsParsers { - switch le_parser.compile( - node: expression_node, withContext: withContext) + for candidate_expression_parser in expression_parsers { + switch candidate_expression_parser.compile( + node: expression_node, withContext: context) { case .Ok(.some(let parsed)): return .Ok(parsed) case .Error(let e): return .Error(e) @@ -181,7 +181,7 @@ struct Expression { struct LValue { public static func Compile( - node: Node, withContext: CompilerContext + node: Node, withContext context: CompilerContext ) -> Result { #RequireNodeType( node: node, type: "expression", nice_type_name: "expression") @@ -193,16 +193,16 @@ struct LValue { // If this is a grouped expression, recurse! if expression_node.nodeType == "grouped_expression" { - return LValue.Compile(node: expression_node.child(at: 1)!, withContext: withContext) + return LValue.Compile(node: expression_node.child(at: 1)!, withContext: context) } - let lvalueParsers: [CompilableLValueExpression.Type] = [ + let lvalue_parsers: [CompilableLValueExpression.Type] = [ TypedIdentifier.self, FieldAccessExpression.self, ArrayAccessExpression.self, ] - for lvalue_parser in lvalueParsers { - switch lvalue_parser.compile_as_lvalue( - node: expression_node, withContext: withContext) + for candidate_lvalue_parser in lvalue_parsers { + switch candidate_lvalue_parser.compile_as_lvalue( + node: expression_node, withContext: context) { case .Ok(.some(let parsed)): return .Ok(parsed) case .Error(let e): return .Error(e)