circuitscript 0.1.5 → 0.1.7
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 +127 -73
- package/dist/cjs/SemanticTokenVisitor.js +19 -13
- package/dist/cjs/antlr/CircuitScriptParser.js +711 -671
- package/dist/cjs/builtinMethods.js +29 -25
- package/dist/cjs/environment.js +118 -0
- package/dist/cjs/execute.js +53 -12
- package/dist/cjs/geometry.js +1 -0
- package/dist/cjs/globals.js +11 -6
- package/dist/cjs/helpers.js +135 -127
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/layout.js +37 -12
- package/dist/cjs/main.js +31 -19
- package/dist/cjs/objects/ExecutionScope.js +33 -0
- package/dist/cjs/objects/ParamDefinition.js +15 -15
- package/dist/cjs/parser.js +27 -21
- package/dist/cjs/regenerate-tests.js +9 -6
- package/dist/cjs/render.js +3 -1
- package/dist/cjs/sizing.js +5 -58
- package/dist/cjs/utils.js +85 -30
- package/dist/cjs/validate/SymbolTable.js +96 -0
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +14 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +170 -0
- package/dist/cjs/validate.js +52 -44
- package/dist/cjs/visitor.js +140 -24
- package/dist/esm/{BaseVisitor.mjs → BaseVisitor.js} +98 -45
- package/dist/esm/{SemanticTokenVisitor.mjs → SemanticTokenVisitor.js} +17 -11
- package/dist/esm/antlr/{CircuitScriptParser.mjs → CircuitScriptParser.js} +711 -671
- package/dist/esm/{builtinMethods.mjs → builtinMethods.js} +20 -16
- package/dist/esm/{draw_symbols.mjs → draw_symbols.js} +7 -7
- package/dist/esm/environment.js +110 -0
- package/dist/esm/{execute.mjs → execute.js} +66 -25
- package/dist/esm/{export.mjs → export.js} +2 -2
- package/dist/esm/{geometry.mjs → geometry.js} +6 -5
- package/dist/esm/{globals.mjs → globals.js} +6 -1
- package/dist/esm/helpers.js +377 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/{layout.mjs → layout.js} +42 -20
- package/dist/esm/{lexer.mjs → lexer.js} +2 -2
- package/dist/esm/{main.mjs → main.js} +33 -21
- package/dist/esm/objects/{ClassComponent.mjs → ClassComponent.js} +5 -4
- package/dist/esm/objects/{ExecutionScope.mjs → ExecutionScope.js} +33 -0
- package/dist/esm/objects/{Frame.mjs → Frame.js} +1 -1
- package/dist/esm/objects/{ParamDefinition.mjs → ParamDefinition.js} +1 -1
- package/dist/esm/objects/{PinDefinition.mjs → PinDefinition.js} +1 -1
- package/dist/esm/parser.js +71 -0
- package/dist/esm/{regenerate-tests.mjs → regenerate-tests.js} +10 -7
- package/dist/esm/{render.mjs → render.js} +11 -9
- package/dist/esm/{sizing.mjs → sizing.js} +6 -34
- package/dist/esm/{utils.mjs → utils.js} +61 -17
- package/dist/esm/validate/SymbolTable.js +90 -0
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +10 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +163 -0
- package/dist/esm/validate.js +86 -0
- package/dist/esm/{visitor.mjs → visitor.js} +151 -35
- package/dist/fonts/Arial.ttf +0 -0
- package/dist/fonts/Inter-Bold.ttf +0 -0
- package/dist/fonts/Inter-Regular.ttf +0 -0
- package/dist/fonts/OpenSans-Regular.ttf +0 -0
- package/dist/fonts/Roboto-Regular.ttf +0 -0
- package/dist/libs/lib.cst +423 -0
- package/dist/types/BaseVisitor.d.ts +34 -21
- package/dist/types/SemanticTokenVisitor.d.ts +6 -5
- package/dist/types/antlr/CircuitScriptParser.d.ts +4 -2
- package/dist/types/builtinMethods.d.ts +3 -2
- package/dist/types/environment.d.ts +31 -0
- package/dist/types/globals.d.ts +4 -1
- package/dist/types/helpers.d.ts +12 -14
- package/dist/types/index.d.ts +5 -0
- package/dist/types/objects/ClassComponent.d.ts +1 -0
- package/dist/types/objects/ExecutionScope.d.ts +11 -0
- package/dist/types/objects/types.d.ts +6 -1
- package/dist/types/parser.d.ts +7 -11
- package/dist/types/sizing.d.ts +0 -3
- package/dist/types/utils.d.ts +30 -6
- package/dist/types/validate/SymbolTable.d.ts +40 -0
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +7 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +32 -0
- package/dist/types/validate.d.ts +1 -1
- package/package.json +14 -13
- package/dist/cjs/SymbolValidatorVisitor.js +0 -233
- package/dist/esm/SymbolValidatorVisitor.mjs +0 -222
- package/dist/esm/helpers.mjs +0 -364
- package/dist/esm/index.mjs +0 -15
- package/dist/esm/parser.mjs +0 -64
- package/dist/esm/validate.mjs +0 -74
- package/dist/types/SymbolValidatorVisitor.d.ts +0 -61
- package/dist/types/layout.d.ts +0 -148
- /package/dist/esm/antlr/{CircuitScriptLexer.mjs → CircuitScriptLexer.js} +0 -0
- /package/dist/esm/antlr/{CircuitScriptVisitor.mjs → CircuitScriptVisitor.js} +0 -0
- /package/dist/esm/{fonts.mjs → fonts.js} +0 -0
- /package/dist/esm/{logger.mjs → logger.js} +0 -0
- /package/dist/esm/objects/{Net.mjs → Net.js} +0 -0
- /package/dist/esm/objects/{PinTypes.mjs → PinTypes.js} +0 -0
- /package/dist/esm/objects/{Wire.mjs → Wire.js} +0 -0
- /package/dist/esm/objects/{types.mjs → types.js} +0 -0
- /package/dist/esm/{server.mjs → server.js} +0 -0
package/dist/cjs/helpers.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPaperSize = exports.isSupportedPaperSize = exports.PaperGridReferences = exports.pxToMM = exports.milsToMM = exports.UnitDimension = exports.
|
|
6
|
+
exports.getPaperSize = exports.isSupportedPaperSize = exports.PaperGridReferences = exports.pxToMM = exports.milsToMM = exports.UnitDimension = exports.detectJSModuleType = exports.renderScript = exports.validateScript = exports.ParseErrorStrategy = exports.getSemanticTokens = exports.prepareFile = exports.JSModuleType = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const pdfkit_1 = __importDefault(require("pdfkit"));
|
|
@@ -13,8 +13,8 @@ const parser_js_1 = require("./parser.js");
|
|
|
13
13
|
const render_js_1 = require("./render.js");
|
|
14
14
|
const utils_js_1 = require("./utils.js");
|
|
15
15
|
const visitor_js_1 = require("./visitor.js");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const SymbolValidatorVisitor_js_1 = require("./validate/SymbolValidatorVisitor.js");
|
|
17
|
+
const SymbolValidatorResolveVisitor_js_1 = require("./validate/SymbolValidatorResolveVisitor.js");
|
|
18
18
|
const antlr4ng_1 = require("antlr4ng");
|
|
19
19
|
const lexer_js_1 = require("./lexer.js");
|
|
20
20
|
const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
|
|
@@ -44,22 +44,12 @@ function prepareFile(textData) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
exports.prepareFile = prepareFile;
|
|
47
|
-
function
|
|
48
|
-
try {
|
|
49
|
-
return (0, fs_1.readFileSync)(filePath, { encoding: 'utf-8' });
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.getScriptText = getScriptText;
|
|
56
|
-
function getSemanticTokens(scriptData, options) {
|
|
47
|
+
async function getSemanticTokens(scriptData, options) {
|
|
57
48
|
const { parser, lexer, tokens } = prepareFile(scriptData);
|
|
58
49
|
const tree = parser.script();
|
|
59
|
-
const
|
|
60
|
-
const visitor = new SemanticTokenVisitor_js_1.SemanticTokensVisitor(true, null, currentDirectory, defaultLibsPath, lexer, scriptData);
|
|
50
|
+
const visitor = new SemanticTokenVisitor_js_1.SemanticTokensVisitor(true, null, options.environment, lexer, scriptData);
|
|
61
51
|
parser.removeErrorListeners();
|
|
62
|
-
visitor.onImportFile = (visitor, textData) => {
|
|
52
|
+
visitor.onImportFile = async (visitor, filePath, textData) => {
|
|
63
53
|
let hasError = false;
|
|
64
54
|
let hasParseError = false;
|
|
65
55
|
if (textData !== null) {
|
|
@@ -72,6 +62,7 @@ function getSemanticTokens(scriptData, options) {
|
|
|
72
62
|
console.log('Error while parsing: ', err);
|
|
73
63
|
hasParseError = true;
|
|
74
64
|
hasError = true;
|
|
65
|
+
throw new utils_js_1.ParseError(`Error parsing semantic tokens in imported file: ${err}`);
|
|
75
66
|
}
|
|
76
67
|
}
|
|
77
68
|
else {
|
|
@@ -82,7 +73,7 @@ function getSemanticTokens(scriptData, options) {
|
|
|
82
73
|
hasError, hasParseError
|
|
83
74
|
};
|
|
84
75
|
};
|
|
85
|
-
visitor.
|
|
76
|
+
await visitor.visitAsync(tree);
|
|
86
77
|
const semanticTokens = visitor.getTokens();
|
|
87
78
|
const parsedTokens = (0, SemanticTokenVisitor_js_1.prepareTokens)(tokens.getTokens(), lexer, scriptData);
|
|
88
79
|
const finalParsedTokens = [];
|
|
@@ -120,27 +111,30 @@ class ParseErrorStrategy extends antlr4ng_1.DefaultErrorStrategy {
|
|
|
120
111
|
}
|
|
121
112
|
}
|
|
122
113
|
exports.ParseErrorStrategy = ParseErrorStrategy;
|
|
123
|
-
function validateScript(scriptData, options) {
|
|
114
|
+
async function validateScript(filePath, scriptData, options) {
|
|
124
115
|
const { parser } = prepareFile(scriptData);
|
|
125
116
|
parser.removeErrorListeners();
|
|
126
117
|
parser.errorHandler = new ParseErrorStrategy();
|
|
127
118
|
parser.addErrorListener(new TokenErrorListener());
|
|
128
119
|
const tree = parser.script();
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
visitor.onImportFile = (visitor, textData) => {
|
|
120
|
+
const visitor = new SymbolValidatorVisitor_js_1.SymbolValidatorVisitor(true, null, options.environment);
|
|
121
|
+
visitor.enterFile(filePath);
|
|
122
|
+
visitor.onImportFile = async (visitor, filePath, textData) => {
|
|
123
|
+
visitor.enterFile(filePath);
|
|
132
124
|
let hasError = false;
|
|
133
125
|
let hasParseError = false;
|
|
134
126
|
if (textData !== null) {
|
|
135
127
|
const { parser } = prepareFile(textData);
|
|
136
128
|
const tree = parser.script();
|
|
137
129
|
try {
|
|
138
|
-
visitor.
|
|
130
|
+
await visitor.visitAsync(tree);
|
|
131
|
+
visitor.exitFile();
|
|
139
132
|
}
|
|
140
133
|
catch (err) {
|
|
141
134
|
console.log('got an error while parsing tree: ', err);
|
|
142
135
|
hasParseError = true;
|
|
143
136
|
hasError = true;
|
|
137
|
+
throw new utils_js_1.ParseError(`Error parsing validation in imported file: ${err}`);
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
else {
|
|
@@ -151,120 +145,160 @@ function validateScript(scriptData, options) {
|
|
|
151
145
|
hasError, hasParseError
|
|
152
146
|
};
|
|
153
147
|
};
|
|
154
|
-
visitor.
|
|
148
|
+
await visitor.visitAsync(tree);
|
|
155
149
|
const symbolTable = visitor.getSymbols();
|
|
156
150
|
symbolTable.clearUndefined();
|
|
157
|
-
const visitorResolver = new
|
|
151
|
+
const visitorResolver = new SymbolValidatorResolveVisitor_js_1.SymbolValidatorResolveVisitor(true, null, options.environment);
|
|
152
|
+
visitorResolver.enterFile(filePath);
|
|
158
153
|
visitorResolver.setSymbols(visitor.getSymbols());
|
|
159
154
|
visitorResolver.onImportFile = visitor.onImportFile;
|
|
160
|
-
visitorResolver.
|
|
155
|
+
await visitorResolver.visitAsync(tree);
|
|
161
156
|
return visitorResolver;
|
|
162
157
|
}
|
|
163
158
|
exports.validateScript = validateScript;
|
|
164
|
-
function renderScript(scriptData, outputPath, options) {
|
|
165
|
-
const {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
async function renderScript(scriptData, outputPath, options) {
|
|
160
|
+
const { dumpNets = false, dumpData = false, showStats = false, environment } = options;
|
|
161
|
+
const errors = [];
|
|
162
|
+
const onErrorHandler = (message, context, error) => {
|
|
163
|
+
if (error && error instanceof utils_js_1.RuntimeExecutionError) {
|
|
164
|
+
errors.push(error);
|
|
165
|
+
}
|
|
166
|
+
else if (error && error instanceof antlr4ng_1.RecognitionException) {
|
|
167
|
+
errors.push(new utils_js_1.ParseSyntaxError(message, context.start, context.stop));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
errors.push(new utils_js_1.ParseError(message, context.start, context.stop));
|
|
169
171
|
}
|
|
170
172
|
};
|
|
171
|
-
const visitor = new visitor_js_1.ParserVisitor(true, onErrorHandler,
|
|
172
|
-
visitor.onImportFile = (visitor, fileData) => {
|
|
173
|
-
const { hasError, hasParseError } = (0, parser_js_1.parseFileWithVisitor)(visitor, fileData);
|
|
173
|
+
const visitor = new visitor_js_1.ParserVisitor(true, onErrorHandler, options.environment);
|
|
174
|
+
visitor.onImportFile = async (visitor, filePath, fileData) => {
|
|
175
|
+
const { hasError, hasParseError } = await (0, parser_js_1.parseFileWithVisitor)(visitor, fileData);
|
|
176
|
+
if (hasError || hasParseError) {
|
|
177
|
+
throw new utils_js_1.ParseError(`Error parsing imported file: ${filePath}`, undefined, undefined, filePath);
|
|
178
|
+
}
|
|
174
179
|
return { hasError, hasParseError };
|
|
175
180
|
};
|
|
176
181
|
visitor.log('reading file');
|
|
177
182
|
visitor.log('done reading file');
|
|
178
|
-
const { tree, parser,
|
|
183
|
+
const { tree, parser, parserTimeTaken, lexerTimeTaken } = await (0, parser_js_1.parseFileWithVisitor)(visitor, scriptData);
|
|
179
184
|
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
180
185
|
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
181
186
|
if (dumpNets) {
|
|
182
187
|
const nets = visitor.dumpNets();
|
|
183
188
|
nets.forEach(item => console.log(item.join(" | ")));
|
|
184
189
|
}
|
|
185
|
-
const dumpDirectory =
|
|
190
|
+
const dumpDirectory = environment.getRelativeToModule('/dump/');
|
|
186
191
|
if (dumpData) {
|
|
192
|
+
console.log('Dump data to:', dumpDirectory);
|
|
187
193
|
if (!(0, fs_1.existsSync)(dumpDirectory)) {
|
|
188
194
|
(0, fs_1.mkdirSync)(dumpDirectory);
|
|
189
195
|
}
|
|
190
196
|
}
|
|
191
197
|
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
|
|
192
198
|
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
|
|
193
|
-
if (hasError || hasParseError) {
|
|
194
|
-
console.log('Error while parsing');
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
const { frameComponent } = visitor.applySheetFrameComponent();
|
|
198
|
-
try {
|
|
199
|
-
visitor.annotateComponents();
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
console.log('Error during annotation: ', err);
|
|
203
|
-
}
|
|
204
|
-
const { sequence, nets } = visitor.getGraph();
|
|
205
|
-
const tmpSequence = (0, utils_js_1.generateDebugSequenceAction)(sequence).map(item => (0, utils_js_1.sequenceActionString)(item));
|
|
206
|
-
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
|
|
207
199
|
let svgOutput = "";
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
fileExtension = path_1.default.extname(outputPath).substring(1);
|
|
213
|
-
if (fileExtension === "pdf") {
|
|
214
|
-
outputDefaultZoom = 1;
|
|
215
|
-
}
|
|
200
|
+
if (errors.length === 0) {
|
|
201
|
+
const { frameComponent } = visitor.applySheetFrameComponent();
|
|
202
|
+
try {
|
|
203
|
+
visitor.annotateComponents();
|
|
216
204
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
missingFootprints.forEach(entry => {
|
|
220
|
-
console.log(`${entry.refdes} (${entry.instanceName}) does not have footprint`);
|
|
221
|
-
});
|
|
222
|
-
(0, fs_1.writeFileSync)(outputPath, (0, export_js_1.printTree)(kicadNetList));
|
|
223
|
-
console.log('Generated file', outputPath);
|
|
224
|
-
return null;
|
|
205
|
+
catch (err) {
|
|
206
|
+
throw new utils_js_1.RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
225
207
|
}
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-render.txt', renderLogger.dump());
|
|
237
|
-
svgOutput = (0, render_js_1.generateSvgOutput)(svgCanvas, outputDefaultZoom);
|
|
238
|
-
if (outputPath) {
|
|
239
|
-
if (fileExtension === 'svg') {
|
|
240
|
-
(0, fs_1.writeFileSync)(outputPath, svgOutput);
|
|
241
|
-
}
|
|
242
|
-
else if (fileExtension === 'pdf') {
|
|
243
|
-
let sheetSize = "A4";
|
|
244
|
-
let sheetSizeDefined = false;
|
|
245
|
-
if (frameComponent) {
|
|
246
|
-
sheetSize = frameComponent.getParam(Frame_js_1.FrameParamKeys.PaperSize);
|
|
247
|
-
sheetSizeDefined = true;
|
|
208
|
+
const { sequence, nets } = visitor.getGraph();
|
|
209
|
+
const tmpSequence = (0, utils_js_1.generateDebugSequenceAction)(sequence).map(item => (0, utils_js_1.sequenceActionString)(item));
|
|
210
|
+
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
|
|
211
|
+
try {
|
|
212
|
+
let fileExtension = null;
|
|
213
|
+
let outputDefaultZoom = globals_js_1.defaultZoomScale;
|
|
214
|
+
if (outputPath) {
|
|
215
|
+
fileExtension = path_1.default.extname(outputPath).substring(1);
|
|
216
|
+
if (fileExtension === "pdf") {
|
|
217
|
+
outputDefaultZoom = 1;
|
|
248
218
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
219
|
+
}
|
|
220
|
+
if (fileExtension === 'net') {
|
|
221
|
+
const { tree: kicadNetList, missingFootprints } = (0, export_js_1.generateKiCADNetList)(visitor.getNetList());
|
|
222
|
+
missingFootprints.forEach(entry => {
|
|
223
|
+
console.log(`${entry.refdes} (${entry.instanceName}) does not have footprint`);
|
|
252
224
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
225
|
+
(0, fs_1.writeFileSync)(outputPath, (0, export_js_1.printTree)(kicadNetList));
|
|
226
|
+
console.log('Generated file', outputPath);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
const layoutEngine = new layout_js_1.LayoutEngine();
|
|
230
|
+
const layoutTimer = new utils_js_1.SimpleStopwatch();
|
|
231
|
+
let sheetFrames;
|
|
232
|
+
try {
|
|
233
|
+
sheetFrames = layoutEngine.runLayout(sequence, nets);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
throw new utils_js_1.RenderError(`Error during layout generation: ${err}`, 'layout');
|
|
237
|
+
}
|
|
238
|
+
layoutEngine.printWarnings();
|
|
239
|
+
showStats && console.log('Layout took:', layoutTimer.lap());
|
|
240
|
+
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
|
|
241
|
+
const generateSvgTimer = new utils_js_1.SimpleStopwatch();
|
|
242
|
+
const renderLogger = new logger_js_1.Logger();
|
|
243
|
+
let svgCanvas;
|
|
244
|
+
try {
|
|
245
|
+
svgCanvas = (0, render_js_1.renderSheetsToSVG)(sheetFrames, renderLogger);
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
throw new utils_js_1.RenderError(`Error during SVG generation: ${err}`, 'svg_generation');
|
|
249
|
+
}
|
|
250
|
+
showStats && console.log('Render took:', generateSvgTimer.lap());
|
|
251
|
+
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-render.txt', renderLogger.dump());
|
|
252
|
+
try {
|
|
253
|
+
svgOutput = (0, render_js_1.generateSvgOutput)(svgCanvas, outputDefaultZoom);
|
|
257
254
|
}
|
|
258
|
-
|
|
259
|
-
throw
|
|
255
|
+
catch (err) {
|
|
256
|
+
throw new utils_js_1.RenderError(`Error generating SVG output: ${err}`, 'svg_output');
|
|
257
|
+
}
|
|
258
|
+
if (outputPath) {
|
|
259
|
+
if (fileExtension === 'svg') {
|
|
260
|
+
try {
|
|
261
|
+
(0, fs_1.writeFileSync)(outputPath, svgOutput);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
throw new utils_js_1.RenderError(`Error writing SVG file: ${err}`, 'file_output');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else if (fileExtension === 'pdf') {
|
|
268
|
+
let sheetSize = "A4";
|
|
269
|
+
let sheetSizeDefined = false;
|
|
270
|
+
if (frameComponent) {
|
|
271
|
+
sheetSize = frameComponent.getParam(Frame_js_1.FrameParamKeys.PaperSize);
|
|
272
|
+
sheetSizeDefined = true;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
const doc = new pdfkit_1.default({
|
|
276
|
+
layout: 'landscape',
|
|
277
|
+
size: sheetSize
|
|
278
|
+
});
|
|
279
|
+
const outputStream = (0, fs_1.createWriteStream)(outputPath);
|
|
280
|
+
(0, render_js_1.generatePdfOutput)(doc, svgCanvas, sheetSize, sheetSizeDefined, outputDefaultZoom);
|
|
281
|
+
doc.pipe(outputStream);
|
|
282
|
+
doc.end();
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
throw new utils_js_1.RenderError(`Error generating PDF file: ${err}`, 'pdf_output');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
throw new utils_js_1.RenderError(`Invalid output format: ${fileExtension}`, 'file_output');
|
|
290
|
+
}
|
|
291
|
+
console.log('Generated file', outputPath);
|
|
260
292
|
}
|
|
261
|
-
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
throw new utils_js_1.RenderError(`Error during rendering: ${err}`, 'output_generation');
|
|
262
296
|
}
|
|
263
297
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
298
|
+
return {
|
|
299
|
+
svgOutput,
|
|
300
|
+
errors
|
|
301
|
+
};
|
|
268
302
|
}
|
|
269
303
|
exports.renderScript = renderScript;
|
|
270
304
|
function detectJSModuleType() {
|
|
@@ -277,32 +311,6 @@ function detectJSModuleType() {
|
|
|
277
311
|
}
|
|
278
312
|
}
|
|
279
313
|
exports.detectJSModuleType = detectJSModuleType;
|
|
280
|
-
const context = (0, this_file_1.createContext)();
|
|
281
|
-
function getCurrentPath() {
|
|
282
|
-
const filename = context.filename;
|
|
283
|
-
return { filePath: filename };
|
|
284
|
-
}
|
|
285
|
-
exports.getCurrentPath = getCurrentPath;
|
|
286
|
-
function getToolsPath() {
|
|
287
|
-
const { filePath } = getCurrentPath();
|
|
288
|
-
return path_1.default.normalize(path_1.default.dirname(filePath) + '/../../');
|
|
289
|
-
}
|
|
290
|
-
function getFontsPath() {
|
|
291
|
-
const toolsPath = getToolsPath();
|
|
292
|
-
return path_1.default.normalize(toolsPath + "fonts");
|
|
293
|
-
}
|
|
294
|
-
exports.getFontsPath = getFontsPath;
|
|
295
|
-
function getDefaultLibsPath() {
|
|
296
|
-
const toolsPath = getToolsPath();
|
|
297
|
-
return path_1.default.normalize(toolsPath + "libs");
|
|
298
|
-
}
|
|
299
|
-
exports.getDefaultLibsPath = getDefaultLibsPath;
|
|
300
|
-
function getPackageVersion() {
|
|
301
|
-
const packageJson = JSON.parse((0, fs_1.readFileSync)(getToolsPath() + 'package.json').toString());
|
|
302
|
-
const { version } = packageJson;
|
|
303
|
-
return version;
|
|
304
|
-
}
|
|
305
|
-
exports.getPackageVersion = getPackageVersion;
|
|
306
314
|
class UnitDimension {
|
|
307
315
|
constructor(value, type = globals_js_1.LengthUnit.mils) {
|
|
308
316
|
this.value = value;
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,3 +29,8 @@ __exportStar(require("./utils.js"), exports);
|
|
|
29
29
|
__exportStar(require("./visitor.js"), exports);
|
|
30
30
|
__exportStar(require("./sizing.js"), exports);
|
|
31
31
|
__exportStar(require("./objects/types.js"), exports);
|
|
32
|
+
__exportStar(require("./builtinMethods.js"), exports);
|
|
33
|
+
__exportStar(require("./validate/SymbolTable.js"), exports);
|
|
34
|
+
__exportStar(require("./validate/SymbolValidatorResolveVisitor.js"), exports);
|
|
35
|
+
__exportStar(require("./validate/SymbolValidatorVisitor.js"), exports);
|
|
36
|
+
__exportStar(require("./environment.js"), exports);
|
package/dist/cjs/layout.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ExtractDrawingRects = exports.CalculatePinPositions = exports.RenderJunction = exports.RenderFrameType = exports.RenderFrame = exports.RenderText = exports.RenderComponent = exports.RenderWire = exports.RenderObject = exports.getBounds = exports.applyComponentParamsToSymbol = exports.LayoutEngine = void 0;
|
|
4
|
-
const graphlib_1 = require("@dagrejs/graphlib");
|
|
7
|
+
const graphlib_1 = __importDefault(require("@dagrejs/graphlib"));
|
|
8
|
+
const { Graph, alg } = graphlib_1.default;
|
|
5
9
|
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
6
10
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
7
11
|
const globals_js_1 = require("./globals.js");
|
|
@@ -111,6 +115,7 @@ class LayoutEngine {
|
|
|
111
115
|
findJunctions(wireGroups) {
|
|
112
116
|
const junctions = [];
|
|
113
117
|
const mergedWires = [];
|
|
118
|
+
const debugSegments = false;
|
|
114
119
|
for (const [key, wires] of wireGroups) {
|
|
115
120
|
const allLines = wires.map(wire => {
|
|
116
121
|
return wire.points.map(pt => {
|
|
@@ -120,15 +125,35 @@ class LayoutEngine {
|
|
|
120
125
|
};
|
|
121
126
|
});
|
|
122
127
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
if (debugSegments) {
|
|
129
|
+
const tmpSegments = [];
|
|
130
|
+
allLines.forEach(wire => {
|
|
131
|
+
for (let i = 1; i < wire.length; i++) {
|
|
132
|
+
const pt1 = wire[i - 1];
|
|
133
|
+
const pt2 = wire[i];
|
|
134
|
+
tmpSegments.push([
|
|
135
|
+
[pt1.x.toNumber(), pt1.y.toNumber()],
|
|
136
|
+
[pt2.x.toNumber(), pt2.y.toNumber()],
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
mergedWires.push({
|
|
141
|
+
netName: key,
|
|
142
|
+
segments: tmpSegments,
|
|
143
|
+
intersectPoints: [],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
const { intersectPoints, segments } = geometry_js_1.Geometry.mergeWires(allLines);
|
|
148
|
+
mergedWires.push({
|
|
149
|
+
netName: key,
|
|
150
|
+
segments,
|
|
151
|
+
intersectPoints,
|
|
152
|
+
});
|
|
153
|
+
intersectPoints.forEach(([x, y]) => {
|
|
154
|
+
junctions.push(new RenderJunction((0, ParamDefinition_js_1.numeric)(x), (0, ParamDefinition_js_1.numeric)(y)));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
132
157
|
}
|
|
133
158
|
return {
|
|
134
159
|
junctions,
|
|
@@ -585,7 +610,7 @@ class LayoutEngine {
|
|
|
585
610
|
generateLayoutGraph(sequence, nets) {
|
|
586
611
|
let previousNode = null;
|
|
587
612
|
let previousPin = null;
|
|
588
|
-
const graph = new
|
|
613
|
+
const graph = new Graph({
|
|
589
614
|
directed: false,
|
|
590
615
|
compound: true,
|
|
591
616
|
});
|
|
@@ -748,7 +773,7 @@ class LayoutEngine {
|
|
|
748
773
|
graph.setEdge(node1, node2, edgeValue);
|
|
749
774
|
}
|
|
750
775
|
sizeSubGraphs(graph) {
|
|
751
|
-
const subGraphs =
|
|
776
|
+
const subGraphs = alg.components(graph);
|
|
752
777
|
const subGraphsStarts = [];
|
|
753
778
|
this.print('===== placing subgraphs =====');
|
|
754
779
|
this.print('number of subgraphs: ', subGraphs.length);
|
package/dist/cjs/main.js
CHANGED
|
@@ -6,14 +6,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
8
|
const figlet_1 = __importDefault(require("figlet"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
9
|
const fs_1 = require("fs");
|
|
11
|
-
const sizing_js_1 = require("./sizing.js");
|
|
12
10
|
const helpers_js_1 = require("./helpers.js");
|
|
11
|
+
const environment_js_1 = require("./environment.js");
|
|
13
12
|
async function main() {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const version =
|
|
13
|
+
const env = new environment_js_1.NodeScriptEnvironment();
|
|
14
|
+
environment_js_1.NodeScriptEnvironment.setInstance(env);
|
|
15
|
+
const version = env.getPackageVersion();
|
|
17
16
|
commander_1.program
|
|
18
17
|
.description('generate graphical output from circuitscript files')
|
|
19
18
|
.version(version)
|
|
@@ -38,11 +37,13 @@ async function main() {
|
|
|
38
37
|
const watchFileChanges = options.watch;
|
|
39
38
|
const dumpNets = options.dumpNets;
|
|
40
39
|
const dumpData = options.dumpData;
|
|
41
|
-
|
|
40
|
+
if (options.currentDirectory) {
|
|
41
|
+
throw "Parameter not supported yet";
|
|
42
|
+
}
|
|
42
43
|
if (watchFileChanges) {
|
|
43
44
|
console.log('watching for file changes...');
|
|
44
45
|
}
|
|
45
|
-
await
|
|
46
|
+
await env.prepareSVGEnvironment();
|
|
46
47
|
let inputFilePath = "";
|
|
47
48
|
if (args.length > 2) {
|
|
48
49
|
console.log("Error: Extra arguments passed");
|
|
@@ -51,11 +52,8 @@ async function main() {
|
|
|
51
52
|
let scriptData;
|
|
52
53
|
if (args.length > 0 && args[0]) {
|
|
53
54
|
inputFilePath = args[0];
|
|
54
|
-
if ((
|
|
55
|
-
scriptData =
|
|
56
|
-
if (currentDirectory === null) {
|
|
57
|
-
currentDirectory = path_1.default.dirname(inputFilePath);
|
|
58
|
-
}
|
|
55
|
+
if ((await env.exists(inputFilePath))) {
|
|
56
|
+
scriptData = await env.readFile(inputFilePath, { encoding: 'utf-8' });
|
|
59
57
|
}
|
|
60
58
|
else {
|
|
61
59
|
console.error("Error: File could not be found");
|
|
@@ -70,29 +68,43 @@ async function main() {
|
|
|
70
68
|
return;
|
|
71
69
|
}
|
|
72
70
|
const scriptOptions = {
|
|
73
|
-
currentDirectory,
|
|
74
|
-
defaultLibsPath,
|
|
75
71
|
dumpNets,
|
|
76
72
|
dumpData,
|
|
77
73
|
showStats: options.stats,
|
|
74
|
+
environment: env,
|
|
78
75
|
};
|
|
79
76
|
let outputPath = null;
|
|
80
77
|
if (args.length > 0 && args[1]) {
|
|
81
78
|
outputPath = args[1];
|
|
82
79
|
}
|
|
83
|
-
const output =
|
|
80
|
+
const output = await parseFile(scriptData, outputPath, scriptOptions);
|
|
84
81
|
if (outputPath === null && output && (options.skipOutput === undefined)) {
|
|
85
82
|
console.log(output);
|
|
86
83
|
}
|
|
87
84
|
if (watchFileChanges) {
|
|
88
|
-
(0, fs_1.watch)(inputFilePath, event => {
|
|
85
|
+
(0, fs_1.watch)(inputFilePath, async (event) => {
|
|
89
86
|
if (event === 'change') {
|
|
90
|
-
const scriptData =
|
|
91
|
-
(
|
|
92
|
-
console.log('done');
|
|
87
|
+
const scriptData = await env.readFile(inputFilePath, { encoding: 'utf-8' });
|
|
88
|
+
parseFile(scriptData, outputPath, scriptOptions);
|
|
93
89
|
}
|
|
94
90
|
});
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
93
|
exports.default = main;
|
|
94
|
+
async function parseFile(scriptData, outputPath, scriptOptions) {
|
|
95
|
+
try {
|
|
96
|
+
const { svgOutput: output, errors } = await (0, helpers_js_1.renderScript)(scriptData, outputPath, scriptOptions);
|
|
97
|
+
errors.forEach((err, index) => {
|
|
98
|
+
console.log(`[${index}] ${err}`);
|
|
99
|
+
});
|
|
100
|
+
if (errors.length > 0) {
|
|
101
|
+
console.log('Render failed due to syntax or parsing errors');
|
|
102
|
+
}
|
|
103
|
+
return output;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error(`Unexpected Error: ${error}`);
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
98
110
|
main();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActiveObject = exports.FrameAction = exports.SequenceAction = exports.ExecutionScope = void 0;
|
|
4
|
+
const CircuitScriptParser_js_1 = require("../antlr/CircuitScriptParser.js");
|
|
4
5
|
class ExecutionScope {
|
|
5
6
|
constructor(scopeId) {
|
|
6
7
|
this.nets = [];
|
|
@@ -9,6 +10,8 @@ class ExecutionScope {
|
|
|
9
10
|
this.variables = new Map();
|
|
10
11
|
this.symbols = new Map();
|
|
11
12
|
this.blockStack = new Map();
|
|
13
|
+
this.contextStack = [];
|
|
14
|
+
this.onPropertyHandler = [];
|
|
12
15
|
this.breakStack = [];
|
|
13
16
|
this.wires = [];
|
|
14
17
|
this.frames = [];
|
|
@@ -123,6 +126,36 @@ class ExecutionScope {
|
|
|
123
126
|
this.currentPin = null;
|
|
124
127
|
}
|
|
125
128
|
}
|
|
129
|
+
enterContext(context) {
|
|
130
|
+
this.contextStack.push(context);
|
|
131
|
+
}
|
|
132
|
+
exitContext() {
|
|
133
|
+
return this.contextStack.pop();
|
|
134
|
+
}
|
|
135
|
+
findPropertyKeyTree() {
|
|
136
|
+
const keyNames = [];
|
|
137
|
+
for (let i = this.contextStack.length - 1; i >= 0; i--) {
|
|
138
|
+
const ctx = this.contextStack[i];
|
|
139
|
+
if (ctx instanceof CircuitScriptParser_js_1.Property_key_exprContext) {
|
|
140
|
+
keyNames.push([ctx, ctx.getText()]);
|
|
141
|
+
}
|
|
142
|
+
else if (typeof ctx === 'number') {
|
|
143
|
+
keyNames.push(['index', ctx]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return keyNames.reverse();
|
|
147
|
+
}
|
|
148
|
+
setOnPropertyHandler(handler) {
|
|
149
|
+
this.onPropertyHandler.push(handler);
|
|
150
|
+
}
|
|
151
|
+
popOnPropertyHandler() {
|
|
152
|
+
return this.onPropertyHandler.pop();
|
|
153
|
+
}
|
|
154
|
+
triggerPropertyHandler(value, valueCtx) {
|
|
155
|
+
const lastHandler = this.onPropertyHandler[this.onPropertyHandler.length - 1];
|
|
156
|
+
const propertyTree = this.findPropertyKeyTree();
|
|
157
|
+
lastHandler && lastHandler(propertyTree, value, valueCtx);
|
|
158
|
+
}
|
|
126
159
|
}
|
|
127
160
|
exports.ExecutionScope = ExecutionScope;
|
|
128
161
|
ExecutionScope.scopeId = 0;
|