Skip to content

Commit 9be55c2

Browse files
authored
81 pv formulae not supported (#116)
* Updated PV parser to correctly parse PV formulae * Added test for PV formula * Added "eq://" to list of plugins * Updated PV.qualifiedName() to check for single-quotes and substituted formulas * Updated PV.qualifiedName() to check for substituted formulas starting with "=" * Replace "=" with "eq://" in substituted formulae
1 parent e66c999 commit 9be55c2

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/redux/store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if (PVWS_SOCKET !== undefined) {
2828
plugins.unshift(["sim://", pvws]);
2929
plugins.unshift(["ssim://", pvws]);
3030
plugins.unshift(["dev://", pvws]);
31+
plugins.unshift(["eq://", pvws]);
3132
}
3233
const connection = new ConnectionForwarder(plugins);
3334

src/types/pv.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ describe("PV", (): void => {
1313
const pv = PV.parse("pvName");
1414
expect(pv).toEqual(new PV("pvName", "ca"));
1515
});
16+
it("ignores nested pv", (): void => {
17+
const pv = PV.parse("=3+4*`sim://ramp`");
18+
expect(pv.qualifiedName()).toEqual("eq://3+4*`sim://ramp`");
19+
});
1620
});

src/types/pv.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ export class PV {
2424
* PV.parse("pvName")
2525
*/
2626
public static parse(pvName: string, defaultProtocol = "ca"): PV {
27+
if (pvName.startsWith("=")) {
28+
return new PV(pvName.slice(1), "eq");
29+
}
2730
if (pvName.includes(PV.DELIMITER)) {
28-
const parts = pvName.split(PV.DELIMITER);
29-
return new PV(parts[1], parts[0]);
31+
// "protocol://name" -> ["protocol://name", "protocol", "name"]
32+
const parts = /^(.*):\/\/(.*)$/.exec(pvName);
33+
if (parts) {
34+
return new PV(parts[2], parts[1]);
35+
}
36+
return new PV(pvName, defaultProtocol);
3037
} else {
3138
return new PV(pvName, defaultProtocol);
3239
}
@@ -41,8 +48,18 @@ export class PV {
4148
public qualifiedName(): string {
4249
// This can happen if the name is substituted by a macro
4350
// after the PV object has been created.
44-
if (this.name.includes(PV.DELIMITER)) {
51+
// Need to make sure that the PV.DELIMITER is not associated with a nested PV.
52+
if (
53+
this.name.includes(PV.DELIMITER) &&
54+
!this.name.includes("`") &&
55+
!this.name.includes("'")
56+
) {
57+
return this.name;
58+
// In case the name has been substituted with another formula
59+
} else if (this.name.startsWith("eq://")) {
4560
return this.name;
61+
} else if (this.name.startsWith("=")) {
62+
return this.name.replace("=", "eq://");
4663
} else {
4764
return `${this.protocol}${PV.DELIMITER}${this.name}`;
4865
}

0 commit comments

Comments
 (0)