Skip to content

Commit

Permalink
adjusted grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Sep 21, 2023
1 parent a2f5cad commit 204db0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ function determineCutSetsForGate(startNode: AstNode, allNodes: AstNode[]): Set<n
return result;
}

if (isAND(startNode.type) || isInhibitGate(startNode.type)) {
if (isAND(startNode) || isInhibitGate(startNode)) {
// concatenate each cut set of a child with every cut set of the other children
for (const child of children) {
result = concatInnerListsWithEachOther(determineCutSetsForGate(child, allNodes), result);
}
} else if (isOR(startNode.type)) {
} else if (isOR(startNode)) {
// add the cut sets of each child to the result
for (const child of children) {
result.push(...determineCutSetsForGate(child, allNodes));
}
} else if (isKNGate(startNode.type)) {
const k = startNode.type.k;
const n = startNode.type.children.length;
} else if (isKNGate(startNode)) {
const k = startNode.k;
const n = startNode.children.length;

// determine every combination (with length k or greater) of the children
// Example: children = [M1, M2, G1] and k = 2 -> [[M1, M2], [M1, G1], [M2, G1], [M1, M2, G1]]
Expand Down Expand Up @@ -190,14 +190,14 @@ function getChildrenOfNode(node: AstNode): namedFtaElement[] {

if (isGate(node)) {
// add children of the gate
for (const childRef of node.type.children) {
for (const childRef of node.children) {
if (childRef.ref) {
children.push(childRef.ref);
}
}
// add condition of inhibit gate
if (isInhibitGate(node.type)) {
for (const childRef of node.type.condition) {
if (isInhibitGate(node)) {
for (const childRef of node.condition) {
if (childRef?.ref) {
children.push(childRef.ref);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
TopEvent,
isComponent,
isCondition,
isGate,
isKNGate,
isKNGate
} from "../../generated/ast";
import { FtaServices } from "../fta-module";
import { FTAEdge, FTANode } from "./fta-interfaces";
Expand Down Expand Up @@ -180,16 +179,16 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator {
desc = node.description;
}

if (isGate(node) && isKNGate(node.type)) {
if (isKNGate(node)) {
return {
type: FTA_NODE_TYPE,
id: nodeId,
nodeType: getFTNodeType(node),
description: desc,
children: children,
highlight: true,
k: node.type.k,
n: node.type.children.length,
k: node.k,
n: node.children.length,
layout: "stack",
layoutOptions: {
paddingTop: 10.0,
Expand Down
22 changes: 11 additions & 11 deletions extension/src-language-server/fta/diagram/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export function getFTNodeType(node: AstNode): FTNodeType {
return FTNodeType.COMPONENT;
} else if (isCondition(node)) {
return FTNodeType.CONDITION;
} else if (isGate(node) && isAND(node.type)) {
} else if (isAND(node)) {
return FTNodeType.AND;
} else if (isGate(node) && isOR(node.type)) {
} else if (isOR(node)) {
return FTNodeType.OR;
} else if (isGate(node) && isKNGate(node.type)) {
} else if (isKNGate(node)) {
return FTNodeType.KN;
} else if (isGate(node) && isInhibitGate(node.type)) {
} else if (isInhibitGate(node)) {
return FTNodeType.INHIBIT;
}
return FTNodeType.UNDEFINED;
Expand All @@ -58,13 +58,13 @@ export function getTargets(node: AstNode): AstNode[] {
}
}
} else if (isGate(node)) {
for (const ref of node.type.children) {
for (const ref of node.children) {
if (ref?.ref) {
targets.push(ref.ref);
}
}
if (isInhibitGate(node.type)) {
for (const ref of node.type.condition) {
if (isInhibitGate(node)) {
for (const ref of node.condition) {
if (ref?.ref) {
targets.push(ref.ref);
}
Expand All @@ -89,13 +89,13 @@ export function getAllGateTypes(gates: Gate[]): Map<string, AstNode[]> {
const inhibGates: AstNode[] = [];

for (const gate of gates) {
if (isAND(gate.type)) {
if (isAND(gate)) {
andGates.push(gate);
} else if (isOR(gate.type)) {
} else if (isOR(gate)) {
orGates.push(gate);
} else if (isKNGate(gate.type)) {
} else if (isKNGate(gate)) {
kNGates.push(gate);
} else if (isInhibitGate(gate.type)) {
} else if (isInhibitGate(gate)) {
inhibGates.push(gate);
}
}
Expand Down
10 changes: 5 additions & 5 deletions extension/src-language-server/fta/fta.langium
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Condition:
name=ID description=STRING;

Gate:
name=ID "=" type=(AND|OR|KNGate|InhibitGate);
AND|OR|KNGate|InhibitGate;

TopEvent:
name=STRING "=" children+=[Children:ID];
Expand All @@ -22,16 +22,16 @@ Children:
Gate | Component;

AND:
children+=[Children:ID] ('and' children+=[Children:ID])+;
name=ID "=" children+=[Children:ID] ('and' children+=[Children:ID])+;

OR:
children+=[Children:ID] ('or' children+=[Children:ID])+;
name=ID "=" children+=[Children:ID] ('or' children+=[Children:ID])+;

KNGate:
k=INT 'of' children+=[Children:ID] (',' children+=[Children:ID])+;
name=ID "=" k=INT 'of' children+=[Children:ID] (',' children+=[Children:ID])+;

InhibitGate:
condition+=[Condition:ID] 'inhibits' children+=[Children:ID];
name=ID "=" condition+=[Condition:ID] 'inhibits' children+=[Children:ID];

hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;
Expand Down

0 comments on commit 204db0e

Please sign in to comment.