parse comments
This commit is contained in:
parent
9dd72484fa
commit
692c052e11
4 changed files with 26 additions and 5 deletions
|
|
@ -143,4 +143,8 @@ text.error, tspan.error {
|
||||||
|
|
||||||
g:hover > .errorHover {
|
g:hover > .errorHover {
|
||||||
display: inline;
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
text.uid {
|
||||||
|
fill: lightgrey;
|
||||||
}
|
}
|
||||||
|
|
@ -734,6 +734,7 @@ export function RountangleSVG(props: {rountangle: Rountangle, selected: string[]
|
||||||
data-parts="bottom left"
|
data-parts="bottom left"
|
||||||
/>
|
/>
|
||||||
<text x={10} y={20}
|
<text x={10} y={20}
|
||||||
|
className="uid"
|
||||||
data-uid={uid}
|
data-uid={uid}
|
||||||
data-parts="left top right bottom">{uid}</text>
|
data-parts="left top right bottom">{uid}</text>
|
||||||
</g>;
|
</g>;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import { TransitionLabel } from "./label_ast";
|
import { Action, TransitionLabel } from "./label_ast";
|
||||||
|
|
||||||
export type AbstractState = {
|
export type AbstractState = {
|
||||||
uid: string;
|
uid: string;
|
||||||
children: ConcreteState[];
|
children: ConcreteState[];
|
||||||
comments: [string, string][]; // array of tuple (text-uid, text-text)
|
comments: [string, string][]; // array of tuple (text-uid, text-text)
|
||||||
|
entryActions: Action[];
|
||||||
|
exitActions: Action[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AndState = {
|
export type AndState = {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ export function parseStatechart(state: VisualEditorState): [Statechart, [string,
|
||||||
uid: "root",
|
uid: "root",
|
||||||
children: [],
|
children: [],
|
||||||
initial: [],
|
initial: [],
|
||||||
|
comments: [],
|
||||||
|
entryActions: [],
|
||||||
|
exitActions: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const uid2State = new Map<string, ConcreteState>([["root", root]]);
|
const uid2State = new Map<string, ConcreteState>([["root", root]]);
|
||||||
|
|
@ -38,6 +41,8 @@ export function parseStatechart(state: VisualEditorState): [Statechart, [string,
|
||||||
uid: rt.uid,
|
uid: rt.uid,
|
||||||
children: [],
|
children: [],
|
||||||
comments: [],
|
comments: [],
|
||||||
|
entryActions: [],
|
||||||
|
exitActions: [],
|
||||||
}
|
}
|
||||||
if (state.kind === "or") {
|
if (state.kind === "or") {
|
||||||
state.initial = [];
|
state.initial = [];
|
||||||
|
|
@ -122,7 +127,8 @@ export function parseStatechart(state: VisualEditorState): [Statechart, [string,
|
||||||
|
|
||||||
// step 3: figure out labels
|
// step 3: figure out labels
|
||||||
|
|
||||||
for (const text of state.texts) {
|
const textsSorted = state.texts.toSorted((a,b) => a.topLeft.y - b.topLeft.y);
|
||||||
|
for (const text of textsSorted) {
|
||||||
let parsed: ParsedText;
|
let parsed: ParsedText;
|
||||||
try {
|
try {
|
||||||
parsed = parseLabel(text.text); // may throw
|
parsed = parseLabel(text.text); // may throw
|
||||||
|
|
@ -176,19 +182,27 @@ export function parseStatechart(state: VisualEditorState): [Statechart, [string,
|
||||||
// text does not belong to transition...
|
// text does not belong to transition...
|
||||||
// so it belongs to a rountangle (a state)
|
// so it belongs to a rountangle (a state)
|
||||||
const rountangle = findRountangle(text.topLeft, state.rountangles);
|
const rountangle = findRountangle(text.topLeft, state.rountangles);
|
||||||
|
const belongsToState = rountangle ? uid2State.get(rountangle.uid)! : root;
|
||||||
if (parsed.kind === "transitionLabel") {
|
if (parsed.kind === "transitionLabel") {
|
||||||
// labels belonging to a rountangle (= a state) must by entry/exit actions
|
// labels belonging to a rountangle (= a state) must by entry/exit actions
|
||||||
// if we cannot find a containing state, then it belong to the root
|
// if we cannot find a containing state, then it belong to the root
|
||||||
const state = rountangle ? uid2State.get(rountangle.uid)! : root;
|
if (parsed.trigger.kind === "entry") {
|
||||||
if (parsed.trigger.kind !== "entry" && parsed.trigger.kind !== "exit") {
|
belongsToState.entryActions.push(...parsed.actions);
|
||||||
|
}
|
||||||
|
else if(parsed.trigger.kind === "exit") {
|
||||||
|
belongsToState.exitActions.push(...parsed.actions);
|
||||||
|
}
|
||||||
|
else {
|
||||||
errorShapes.push([text.uid, {
|
errorShapes.push([text.uid, {
|
||||||
message: "states can only have entry/exit triggers",
|
message: "states can only have entry/exit triggers",
|
||||||
location: {start: {offset: 0}, end: {offset: text.text.length}},
|
location: {start: {offset: 0}, end: {offset: text.text.length}},
|
||||||
}]);
|
} as unknown as string]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (parsed.kind === "comment") {
|
else if (parsed.kind === "comment") {
|
||||||
// just append comments to their respective states
|
// just append comments to their respective states
|
||||||
|
belongsToState.comments.push([text.uid, parsed.text]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue