Skip to content

Commit 5749ca7

Browse files
authored
Use Shared State Machine Parser Module (#111)
1 parent 88fca81 commit 5749ca7

30 files changed

Lines changed: 24 additions & 1020 deletions

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ For more information, check the following repositories:
137137
- [liquidjava](https://github.com/liquid-java/liquidjava): Includes the API, verifier and some examples
138138
- [vscode-liquidjava](https://github.com/liquid-java/vscode-liquidjava): Source code of this VS Code extension
139139
- [liquidjava-examples](https://github.com/liquid-java/liquidjava-examples): Examples of how to use LiquidJava
140-
- [liquid-java-external-libs](https://github.com/liquid-java/liquid-java-external-libs): Examples of how to use LiquidJava to refine external libraries
140+
- [liquid-java-external-libs](https://github.com/liquid-java/liquid-java-external-libs): Examples of how to use LiquidJava to refine external libraries
141+
- [liquidjava-fsm](https://github.com/liquid-java/liquidjava-fsm): State machine parser used by the VS Code language server

‎client/src/types/fsm.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
export type LJStateMachine = {
44
className: string;
5-
initialTransitions: { to: string; postCond?: string | null }[];
5+
initialTransitions: { to: string; toCondition?: string | null }[];
66
states: string[];
7-
transitions: { from: string; to: string; label: string; preCond?: string | null; postCond?: string | null }[];
7+
transitions: { from: string; to: string; label: string; fromCondition?: string | null; toCondition?: string | null }[];
88
errorContext: LJStateMachineErrorContext | null;
99
};
1010

‎client/src/webview/diagram.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function createMermaidDiagram(
3535

3636
// initial transitions
3737
sm.initialTransitions.forEach(transition => {
38-
const label = getInitialTransitionLabel(transition.postCond, showConditions);
38+
const label = getInitialTransitionLabel(transition.toCondition, showConditions);
3939
lines.push(` [*] --> ${transition.to}${label ? ` : ${label}` : ''}`);
4040
});
4141

@@ -45,8 +45,8 @@ export function createMermaidDiagram(
4545
const isCalledMethod = transition.label === sm.errorContext?.calledMethod;
4646
const label = getTransitionLabel(
4747
transition.label,
48-
transition.preCond,
49-
transition.postCond,
48+
transition.fromCondition,
49+
transition.toCondition,
5050
showConditions,
5151
isCalledMethod,
5252
);
@@ -72,8 +72,8 @@ export function createMermaidDiagram(
7272

7373
function getTransitionLabel(
7474
label: string,
75-
preCond?: string | null,
76-
postCond?: string | null,
75+
fromCondition?: string | null,
76+
toCondition?: string | null,
7777
showConditions = false,
7878
isCalledMethod = false,
7979
): string {
@@ -83,14 +83,14 @@ function getTransitionLabel(
8383
: escapedLabel;
8484
if (!showConditions) return methodLabel;
8585
return [
86-
getConditionLabel('pre', preCond),
86+
getConditionLabel('pre', fromCondition),
8787
methodLabel,
88-
getConditionLabel('post', postCond)
88+
getConditionLabel('post', toCondition)
8989
].filter(Boolean).join('<br/>');
9090
}
9191

92-
function getInitialTransitionLabel(postCond?: string | null, showConditions = false): string {
93-
return showConditions ? getConditionLabel('post', postCond) : '';
92+
function getInitialTransitionLabel(toCondition?: string | null, showConditions = false): string {
93+
return showConditions ? getConditionLabel('post', toCondition) : '';
9494
}
9595

9696
function getConditionLabel(kind: 'pre' | 'post', cond?: string | null): string {

‎client/src/webview/views/fsm/fsm.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export function renderStateMachineView(root: HTMLElement, sm: LJStateMachine | u
1111

1212
function renderStateMachineViewHtml(sm: LJStateMachine | undefined, diagram: string, orientation: "LR" | "TB", showConditions: boolean, diagramHeight?: number): string {
1313
const hasConditionExpansions = sm
14-
? sm.initialTransitions.some(transition => !!transition.postCond)
15-
|| sm.transitions.some(transition => !!transition.preCond || !!transition.postCond)
14+
? sm.initialTransitions.some(transition => !!transition.toCondition)
15+
|| sm.transitions.some(transition => !!transition.fromCondition || !!transition.toCondition)
1616
: false;
1717
const conditionToggleLabel = !hasConditionExpansions
1818
? 'No additional conditions to expand'

‎server/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@
174174
<artifactId>liquidjava-verifier</artifactId>
175175
<version>0.0.32</version>
176176
</dependency>
177+
<dependency>
178+
<groupId>io.github.liquid-java</groupId>
179+
<artifactId>liquidjava-fsm</artifactId>
180+
<version>0.1.0</version>
181+
</dependency>
177182
<dependency>
178183
<groupId>tools.aqua</groupId>
179184
<artifactId>z3-turnkey</artifactId>

‎server/src/main/java/LJLanguageServer.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import org.eclipse.lsp4j.services.WorkspaceService;
1616

1717
import dtos.uri.Uri;
18-
import fsm.StateMachine;
19-
import fsm.StateMachineParser;
18+
import liquidjava.fsm.StateMachine;
19+
import liquidjava.fsm.StateMachineParser;
2020

2121
public class LJLanguageServer implements LanguageServer {
2222

‎server/src/main/java/dtos/errors/StateRefinementErrorDTO.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import dtos.diagnostics.SourcePositionDTO;
66
import dtos.diagnostics.VCSimplificationResultDTO;
7-
import fsm.StateMachine;
8-
import fsm.StateMachineParser;
7+
import liquidjava.fsm.StateMachine;
8+
import liquidjava.fsm.StateMachineParser;
99
import liquidjava.diagnostics.errors.StateRefinementError;
1010
import liquidjava.rj_language.ast.formatter.ExpressionFormatter;
1111

‎server/src/main/java/fsm/StateMachine.java‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎server/src/main/java/fsm/StateMachineErrorContext.java‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎server/src/main/java/fsm/StateMachineInitialTransition.java‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)