import { useState } from "react"; import { ConcreteState, emptyStatechart, isAncestorOf, Statechart, stateDescription, Transition } from "../VisualEditor/ast"; import { VisualEditor } from "../VisualEditor/VisualEditor"; import { Environment, Mode, RT_Statechart } from "../VisualEditor/runtime_types"; import { initialize, handleEvent, handleInputEvent } from "../VisualEditor/interpreter"; import { Action, Expression } from "../VisualEditor/label_ast"; import "../index.css"; import "./App.css"; export function ShowTransition(props: {transition: Transition}) { return <>➔ {stateDescription(props.transition.tgt)}; } export function ShowExpr(props: {expr: Expression}) { if (props.expr.kind === "literal") { return <>{props.expr.value}; } else if (props.expr.kind === "ref") { return <>{props.expr.variable}; } else if (props.expr.kind === "unaryExpr") { return <>{props.expr.operator}; } else if (props.expr.kind === "binaryExpr") { return <>{props.expr.operator}; } } export function ShowAction(props: {action: Action}) { if (props.action.kind === "raise") { return <>raise {props.action.event}; } else if (props.action.kind === "assignment") { return <>{props.action.lhs} = ;; } } export function AST(props: {root: ConcreteState, transitions: Map}) { const description = stateDescription(props.root); const outgoing = props.transitions.get(props.root.uid) || []; return
{props.root.kind}: {description} {props.root.entryActions.length>0 && props.root.entryActions.map(action =>
 entry /
) } {props.root.exitActions.length>0 && props.root.exitActions.map(action =>
 exit /
) } {props.root.children.length>0 && props.root.children.map(child => ) } {outgoing.length>0 && outgoing.map(transition => <> 
) }
} export function App() { const [ast, setAST] = useState(emptyStatechart); const [errors, setErrors] = useState<[string,string][]>([]); const [rt, setRT] = useState([]); const [rtIdx, setRTIdx] = useState(null); const [timeMs, setTimeMs] = useState(0); const [paused, setPaused] = useState(true); const [timescale, setTimescale] = useState(1); function restart() { const rt = initialize(ast); console.log('runtime: ', rt); setRT([rt]); setRTIdx(0); } function stop() { setRT([]); setRTIdx(null); } function raise(event: string) { console.log(rtIdx); if (rt.length>0 && rtIdx!==null && ast.inputEvents.has(event)) { const nextConfig = handleInputEvent(event, ast, rt[rtIdx]!); setRT([...rt.slice(0, rtIdx+1), nextConfig]); setRTIdx(rtIdx+1); } } return
  raise {[...ast.inputEvents].map(event => )}   setPaused(e.target.checked)}/> setPaused(!e.target.checked)}/>   time is {timeMs} ms
; } function ShowEnvironment(props: {environment: Environment}) { return <>{[...props.environment.entries()].map(([variable,value]) => `${variable}: ${value}` ).join(', ')}; } function ShowMode(props: {mode: Mode, statechart: Statechart}) { const activeLeafs = getActiveLeafs(props.mode, props.statechart); return <>{[...activeLeafs].map(uid => stateDescription(props.statechart.uid2State.get(uid)!)).join(",")}; } function getActiveLeafs(mode: Mode, sc: Statechart) { const toDelete = []; for (const stateA of mode) { for (const stateB of mode) { if (sc.uid2State.get(stateA)!.parent === sc.uid2State.get(stateB)) { toDelete.push(stateB); } } } return mode.difference(new Set(toDelete)); } export default App;