Skip to content

Commit

Permalink
Json xml (#26)
Browse files Browse the repository at this point in the history
* Location, Edge, Component and System data structures done, no testing

* Component, System, Location and Edge done with tests

* Queries, Query and Declarations parsed an finished.

* Fixed missing comma after merge conflict

* After yarn format

* After yarn format

* LINT FIX

* New file structure with smaller files

* fixed import error

* added more subfiles

* New filescructure and JsDoc documentation

* yarn.lock

* removed lodash and replaced with strict equal

* removed @types/lodash

---------

Co-authored-by: AlbertHald <[email protected]>
  • Loading branch information
KamyaPA and AlbertHald authored Sep 28, 2023
1 parent 5f2f356 commit c2d6ca6
Show file tree
Hide file tree
Showing 31 changed files with 1,762 additions and 0 deletions.
568 changes: 568 additions & 0 deletions src/lib/classes/automaton.test.ts

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions src/lib/classes/automaton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Raw Types
export type {
RawLocation,
RawEdge,
RawComponent,
RawSystem,
RawQuery,
RawDeclaration,
FromRaw,
ToRaw,
SerializeRaw,
DeserializeRaw
} from './automaton/raw';

// Enums
export { Backend } from './automaton/backend';
export { DeclarationType } from './automaton/declaration_type';
export { Status } from './automaton/status';
export { LocationType } from './automaton/location_type';
export { OperatorType } from './automaton/operator_type';
export { PropertyType } from './automaton/property_type';
export { Urgency } from './automaton/urgency';

// Minor Classes
export { Invariant } from './automaton/invariant';
export { Nickname } from './automaton/nickname';
export { Operator } from './automaton/operator';
export { Property } from './automaton/property';
export { SystemEdge } from './automaton/system_edge';
export { ComponentInstance } from './automaton/component_instance';

// Major Classes
export { Declaration } from './automaton/declaration';
export { Component } from './automaton/component';
export { Edge } from './automaton/edge';
export { Location } from './automaton/location';
export { Query, Queries } from './automaton/query';
export { System } from './automaton/system';
9 changes: 9 additions & 0 deletions src/lib/classes/automaton/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* What backend is targeted
* - j-ECDAR or
* - Reveaal
* */
export enum Backend {
J_ECDAR = 0,
REVEAAL = 1
}
131 changes: 131 additions & 0 deletions src/lib/classes/automaton/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Point, Dimensions } from '$lib/classes/draw';

import { Edge, Location } from '../automaton';
import type { SerializeRaw, ToRaw, FromRaw, DeserializeRaw, RawComponent } from '../automaton';

/**
* # An Ecdar component
* It stores the edges and locations of a single automaton
* */
export class Component implements SerializeRaw, ToRaw<RawComponent> {
/**
* The name of the component
* */
name: string = '';

/**
* The declarations of the component ex "clock t;"
* */
declarations: string = '';

/**
* A list of Locations in the Component
* */
locations: Location[] = [];

/**
* A list of Edges in the Component
* */
edges: Edge[] = [];

/**
* A description of the Component
* */
description: string = '';

/**
* The position of the Component
* */
position = new Point(0, 0);

/**
* The dimensions of the Component
* */
dimensions: Dimensions;

/**
* The color of the Component
* */
color: string = '0';

/**
* Include in periodic checks
* ! Some more information might be needed !
* */
includeInPeriodicCheck: boolean = false;

constructor(
name: string = '',
declarations: string = '',
locations: Location[] = [],
edges: Edge[] = [],
description: string = '',
position = new Point(0, 0),
dimensions = new Dimensions(100, 100),
color: string = '0',
includeInPeriodicCheck: boolean = false
) {
this.name = name;
this.declarations = declarations;
this.locations = locations;
this.edges = edges;
this.description = description;
this.position = position;
this.dimensions = dimensions;
this.color = color;
this.includeInPeriodicCheck = includeInPeriodicCheck;
}

toRaw() {
return {
name: this.name,
declarations: this.declarations,
locations: this.locations.map((l) => {
return l.toRaw();
}),
edges: this.edges.map((e) => {
return e.toRaw();
}),
description: this.description,
x: this.position.x,
y: this.position.y,
width: this.dimensions.width,
height: this.dimensions.height,
color: this.color,
includeInPeriodicCheck: this.includeInPeriodicCheck
};
}

serializeRaw() {
return JSON.stringify(this.toRaw());
}

/**
* Converts the Component into a RawComponent
* */
static fromRaw: FromRaw<RawComponent, Component> = (raw) => {
return new Component(
raw.name,
raw.declarations,
raw.locations.map((raw) => {
return Location.fromRaw(raw);
}),
raw.edges.map((raw) => {
return Edge.fromRaw(raw);
}),
raw.description,
new Point(raw.x, raw.y),
new Dimensions(raw.width, raw.height),
raw.color,
raw.includeInPeriodicCheck
);
};

/**
* Creates a Component from a JSON string of a RawComponent
* */
static deserializeRaw: DeserializeRaw<Component> = (input) => {
const raw: RawComponent = JSON.parse(input);
return Component.fromRaw(raw);
};
}
29 changes: 29 additions & 0 deletions src/lib/classes/automaton/component_instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Point } from '$lib/classes/draw';

/**
* # A Component Instance
* Is used by a System to store what components are used
* */
export class ComponentInstance {
/**
* The id of the component instance
* This must be unique and is shared by Operators
* */
id: number;

/**
* The name of the component this references
* */
name: string;

/**
* The position of the component instance
* */
position: Point;

constructor(id: number, name: string, position: Point) {
this.id = id;
this.name = name;
this.position = position;
}
}
42 changes: 42 additions & 0 deletions src/lib/classes/automaton/declaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
type SerializeRaw,
type ToRaw,
type FromRaw,
type DeserializeRaw,
type RawDeclaration,
DeclarationType
} from '../automaton';

/**
* The top level declarations
* */
export class Declaration implements SerializeRaw, ToRaw<RawDeclaration> {
type: DeclarationType;
declarations: string;

constructor(type = DeclarationType.GLOBAL, declarations = '') {
this.type = type;
this.declarations = declarations;
}

static fromRaw: FromRaw<RawDeclaration, Declaration> = (raw) => {
return new Declaration(raw.name as DeclarationType, raw.declarations);
};

static deserializeRaw: DeserializeRaw<Declaration> = (input) => {
const raw = JSON.parse(input);
return Declaration.fromRaw(raw);
};

toRaw() {
return {
name: this.type,
declarations: this.declarations
};
}

serializeRaw(): string {
const raw = this.toRaw();
return JSON.stringify(raw);
}
}
4 changes: 4 additions & 0 deletions src/lib/classes/automaton/declaration_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum DeclarationType {
GLOBAL = 'Global Declarations',
SYSETEM = 'System Declarations'
}
Loading

0 comments on commit c2d6ca6

Please sign in to comment.