circuitscript 0.0.22 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { createSVGWindow } from 'svgdom';
|
|
2
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
3
|
-
import { RenderFrameType, getBounds } from "./layout.
|
|
4
|
-
import { applyFontsToSVG } from './sizing.
|
|
5
|
-
import { ParamKeys, bodyColor, junctionColor, junctionSize, wireColor } from './globals.
|
|
6
|
-
import { NumericValue } from './objects/ParamDefinition.
|
|
7
|
-
import { getBoundsSize } from './utils.
|
|
2
|
+
import { RenderFrameType, getBounds } from "./layout.mjs";
|
|
3
|
+
import { applyFontsToSVG, getCreateSVGWindow } from './sizing.mjs';
|
|
4
|
+
import { ParamKeys, bodyColor, junctionColor, junctionSize, wireColor } from './globals.mjs';
|
|
5
|
+
import { NumericValue } from './objects/ParamDefinition.mjs';
|
|
6
|
+
import { getBoundsSize } from './utils.mjs';
|
|
8
7
|
export function generateSVG2(graph) {
|
|
9
|
-
const window =
|
|
8
|
+
const window = getCreateSVGWindow()();
|
|
10
9
|
const document = window.document;
|
|
11
10
|
registerWindow(window, document);
|
|
12
11
|
const canvas = SVG(document.documentElement);
|
|
@@ -36,7 +35,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
36
35
|
symbolGroup.translate(x, y);
|
|
37
36
|
const { symbol = null } = item;
|
|
38
37
|
if (symbol !== null && symbol) {
|
|
39
|
-
|
|
38
|
+
const extra = {};
|
|
40
39
|
if (item.component.parameters.has('__is_net')) {
|
|
41
40
|
extra.net_name = item.component.parameters.get(ParamKeys.net_name);
|
|
42
41
|
}
|
|
@@ -150,19 +149,3 @@ function drawGrid(group, canvasSize) {
|
|
|
150
149
|
color: '#aaa'
|
|
151
150
|
});
|
|
152
151
|
}
|
|
153
|
-
function calculateBoundingBox(components) {
|
|
154
|
-
let maxX = Number.NEGATIVE_INFINITY;
|
|
155
|
-
let minX = Number.POSITIVE_INFINITY;
|
|
156
|
-
let maxY = Number.NEGATIVE_INFINITY;
|
|
157
|
-
let minY = Number.POSITIVE_INFINITY;
|
|
158
|
-
components.forEach(item => {
|
|
159
|
-
minX = Math.min(item.x, minX);
|
|
160
|
-
maxX = Math.max(item.x + item.width, maxX);
|
|
161
|
-
minY = Math.min(item.y, minY);
|
|
162
|
-
maxY = Math.max(item.y + item.height, maxY);
|
|
163
|
-
});
|
|
164
|
-
return {
|
|
165
|
-
width: (maxX - minX),
|
|
166
|
-
height: (maxY - minY)
|
|
167
|
-
};
|
|
168
|
-
}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { HorizontalAlign, VerticalAlign } from './geometry.mjs';
|
|
3
|
+
import { defaultFont } from './globals.mjs';
|
|
4
|
+
import { JSModuleType, detectJSModuleType } from './helpers.mjs';
|
|
5
5
|
let MainCanvas = null;
|
|
6
6
|
const supportedFonts = {};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
let globalCreateSVGWindow;
|
|
8
|
+
export async function prepareSVGEnvironment(fontsPath) {
|
|
9
|
+
const moduleType = detectJSModuleType();
|
|
10
|
+
if (moduleType === JSModuleType.CommonJs) {
|
|
11
|
+
const { config, createSVGWindow } = await import('svgdom');
|
|
12
|
+
globalCreateSVGWindow = createSVGWindow;
|
|
13
|
+
if (fontsPath !== null) {
|
|
14
|
+
await config.setFontDir(fontsPath)
|
|
15
|
+
.setFontFamilyMappings(supportedFonts)
|
|
16
|
+
.preloadFonts();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function getCreateSVGWindow() {
|
|
21
|
+
if (globalCreateSVGWindow === undefined) {
|
|
22
|
+
throw "SVG environment is not set up yet";
|
|
23
|
+
}
|
|
24
|
+
return globalCreateSVGWindow;
|
|
11
25
|
}
|
|
12
26
|
export function applyFontsToSVG(canvas) {
|
|
13
27
|
}
|
|
@@ -18,7 +32,7 @@ const measureTextSizeCache = {};
|
|
|
18
32
|
const measureTextSizeCacheHits = {};
|
|
19
33
|
export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom) {
|
|
20
34
|
if (MainCanvas === null) {
|
|
21
|
-
const window =
|
|
35
|
+
const window = getCreateSVGWindow()();
|
|
22
36
|
const { document } = window;
|
|
23
37
|
registerWindow(window, document);
|
|
24
38
|
MainCanvas = SVG(document.documentElement);
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
|
|
3
2
|
import { program } from 'commander';
|
|
4
3
|
import figlet from 'figlet';
|
|
5
4
|
import path from 'path';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export default async function main(): Promise<void> {
|
|
13
|
-
const toolSrcPath = fileURLToPath(import.meta.url);
|
|
14
|
-
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
import { prepareSVGEnvironment } from './sizing.mjs';
|
|
7
|
+
import { getCurrentPath, getScriptText, getSemanticTokens, validateScript } from './helpers.mjs';
|
|
8
|
+
export async function validate() {
|
|
9
|
+
const { filePath } = getCurrentPath();
|
|
10
|
+
const toolSrcPath = filePath;
|
|
15
11
|
const toolDirectory = path.dirname(toolSrcPath) + '/../../';
|
|
16
12
|
const fontsPath = toolDirectory + '/fonts';
|
|
17
|
-
const defaultLibsPath = toolDirectory + '/libs';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const {version} = packageJson;
|
|
21
|
-
|
|
13
|
+
const defaultLibsPath = toolDirectory + '/libs';
|
|
14
|
+
const packageJson = JSON.parse(readFileSync(toolDirectory + 'package.json').toString());
|
|
15
|
+
;
|
|
16
|
+
const { version } = packageJson;
|
|
22
17
|
program
|
|
23
18
|
.description('generate graphical output from circuitscript files')
|
|
24
19
|
.version(version)
|
|
@@ -30,76 +25,50 @@ export default async function main(): Promise<void> {
|
|
|
30
25
|
.option('-w, --watch', 'Watch for file changes')
|
|
31
26
|
.option('-n, --dump-nets', 'Dump out net information')
|
|
32
27
|
.option('-d, --dump-data', 'Dump data during parsing')
|
|
33
|
-
.option('-s, --stats', 'Show stats during generation')
|
|
34
|
-
;
|
|
35
|
-
|
|
28
|
+
.option('-s, --stats', 'Show stats during generation');
|
|
36
29
|
program.addHelpText('before', figlet.textSync('circuitscript', {
|
|
37
30
|
font: 'Small Slant'
|
|
38
31
|
}));
|
|
39
|
-
|
|
40
|
-
if (process.argv.length < 3){
|
|
32
|
+
if (process.argv.length < 3) {
|
|
41
33
|
program.help();
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
program.parse();
|
|
45
|
-
|
|
35
|
+
program.parse();
|
|
46
36
|
const options = program.opts();
|
|
47
|
-
|
|
48
37
|
const watchFileChanges = options.watch;
|
|
49
38
|
const outputPath = options.output ?? null;
|
|
50
39
|
const dumpNets = options.dumpNets;
|
|
51
40
|
const dumpData = options.dumpData;
|
|
52
41
|
const kicadNetlist = options.kicadNetlist;
|
|
53
|
-
|
|
54
42
|
let currentDirectory = options.currentDirectory ?? null;
|
|
55
|
-
|
|
56
43
|
if (watchFileChanges) {
|
|
57
44
|
console.log('watching for file changes...');
|
|
58
45
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let inputFilePath: string = null;
|
|
63
|
-
|
|
64
|
-
let scriptData: string;
|
|
46
|
+
await prepareSVGEnvironment(fontsPath);
|
|
47
|
+
let inputFilePath = null;
|
|
48
|
+
let scriptData;
|
|
65
49
|
if (options.input) {
|
|
66
50
|
scriptData = options.input;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
inputFilePath = options.inputFile;
|
|
54
|
+
const tmpScriptData = getScriptText(inputFilePath);
|
|
55
|
+
if (tmpScriptData === null) {
|
|
56
|
+
throw "File does not exists";
|
|
57
|
+
}
|
|
58
|
+
scriptData = tmpScriptData;
|
|
71
59
|
if (currentDirectory === null) {
|
|
72
60
|
currentDirectory = path.dirname(inputFilePath);
|
|
73
61
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const renderOptions = {
|
|
62
|
+
}
|
|
63
|
+
const scriptOptions = {
|
|
77
64
|
currentDirectory,
|
|
78
65
|
defaultLibsPath,
|
|
79
|
-
dumpNets,
|
|
66
|
+
dumpNets,
|
|
80
67
|
dumpData,
|
|
81
68
|
kicadNetlistPath: kicadNetlist,
|
|
82
69
|
showStats: options.stats,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
renderOptions);
|
|
87
|
-
|
|
88
|
-
if (outputPath === null && output){
|
|
89
|
-
console.log(output);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (watchFileChanges) {
|
|
93
|
-
watch(inputFilePath, event => {
|
|
94
|
-
if (event === 'change') {
|
|
95
|
-
const scriptData = readFileSync(inputFilePath,
|
|
96
|
-
{encoding: 'utf-8'});
|
|
97
|
-
|
|
98
|
-
renderScript(scriptData, outputPath, renderOptions);
|
|
99
|
-
console.log('done');
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
70
|
+
};
|
|
71
|
+
const visitor = validateScript(scriptData, scriptOptions);
|
|
72
|
+
const semanticTokensVisitor = getSemanticTokens(scriptData, scriptOptions);
|
|
103
73
|
}
|
|
104
|
-
|
|
105
|
-
main();
|
|
74
|
+
validate();
|