@@ -51,27 +51,27 @@ extension SelectExpression: EvaluatableExpression {
|
||||
}
|
||||
|
||||
extension P4StringValue: EvaluatableExpression {
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension P4BooleanValue: EvaluatableExpression {
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension P4StructValue: EvaluatableExpression {
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension P4IntValue: EvaluatableExpression {
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
|
||||
return .Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
// Variables are evaluatable because they can be looked up by identifiers.
|
||||
@@ -83,4 +83,4 @@ extension TypedIdentifier: EvaluatableExpression {
|
||||
public func evaluate(execution: Common.ProgramExecution) -> Result<P4Value> {
|
||||
return execution.scopes.lookup(identifier: self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,7 @@ public struct ParserStateDirectTransition: ParserStateInstance {
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
get {
|
||||
return "Instance of \(currrent_state)"
|
||||
}
|
||||
return "Instance of \(currrent_state)"
|
||||
}
|
||||
|
||||
public let currrent_state: ParserState
|
||||
@@ -71,7 +69,7 @@ public struct ParserStateDirectTransition: ParserStateInstance {
|
||||
}
|
||||
|
||||
program = program.setError(error: res.error()!).exit_scope()
|
||||
|
||||
|
||||
return (self, program.exit_scope())
|
||||
}
|
||||
|
||||
@@ -99,9 +97,7 @@ public struct ParserStateNoTransition: ParserStateInstance {
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
get {
|
||||
return "Instance of \(currrent_state)"
|
||||
}
|
||||
return "Instance of \(currrent_state)"
|
||||
}
|
||||
|
||||
public let currrent_state: ParserState
|
||||
@@ -134,9 +130,7 @@ public struct ParserStateSelectTransition: ParserStateInstance {
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
get {
|
||||
return "Instance of \(currrent_state)"
|
||||
}
|
||||
return "Instance of \(currrent_state)"
|
||||
}
|
||||
|
||||
public func execute(
|
||||
@@ -203,7 +197,7 @@ extension ParserStates: Compilable {
|
||||
public typealias ToCompile = ParserStates
|
||||
public typealias Compiled = (ParserStateInstance, [ParserStateInstance])
|
||||
public static func compile(_ parser: ToCompile) -> Result<Compiled> {
|
||||
var compiled_states:[ParserStateInstance] = Array()
|
||||
var compiled_states: [ParserStateInstance] = Array()
|
||||
|
||||
compiled_states.append(ParserStateNoTransition(currrent_state: accept))
|
||||
compiled_states.append(ParserStateNoTransition(currrent_state: reject))
|
||||
@@ -213,7 +207,7 @@ extension ParserStates: Compilable {
|
||||
// TODO: We assume that states are in transition-order!
|
||||
for state in parser.states {
|
||||
switch ParserState.compile(state) {
|
||||
case .Ok(let compiled):
|
||||
case .Ok(let compiled):
|
||||
if compiled.state().state == Identifier(name: "start") {
|
||||
start_state = compiled
|
||||
}
|
||||
@@ -252,7 +246,8 @@ extension ParserInstance: Compilable {
|
||||
|
||||
public static func compile(_ parser: ToCompile) -> Result<Compiled> {
|
||||
return switch ParserStates.compile(parser.states) {
|
||||
case .Ok(let (start_state, states)): Result.Ok(ParserInstance(start: start_state, states: states))
|
||||
case .Ok(let (start_state, states)):
|
||||
Result.Ok(ParserInstance(start: start_state, states: states))
|
||||
case .Error(let e): Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,4 +66,4 @@ extension ExpressionStatement: EvaluatableStatement {
|
||||
public func evaluate(execution: ProgramExecution) -> ProgramExecution {
|
||||
return execution
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user