This is a lisp sort of thing to do as written, but there really is no reason these can't be ordinary objects with two methods, test and act. The code would be clearer and easier to debug. Particularly if the classes have names like
final class StartState(states: => ArrayBuffer[State], val stateNum: Int) extends State(states) {
|
type R = Registers // put into State base class, protected
|
|
object Got_EC_goto_ESCState extends Rule {
|
def test(r: R) = { ... }
|
def act(r: R) = { ... }
|
}
|
|
object Got_EEC_goto_ESCESCState extends Rule {
|
def test(r: R) = { ... }
|
def act(r: R) = { ... }
|
}
|
...
|
override val rules = ArrayBuffer(
|
Got_EC_goto_ESCState,
|
Got_EEC_goto_EECState,
|
...
|
)
|
...
|
}
|
In the above, the nesting makes it clear each "Rule" which is a state-machine transition, originates at a particular state.