Refactor Parser States
Refactor the class hierarchy for parser states so that there is a parser state that acts more like a type and one that acts more like a value (the latter, then, serves as the base class for the other instantiated parser states). Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -24,8 +24,7 @@ extension SelectCaseExpression: EvaluatableExpression {
|
||||
}
|
||||
|
||||
public func type() -> any Common.P4Type {
|
||||
// TODO
|
||||
return reject
|
||||
return ParserState()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +45,8 @@ extension SelectExpression: EvaluatableExpression {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
public func type() -> any Common.P4Type {
|
||||
return reject
|
||||
return ParserState()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,11 +118,11 @@ extension ParserStateSelectTransition: EvaluatableParserState {
|
||||
}
|
||||
|
||||
extension Parser: ParserExecution {
|
||||
public func execute(execution: ProgramExecution) -> (ParserState, ProgramExecution) {
|
||||
public func execute(execution: ProgramExecution) -> (InstantiatedParserState, ProgramExecution) {
|
||||
var execution = execution.enter_scope()
|
||||
|
||||
execution = execution.declare(identifier: accept.state().state, withValue: accept)
|
||||
execution = execution.declare(identifier: reject.state().state, withValue: reject)
|
||||
execution = execution.declare(identifier: AsInstantiatedParserState(accept.state()).state, withValue: accept)
|
||||
execution = execution.declare(identifier: AsInstantiatedParserState(reject.state()).state, withValue: reject)
|
||||
|
||||
// Add initial values to the global scope
|
||||
if let initial = execution.initial_values() {
|
||||
@@ -148,6 +148,6 @@ extension Parser: ParserExecution {
|
||||
while !current_state.done() && !execution.hasError() {
|
||||
(current_state, execution) = current_state.execute(program: execution)
|
||||
}
|
||||
return (current_state.state(), execution)
|
||||
return (AsInstantiatedParserState(current_state.state()), execution)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,5 +35,5 @@ public protocol EvaluatableParserState: P4Value {
|
||||
}
|
||||
|
||||
public protocol ParserExecution {
|
||||
func execute(execution: ProgramExecution) -> (ParserState, ProgramExecution)
|
||||
func execute(execution: ProgramExecution) -> (InstantiatedParserState, ProgramExecution)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user