module demo::lang::MissGrant::ToMethods
rascal-0.40.17
Usage
import demo::lang::MissGrant::ToMethods;
Dependencies
import demo::lang::MissGrant::AST;
function controller2methods
public str controller2methods(str name, Controller ctl) =
"public class <name> {
' <for (e <- ctl.events) {>
' <event2java(e)>
' <}>
' <for (c <- ctl.commands) {>
' <command2java(c)>
' <}>
' <for (s <- ctl.states) {>
' <state2java(s)>
' <}>
'}";
function event2java
public str event2java(Event event) =
"private boolean <event.name>(String token) {
' return token.equals(\"<event.token>\");
'}";
function command2java
public str command2java(Command command) =
"private void <command.name>(Writer output) {
' output.write(\"<command.token>\");
'}";
function state2java
public str state2java(State state) =
"private void <stateName(state)>(Scanner input, Writer output) {
' <for (a <- state.actions) {>
' <a>(output);
' <}>
' String token = input.nextLine();
' <for (t <- state.transitions) {>
' if (<t.event>(token)) {
' <stateName(t.state)>(input, output);
' return;
' }
' <stateName(state)>(input, output);
' <}>
'}";
function stateName
public str stateName(State s) = stateName(s.name);
public str stateName(str s) = "state$<s>";