@@ -279,9 +279,9 @@ public class P4ArrayValue: P4Value {
|
||||
return P4Array()
|
||||
}
|
||||
|
||||
let value: Array<EvaluatableExpression>
|
||||
let value: [EvaluatableExpression]
|
||||
|
||||
public init(withValue value: Array<EvaluatableExpression>) {
|
||||
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!!
|
||||
|
||||
@@ -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<Node, EvaluatableExpression?>(
|
||||
@@ -362,12 +364,14 @@ 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()!)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ public struct Program {
|
||||
return Program.Compile(source, withGlobalTypes: .none)
|
||||
}
|
||||
|
||||
public static func Compile(_ source: String, withGlobalTypes globalTypes: LexicalScopes?) -> Result<P4Lang.Program> {
|
||||
public static func Compile(
|
||||
_ source: String, withGlobalTypes globalTypes: LexicalScopes?
|
||||
) -> Result<P4Lang.Program> {
|
||||
|
||||
let maybe_parser = ConfigureP4Parser()
|
||||
guard case .Ok(let p) = maybe_parser else {
|
||||
@@ -194,7 +196,8 @@ 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
|
||||
program.types = Array(
|
||||
compilation_context.names.map { (_, v) in
|
||||
v
|
||||
})
|
||||
return Result.Ok(program)
|
||||
|
||||
@@ -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<ParserRuntime> {
|
||||
public static func create(
|
||||
program: P4Lang.Program, withInitialValues initial: ValueScopes?
|
||||
) -> Result<ParserRuntime> {
|
||||
return switch program.starting_parser() {
|
||||
case .Ok(let parser):
|
||||
.Ok(P4Runtime.ParserRuntime(parser: parser, withInitialValues: initial))
|
||||
@@ -50,7 +52,8 @@ public struct ParserRuntime: CustomStringConvertible {
|
||||
/// Run the P4 parser on a given packet
|
||||
public func run() -> Result<(ParserState, ProgramExecution)> {
|
||||
|
||||
let pe = if let initial = initialValues {
|
||||
let pe =
|
||||
if let initial = initialValues {
|
||||
ProgramExecution(withGlobalValues: initial)
|
||||
} else {
|
||||
ProgramExecution()
|
||||
|
||||
Reference in New Issue
Block a user