From 0b68cc86a762fc91b8989852f2b68d246cf99917 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Thu, 14 Mar 2024 13:17:51 +0200 Subject: [PATCH] fix(parser): parse global properties (K objects) fixes the pin label color issue: https://github.com/TinyTapeout/xschem-viewer/issues/2#issuecomment-1997048537 --- src/SVGRenderer.ts | 5 ++++- src/xschem-parser.peg | 6 +++--- src/xschem-parser.ts | 17 ++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/SVGRenderer.ts b/src/SVGRenderer.ts index 3a3b2d5..2ddcb78 100644 --- a/src/SVGRenderer.ts +++ b/src/SVGRenderer.ts @@ -231,8 +231,11 @@ export class SVGRenderer extends EventTarget { break; } + case 'GlobalProperties': + Object.assign(properties, item.properties); + break; + case 'Version': - case 'Netlisting': case 'Verilog': case 'Spice': case 'VHDL': diff --git a/src/xschem-parser.peg b/src/xschem-parser.peg index 97a33b2..05a80c4 100644 --- a/src/xschem-parser.peg +++ b/src/xschem-parser.peg @@ -41,7 +41,7 @@ Object / Verilog / VHDL / TEDAx - / Netlisting + / GlobalProperties / EmbeddedSymbol Spice @@ -56,8 +56,8 @@ VHDL TEDAx = "E" _ content:CurlyBracedString { return { type: "TEDAx", content }; } -Netlisting - = "K" _ content:CurlyBracedString { return { type: "Netlisting", content }; } +GlobalProperties + = "K" _ properties:Properties { return { type: "GlobalProperties", properties }; } CurlyBracedString = "{" _ content:(Escape / NotEscape)* "}" { diff --git a/src/xschem-parser.ts b/src/xschem-parser.ts index 3dc9199..a8ce62b 100644 --- a/src/xschem-parser.ts +++ b/src/xschem-parser.ts @@ -451,9 +451,9 @@ const peggyParser: { parse: any; SyntaxError: any; DefaultTracer?: any } = // Ge return { type: 'TEDAx', content }; }; // @ts-ignore - var peg$f10 = function (content) { + var peg$f10 = function (properties) { // @ts-ignore - return { type: 'Netlisting', content }; + return { type: 'GlobalProperties', properties }; }; // @ts-ignore var peg$f11 = function (content) { @@ -1419,7 +1419,7 @@ const peggyParser: { parse: any; SyntaxError: any; DefaultTracer?: any } = // Ge // @ts-ignore if (s0 === peg$FAILED) { // @ts-ignore - s0 = peg$parseNetlisting(); + s0 = peg$parseGlobalProperties(); // @ts-ignore if (s0 === peg$FAILED) { // @ts-ignore @@ -1659,7 +1659,7 @@ const peggyParser: { parse: any; SyntaxError: any; DefaultTracer?: any } = // Ge // @ts-ignore function // @ts-ignore - peg$parseNetlisting() { + peg$parseGlobalProperties() { // @ts-ignore var s0, s1, s2, s3; @@ -1685,7 +1685,7 @@ const peggyParser: { parse: any; SyntaxError: any; DefaultTracer?: any } = // Ge // @ts-ignore s2 = peg$parse_(); // @ts-ignore - s3 = peg$parseCurlyBracedString(); + s3 = peg$parseProperties(); // @ts-ignore if (s3 !== peg$FAILED) { // @ts-ignore @@ -4149,13 +4149,16 @@ export type Object_1 = | Verilog | VHDL | TEDAx - | Netlisting + | GlobalProperties | EmbeddedSymbol; export type Spice = { type: 'Spice'; content: CurlyBracedString }; export type Verilog = { type: 'Verilog'; content: CurlyBracedString }; export type VHDL = { type: 'VHDL'; content: CurlyBracedString }; export type TEDAx = { type: 'TEDAx'; content: CurlyBracedString }; -export type Netlisting = { type: 'Netlisting'; content: CurlyBracedString }; +export type GlobalProperties = { + type: 'GlobalProperties'; + properties: Properties; +}; export type CurlyBracedString = string; export type Escape = '\\' | '{' | '}'; export type NotEscape = string;