circuitscript 0.5.3 → 0.5.5

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.
Files changed (74) hide show
  1. package/dist/cjs/BaseVisitor.js +11 -10
  2. package/dist/cjs/annotate/ComponentAnnotater.js +3 -2
  3. package/dist/cjs/builtinMethods.js +6 -5
  4. package/dist/cjs/environment/environment.js +2 -2
  5. package/dist/cjs/errors.js +140 -0
  6. package/dist/cjs/execute.js +12 -5
  7. package/dist/cjs/globals.js +10 -6
  8. package/dist/cjs/main.js +3 -2
  9. package/dist/cjs/objects/ClassComponent.js +4 -4
  10. package/dist/cjs/objects/ExecutionScope.js +2 -2
  11. package/dist/cjs/objects/Frame.js +7 -0
  12. package/dist/cjs/objects/NumericValue.js +15 -0
  13. package/dist/cjs/objects/PinDefinition.js +2 -2
  14. package/dist/cjs/objects/types.js +2 -2
  15. package/dist/cjs/parser.js +3 -2
  16. package/dist/cjs/pipeline.js +25 -15
  17. package/dist/cjs/regenerate-tests.js +6 -6
  18. package/dist/cjs/render/draw_symbols.js +40 -25
  19. package/dist/cjs/render/geometry.js +6 -6
  20. package/dist/cjs/render/graph.js +4 -0
  21. package/dist/cjs/render/layout.js +325 -253
  22. package/dist/cjs/render/render.js +38 -24
  23. package/dist/cjs/semantic-tokens/getSemanticTokens.js +2 -2
  24. package/dist/cjs/sizing.js +2 -2
  25. package/dist/cjs/styles.js +19 -0
  26. package/dist/cjs/utils.js +13 -110
  27. package/dist/cjs/validate/validateScript.js +2 -2
  28. package/dist/cjs/visitor.js +14 -12
  29. package/dist/esm/BaseVisitor.js +2 -1
  30. package/dist/esm/annotate/ComponentAnnotater.js +3 -2
  31. package/dist/esm/builtinMethods.js +6 -5
  32. package/dist/esm/environment/environment.js +1 -1
  33. package/dist/esm/errors.js +119 -0
  34. package/dist/esm/execute.js +10 -3
  35. package/dist/esm/globals.js +8 -4
  36. package/dist/esm/main.js +3 -2
  37. package/dist/esm/objects/ClassComponent.js +1 -1
  38. package/dist/esm/objects/ExecutionScope.js +1 -1
  39. package/dist/esm/objects/Frame.js +7 -0
  40. package/dist/esm/objects/NumericValue.js +15 -0
  41. package/dist/esm/objects/PinDefinition.js +1 -1
  42. package/dist/esm/objects/types.js +1 -1
  43. package/dist/esm/parser.js +2 -1
  44. package/dist/esm/pipeline.js +14 -4
  45. package/dist/esm/regenerate-tests.js +6 -6
  46. package/dist/esm/render/draw_symbols.js +41 -24
  47. package/dist/esm/render/geometry.js +6 -6
  48. package/dist/esm/render/graph.js +5 -0
  49. package/dist/esm/render/layout.js +325 -253
  50. package/dist/esm/render/render.js +38 -24
  51. package/dist/esm/semantic-tokens/getSemanticTokens.js +1 -1
  52. package/dist/esm/sizing.js +2 -2
  53. package/dist/esm/styles.js +20 -0
  54. package/dist/esm/utils.js +10 -95
  55. package/dist/esm/validate/validateScript.js +1 -1
  56. package/dist/esm/visitor.js +4 -2
  57. package/dist/libs/std.cst +37 -37
  58. package/dist/types/BaseVisitor.d.ts +3 -1
  59. package/dist/types/errors.d.ts +37 -0
  60. package/dist/types/execute.d.ts +1 -1
  61. package/dist/types/globals.d.ts +8 -4
  62. package/dist/types/helpers.d.ts +1 -1
  63. package/dist/types/objects/Frame.d.ts +7 -0
  64. package/dist/types/objects/NumericValue.d.ts +5 -1
  65. package/dist/types/render/draw_symbols.d.ts +8 -3
  66. package/dist/types/render/geometry.d.ts +4 -4
  67. package/dist/types/render/graph.d.ts +3 -0
  68. package/dist/types/render/layout.d.ts +7 -1
  69. package/dist/types/render/render.d.ts +2 -1
  70. package/dist/types/styles.d.ts +11 -0
  71. package/dist/types/utils.d.ts +2 -27
  72. package/dist/types/visitor.d.ts +1 -1
  73. package/libs/std.cst +37 -37
  74. package/package.json +1 -1
@@ -14,7 +14,7 @@ const types_js_1 = require("./objects/types.js");
14
14
  const globals_js_1 = require("./globals.js");
15
15
  const utils_js_1 = require("./utils.js");
16
16
  const builtinMethods_js_1 = require("./builtinMethods.js");
17
- const utils_js_2 = require("./utils.js");
17
+ const errors_js_1 = require("./errors.js");
18
18
  const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
19
19
  const hash_js_1 = require("./cache/hash.js");
20
20
  const storage_js_1 = require("./cache/storage.js");
@@ -34,6 +34,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
34
34
  types_js_1.Direction.Right, types_js_1.Direction.Left];
35
35
  this.resultData = new Map;
36
36
  this.componentCtxLinks = new Map;
37
+ this.wireCtxLinks = new Map;
37
38
  this.onErrorHandler = null;
38
39
  this.importedFiles = [];
39
40
  this.warnings = [];
@@ -312,7 +313,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
312
313
  this.setResult(ctx, returnList);
313
314
  };
314
315
  this.visitImport_expr = (ctx) => {
315
- throw new utils_js_2.RuntimeExecutionError("Cannot parse imports here", ctx);
316
+ throw new errors_js_1.RuntimeExecutionError("Cannot parse imports here", ctx);
316
317
  };
317
318
  this.visitFunction_return_expr = (ctx) => {
318
319
  const executor = this.getExecutor();
@@ -360,14 +361,14 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
360
361
  const arrayItem = this.visitResult(ctxArray);
361
362
  const indexValue = this.visitResult(ctxArrayIndex);
362
363
  if (!Array.isArray(arrayItem)) {
363
- throw new utils_js_2.RuntimeExecutionError("Invalid array", ctxArray);
364
+ throw new errors_js_1.RuntimeExecutionError("Invalid array", ctxArray);
364
365
  }
365
366
  if (!(indexValue instanceof NumericValue_js_1.NumericValue)) {
366
- throw new utils_js_2.RuntimeExecutionError("Invalid index value", ctxArrayIndex);
367
+ throw new errors_js_1.RuntimeExecutionError("Invalid index value", ctxArrayIndex);
367
368
  }
368
369
  const indexValueNumber = indexValue.toNumber();
369
370
  if (isNaN(indexValueNumber)) {
370
- throw new utils_js_2.RuntimeExecutionError("Invalid index value", ctxArrayIndex);
371
+ throw new errors_js_1.RuntimeExecutionError("Invalid index value", ctxArrayIndex);
371
372
  }
372
373
  if (Array.isArray(arrayItem)) {
373
374
  this.setResult(ctx, arrayItem[indexValueNumber]);
@@ -738,7 +739,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
738
739
  const invalidImportCondition2 = alreadyImportedFlag !== types_js_1.ImportFunctionHandling.AllWithNamespace &&
739
740
  importHandling === types_js_1.ImportFunctionHandling.AllWithNamespace;
740
741
  if (invalidImportCondition1 || invalidImportCondition2) {
741
- throw new utils_js_2.RuntimeExecutionError(`Namespace import and wildcard/specific imports cannot be mixed: ${name}`, ctx);
742
+ throw new errors_js_1.RuntimeExecutionError(`Namespace import and wildcard/specific imports cannot be mixed: ${name}`, ctx);
742
743
  }
743
744
  if (isMergedNamespace) {
744
745
  if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
@@ -866,7 +867,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
866
867
  }
867
868
  }
868
869
  if (errorMessage !== null && ctx) {
869
- throw new utils_js_2.RuntimeExecutionError(errorMessage, ctx);
870
+ throw new errors_js_1.RuntimeExecutionError(errorMessage, ctx);
870
871
  }
871
872
  const newImportedFile = {
872
873
  id: name.trim(),
@@ -892,7 +893,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
892
893
  }
893
894
  catch (err) {
894
895
  this.log(`failed to cache library: ${libName}`);
895
- throw new utils_js_2.RuntimeExecutionError(`Failed to cache library: ${libName}`);
896
+ throw new errors_js_1.RuntimeExecutionError(`Failed to cache library: ${libName}`);
896
897
  }
897
898
  }
898
899
  }
@@ -1037,7 +1038,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
1037
1038
  return value.slice(1, value.length - 1);
1038
1039
  }
1039
1040
  throwWithContext(context, messageOrError) {
1040
- (0, utils_js_2.throwWithContext)(context, messageOrError);
1041
+ (0, errors_js_1.throwWithContext)(context, messageOrError);
1041
1042
  }
1042
1043
  validateType(value, context, validateFunction, expectedType) {
1043
1044
  if (value === undefined) {
@@ -1045,7 +1046,7 @@ class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVis
1045
1046
  }
1046
1047
  const result = validateFunction(value);
1047
1048
  if (!result) {
1048
- throw new utils_js_2.RuntimeExecutionError(`Invalid ${expectedType}`, context);
1049
+ throw new errors_js_1.RuntimeExecutionError(`Invalid ${expectedType}`, context);
1049
1050
  }
1050
1051
  return result;
1051
1052
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentAnnotater = void 0;
4
4
  const visitor_js_1 = require("./../visitor.js");
5
+ const globals_js_1 = require("../globals.js");
5
6
  class ComponentAnnotater {
6
7
  constructor() {
7
8
  this.counter = {};
@@ -14,8 +15,8 @@ class ComponentAnnotater {
14
15
  getAnnotation(instance) {
15
16
  let usePrefix;
16
17
  let useCounterKey;
17
- if (instance.hasParam('refdesPrefix')) {
18
- const prefix = instance.getParam('refdesPrefix');
18
+ if (instance.hasParam(globals_js_1.KeywordRefdesPrefix)) {
19
+ const prefix = instance.getParam(globals_js_1.KeywordRefdesPrefix);
19
20
  if (this.counter[prefix] === undefined) {
20
21
  this.counter[prefix] = 1;
21
22
  }
@@ -8,17 +8,18 @@ const big_js_1 = __importDefault(require("big.js"));
8
8
  const NumericValue_js_1 = require("./objects/NumericValue.js");
9
9
  const types_js_1 = require("./objects/types.js");
10
10
  const utils_js_1 = require("./utils.js");
11
+ const errors_js_1 = require("./errors.js");
11
12
  const globals_js_1 = require("./globals.js");
12
13
  const ClassComponent_js_1 = require("./objects/ClassComponent.js");
13
14
  const Net_js_1 = require("./objects/Net.js");
14
15
  const builtInMethods = [
15
16
  ['enumerate', enumerate],
16
- ['toMils', toMils],
17
+ ['to_mils', toMils],
17
18
  ['range', range],
18
19
  ['len', objectLength],
19
- ['arrayPush', arrayPush],
20
- ['arrayGet', arrayGet],
21
- ['arraySet', arraySet],
20
+ ['array_push', arrayPush],
21
+ ['array_get', arrayGet],
22
+ ['array_set', arraySet],
22
23
  ['print', null],
23
24
  ];
24
25
  exports.buildInMethodNamesList = builtInMethods.map(item => item[0]);
@@ -120,7 +121,7 @@ function arrayGet(arrayObject, index) {
120
121
  useValue = index;
121
122
  }
122
123
  if (isNaN(useValue)) {
123
- throw new utils_js_1.RuntimeExecutionError("Invalid index for arrayGet");
124
+ throw new errors_js_1.RuntimeExecutionError("Invalid index for arrayGet");
124
125
  }
125
126
  return arrayObject[useValue];
126
127
  }
@@ -9,7 +9,7 @@ const fs_1 = __importDefault(require("fs"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const crypto_js_1 = __importDefault(require("crypto-js"));
11
11
  const globals_js_1 = require("../globals.js");
12
- const utils_js_1 = require("../utils.js");
12
+ const errors_js_1 = require("../errors.js");
13
13
  class NodeScriptEnvironment {
14
14
  constructor() {
15
15
  this.useModuleDirectoryPath = null;
@@ -71,7 +71,7 @@ class NodeScriptEnvironment {
71
71
  return finalPath;
72
72
  }
73
73
  }
74
- throw new utils_js_1.RuntimeExecutionError("Failed to get current module directory");
74
+ throw new errors_js_1.RuntimeExecutionError("Failed to get current module directory");
75
75
  }
76
76
  getRelativeToModule(filePath) {
77
77
  return path_1.default.join(this.getModuleDirectory(), filePath);
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printErrorChain = exports.collectErrorChain = exports.ParseError = exports.ParseSyntaxError = exports.RuntimeExecutionError = exports.AutoWireFailedError = exports.AutoWireFailedError_ = exports.RenderError = exports.throwWithTokenRange = exports.throwWithContext = exports.getLinePositionAsString = exports.BaseError = void 0;
4
+ const antlr4ng_1 = require("antlr4ng");
5
+ class BaseError extends Error {
6
+ constructor(message, startTokenOrCtx, endToken, filePath, options) {
7
+ super(message, options);
8
+ this.name = 'BaseError';
9
+ this.message = message;
10
+ if (startTokenOrCtx instanceof antlr4ng_1.ParserRuleContext) {
11
+ this.startToken = startTokenOrCtx.start;
12
+ this.endToken = startTokenOrCtx.stop;
13
+ }
14
+ else {
15
+ this.startToken = startTokenOrCtx;
16
+ this.endToken = endToken;
17
+ }
18
+ this.filePath = filePath;
19
+ }
20
+ toString() {
21
+ const parts = [this.name];
22
+ const linePosition = getLinePositionAsString({
23
+ start: this.startToken,
24
+ stop: this.endToken
25
+ });
26
+ if (linePosition !== null) {
27
+ parts.push(linePosition);
28
+ }
29
+ parts.push(`: ${this.message}`);
30
+ return parts.join('');
31
+ }
32
+ }
33
+ exports.BaseError = BaseError;
34
+ function getLinePositionAsString(ctx) {
35
+ if (ctx === null || ctx === undefined) {
36
+ return null;
37
+ }
38
+ const { start: startToken, stop: stopToken } = ctx;
39
+ let result = null;
40
+ if (startToken) {
41
+ const { line, column } = startToken;
42
+ let stopLine = 0;
43
+ let stopCol = 0;
44
+ if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
45
+ stopLine = stopToken.line;
46
+ stopCol = stopToken.column + (stopToken.stop - stopToken.start);
47
+ }
48
+ else if (startToken === stopToken || startToken) {
49
+ stopLine = line;
50
+ stopCol = column + 1 + (startToken.stop - startToken.start);
51
+ }
52
+ else {
53
+ stopCol = -1;
54
+ }
55
+ result = ` at ${line}:${column + 1}`;
56
+ if (stopCol !== -1) {
57
+ result += `-${stopLine}:${stopCol + 1}`;
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ exports.getLinePositionAsString = getLinePositionAsString;
63
+ function throwWithContext(context, messageOrError) {
64
+ if (messageOrError instanceof BaseError) {
65
+ throw messageOrError;
66
+ }
67
+ throwWithTokenRange(messageOrError, context.start, context.stop);
68
+ }
69
+ exports.throwWithContext = throwWithContext;
70
+ function throwWithTokenRange(message, startToken, endToken) {
71
+ throw new ParseError(message, startToken, endToken);
72
+ }
73
+ exports.throwWithTokenRange = throwWithTokenRange;
74
+ class RenderError extends Error {
75
+ constructor(message, stage, options) {
76
+ super(message, options);
77
+ this.name = 'RenderError';
78
+ this.stage = stage;
79
+ }
80
+ }
81
+ exports.RenderError = RenderError;
82
+ class AutoWireFailedError_ extends Error {
83
+ constructor(message, wire) {
84
+ super(message);
85
+ this.name = 'AutoWireFailedError_';
86
+ this.wire = wire;
87
+ }
88
+ }
89
+ exports.AutoWireFailedError_ = AutoWireFailedError_;
90
+ class AutoWireFailedError extends BaseError {
91
+ constructor() {
92
+ super(...arguments);
93
+ this.name = 'AutoWireFailedError';
94
+ }
95
+ }
96
+ exports.AutoWireFailedError = AutoWireFailedError;
97
+ class RuntimeExecutionError extends BaseError {
98
+ constructor() {
99
+ super(...arguments);
100
+ this.name = 'RuntimeExecutionError';
101
+ }
102
+ }
103
+ exports.RuntimeExecutionError = RuntimeExecutionError;
104
+ class ParseSyntaxError extends BaseError {
105
+ constructor() {
106
+ super(...arguments);
107
+ this.name = 'ParseSyntaxError';
108
+ }
109
+ }
110
+ exports.ParseSyntaxError = ParseSyntaxError;
111
+ class ParseError extends ParseSyntaxError {
112
+ constructor() {
113
+ super(...arguments);
114
+ this.name = 'ParseError';
115
+ }
116
+ }
117
+ exports.ParseError = ParseError;
118
+ function collectErrorChain(error) {
119
+ const items = [];
120
+ let currentError = error;
121
+ for (let i = 0; i < 100; i++) {
122
+ if (currentError.cause) {
123
+ items.push(currentError.cause);
124
+ currentError = currentError.cause;
125
+ }
126
+ else {
127
+ break;
128
+ }
129
+ }
130
+ return items;
131
+ }
132
+ exports.collectErrorChain = collectErrorChain;
133
+ function printErrorChain(error) {
134
+ const errors = collectErrorChain(error);
135
+ errors.reverse();
136
+ for (const err of errors) {
137
+ console.log(" " + err.toString());
138
+ }
139
+ }
140
+ exports.printErrorChain = printErrorChain;
@@ -16,6 +16,7 @@ const layout_js_1 = require("./render/layout.js");
16
16
  const helpers_js_1 = require("./helpers.js");
17
17
  const draw_symbols_js_1 = require("./render/draw_symbols.js");
18
18
  const utils_js_1 = require("./utils.js");
19
+ const errors_js_1 = require("./errors.js");
19
20
  class ExecutionContext {
20
21
  constructor(name, namespace, netNamespace, executionLevel = 0, scopeLevel = 0, silent = false, logger, warnings, parent) {
21
22
  this.tmpPointId = 0;
@@ -347,7 +348,7 @@ class ExecutionContext {
347
348
  this.log('to component');
348
349
  const { addSequence = false } = options ?? {};
349
350
  if (!(component instanceof ClassComponent_js_1.ClassComponent)) {
350
- throw new utils_js_1.RuntimeExecutionError("Not a valid component!");
351
+ throw new errors_js_1.RuntimeExecutionError("Not a valid component!");
351
352
  }
352
353
  if (pinId === null) {
353
354
  pinId = component.getDefaultPin();
@@ -358,7 +359,7 @@ class ExecutionContext {
358
359
  }
359
360
  else {
360
361
  console.trace();
361
- throw new utils_js_1.RuntimeExecutionError('Invalid pin number ' +
362
+ throw new errors_js_1.RuntimeExecutionError('Invalid pin number ' +
362
363
  pinId +
363
364
  ' in ' +
364
365
  component.instanceName);
@@ -400,7 +401,7 @@ class ExecutionContext {
400
401
  usePinId = component.getPin(pinId);
401
402
  }
402
403
  else {
403
- throw new utils_js_1.RuntimeExecutionError('Invalid pin number '
404
+ throw new errors_js_1.RuntimeExecutionError('Invalid pin number '
404
405
  + pinId + ' in ' + component);
405
406
  }
406
407
  this.scope.setCurrent(component, usePinId);
@@ -484,7 +485,13 @@ class ExecutionContext {
484
485
  const { start_point: [component, pin,] } = stackRef;
485
486
  this.atComponent(component, pin, { addSequence: true });
486
487
  }
487
- this.scope.blockStack.delete(scopeLevel);
488
+ const scopeLevels = Array.from(this.scope.blockStack.keys());
489
+ for (const level of scopeLevels) {
490
+ if (level >= scopeLevel) {
491
+ this.log(`blockstack delete level ${level}`);
492
+ this.scope.blockStack.delete(level);
493
+ }
494
+ }
488
495
  this.log('exit blocks');
489
496
  }
490
497
  closeOpenPathBlocks() {
@@ -901,7 +908,7 @@ class ExecutionContext {
901
908
  this.log('-- done merging scope --');
902
909
  return mergedInstances;
903
910
  }
904
- addWire(segments) {
911
+ addWire(segments, ctx) {
905
912
  if (this.scope.currentComponent === null) {
906
913
  throw "No current component";
907
914
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SymbolValidatorContext = exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.NetGraphicsParams = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.ValidPinSides = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.RefdesFileSuffix = exports.BaseNamespace = exports.DoubleDelimiter1 = exports.Delimiter1 = exports.TOOL_VERSION = void 0;
4
- exports.PinTypesList = exports.DefaultComponentUnit = exports.TrailerArrayIndex = void 0;
3
+ exports.RenderFlags = exports.KeywordRefdesPrefix = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.NetGraphicsParams = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultSymbolLineWidth = exports.Defaults = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.ValidPinSides = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.RefdesFileSuffix = exports.BaseNamespace = exports.DoubleDelimiter1 = exports.Delimiter1 = exports.TOOL_VERSION = void 0;
4
+ exports.PinTypesList = exports.DefaultComponentUnit = exports.TrailerArrayIndex = exports.SymbolValidatorContext = void 0;
5
5
  const NumericValue_js_1 = require("./objects/NumericValue.js");
6
6
  const PinTypes_js_1 = require("./objects/PinTypes.js");
7
7
  exports.TOOL_VERSION = '0.1.5';
@@ -60,8 +60,11 @@ exports.portHeight = 2;
60
60
  exports.defaultGridSizeUnits = (0, NumericValue_js_1.numeric)(exports.MilsToMM).mul(100).toNumber();
61
61
  exports.defaultZoomScale = 2.5;
62
62
  exports.fontDisplayScale = 0.032;
63
+ exports.Defaults = {
64
+ WireLineWidth: (0, NumericValue_js_1.numeric)(6),
65
+ LineWidth: (0, NumericValue_js_1.numeric)(5),
66
+ };
63
67
  exports.defaultSymbolLineWidth = (0, NumericValue_js_1.numeric)(exports.MilsToMM).mul(6).toNumber();
64
- exports.defaultWireLineWidth = (0, NumericValue_js_1.numeric)(exports.MilsToMM).mul(6).toNumber();
65
68
  exports.defaultPinNameTextSize = 40;
66
69
  exports.defaultPinIdTextSize = 30;
67
70
  exports.defaultPageMarginMM = 10;
@@ -107,10 +110,10 @@ var ReferenceTypes;
107
110
  var NetGraphicsParams;
108
111
  (function (NetGraphicsParams) {
109
112
  NetGraphicsParams["Color"] = "color";
110
- NetGraphicsParams["LineWidth"] = "lineWidth";
113
+ NetGraphicsParams["LineWidth"] = "line_width";
111
114
  NetGraphicsParams["Highlight"] = "highlight";
112
- NetGraphicsParams["HighlightWidth"] = "highlightWidth";
113
- NetGraphicsParams["HighlightOpacity"] = "highlightOpacity";
115
+ NetGraphicsParams["HighlightWidth"] = "highlight_width";
116
+ NetGraphicsParams["HighlightOpacity"] = "highlight_opacity";
114
117
  })(NetGraphicsParams || (exports.NetGraphicsParams = NetGraphicsParams = {}));
115
118
  var FrameType;
116
119
  (function (FrameType) {
@@ -119,6 +122,7 @@ var FrameType;
119
122
  })(FrameType || (exports.FrameType = FrameType = {}));
120
123
  exports.ModuleContainsKeyword = 'contains';
121
124
  exports.GlobalDocumentName = 'document';
125
+ exports.KeywordRefdesPrefix = 'refdes_prefix';
122
126
  exports.RenderFlags = {
123
127
  ShowElementFrames: false,
124
128
  ShowOrigin: false,
package/dist/cjs/main.js CHANGED
@@ -9,6 +9,7 @@ const figlet_1 = __importDefault(require("figlet"));
9
9
  const fs_1 = require("fs");
10
10
  const pipeline_js_1 = require("./pipeline.js");
11
11
  const environment_js_1 = require("./environment/environment.js");
12
+ const errors_js_1 = require("./errors.js");
12
13
  async function main() {
13
14
  const env = new environment_js_1.NodeScriptEnvironment();
14
15
  environment_js_1.NodeScriptEnvironment.setInstance(env);
@@ -139,8 +140,8 @@ async function parseFile(scriptData, outputPath, scriptOptions) {
139
140
  return output;
140
141
  }
141
142
  catch (error) {
142
- console.error(`Unexpected Error: ${error}`);
143
- console.log(error.stack);
143
+ console.error(`Unexpected Error:`);
144
+ (0, errors_js_1.printErrorChain)(error);
144
145
  }
145
146
  return null;
146
147
  }
@@ -5,7 +5,7 @@ const draw_symbols_js_1 = require("../render/draw_symbols.js");
5
5
  const PinDefinition_js_1 = require("./PinDefinition.js");
6
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
7
  const globals_js_1 = require("../globals.js");
8
- const utils_js_1 = require("../utils.js");
8
+ const errors_js_1 = require("../errors.js");
9
9
  class ComponentUnit {
10
10
  get instanceName() {
11
11
  return `${this.parent.instanceName},${this.unitId}`;
@@ -190,7 +190,7 @@ class ClassComponent {
190
190
  }
191
191
  }
192
192
  }
193
- throw new utils_js_1.RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
193
+ throw new errors_js_1.RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
194
194
  }
195
195
  getNextPinAfter(pinIndex) {
196
196
  const pins = Array.from(this.pins.keys());
@@ -321,14 +321,14 @@ class ClassComponent {
321
321
  }
322
322
  getUnitForPin(pinId) {
323
323
  if (typeof pinId === "number") {
324
- throw new utils_js_1.RuntimeExecutionError("Invalid pin id");
324
+ throw new errors_js_1.RuntimeExecutionError("Invalid pin id");
325
325
  }
326
326
  for (const [tmpPin, componentUnit] of this.pinUnitMap) {
327
327
  if (tmpPin.equals(pinId)) {
328
328
  return componentUnit;
329
329
  }
330
330
  }
331
- throw new utils_js_1.RuntimeExecutionError("Could not find unit for pin: " + pinId);
331
+ throw new errors_js_1.RuntimeExecutionError("Could not find unit for pin: " + pinId);
332
332
  }
333
333
  }
334
334
  exports.ClassComponent = ClassComponent;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActiveObject = exports.FrameAction = exports.SequenceAction = exports.ExecutionScope = void 0;
4
4
  const CircuitScriptParser_js_1 = require("../antlr/CircuitScriptParser.js");
5
5
  const PinDefinition_js_1 = require("./PinDefinition.js");
6
- const utils_js_1 = require("../utils.js");
6
+ const errors_js_1 = require("../errors.js");
7
7
  class ExecutionScope {
8
8
  constructor(scopeId) {
9
9
  this.nets = [];
@@ -37,7 +37,7 @@ class ExecutionScope {
37
37
  }
38
38
  findNet(component, pin) {
39
39
  if (!(pin instanceof PinDefinition_js_1.PinId)) {
40
- throw new utils_js_1.RuntimeExecutionError('Invalid value for PinId: ' + pin);
40
+ throw new errors_js_1.RuntimeExecutionError('Invalid value for PinId: ' + pin);
41
41
  }
42
42
  return this.nets.find(([tmpComponent, tmpPin]) => {
43
43
  return tmpComponent.isEqual(component) && tmpPin.equals(pin);
@@ -27,6 +27,13 @@ var FrameParamKeys;
27
27
  FrameParamKeys["SheetType"] = "sheet_type";
28
28
  FrameParamKeys["GridStyle"] = "grid_style";
29
29
  FrameParamKeys["GridColor"] = "grid_color";
30
+ FrameParamKeys["BackgroundColor"] = "background_color";
31
+ FrameParamKeys["LineColor"] = "line_color";
32
+ FrameParamKeys["LineWidth"] = "line_width";
33
+ FrameParamKeys["FillColor"] = "fill_color";
34
+ FrameParamKeys["TextColor"] = "text_color";
35
+ FrameParamKeys["WireColor"] = "wire_color";
36
+ FrameParamKeys["WireWidth"] = "wire_width";
30
37
  FrameParamKeys["TitleAlign"] = "title_align";
31
38
  FrameParamKeys["HorizontalAlign"] = "align";
32
39
  FrameParamKeys["VerticalAlign"] = "valign";
@@ -27,6 +27,9 @@ class NumericValue {
27
27
  toString() {
28
28
  return 'numeric:' + this.value;
29
29
  }
30
+ copy() {
31
+ return this.add(0);
32
+ }
30
33
  toDisplayString() {
31
34
  if (typeof this.value === 'number') {
32
35
  return this.value.toString();
@@ -81,6 +84,15 @@ class NumericValue {
81
84
  eq(value) {
82
85
  return this.toBigNumber().eq(value.toBigNumber());
83
86
  }
87
+ floor() {
88
+ return numeric(Math.floor(this.toNumber()));
89
+ }
90
+ ceil() {
91
+ return numeric(Math.ceil(this.toNumber()));
92
+ }
93
+ roundDp() {
94
+ return roundValue(this.toNumber());
95
+ }
84
96
  }
85
97
  exports.NumericValue = NumericValue;
86
98
  class NumberOperator {
@@ -191,6 +203,9 @@ function resolveToNumericValue(value) {
191
203
  }
192
204
  exports.resolveToNumericValue = resolveToNumericValue;
193
205
  function roundValue(value) {
206
+ if (typeof value === "number") {
207
+ value = numeric(value);
208
+ }
194
209
  return resolveToNumericValue(new big_js_1.Big(value.toBigNumber().toFixed(7)));
195
210
  }
196
211
  exports.roundValue = roundValue;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPinDefinition = exports.isPinId = exports.PortSide = exports.PinIdType = exports.PinDefinition = exports.PinId = void 0;
4
- const utils_js_1 = require("../utils.js");
4
+ const errors_js_1 = require("../errors.js");
5
5
  const NumericValue_js_1 = require("./NumericValue.js");
6
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
7
  class PinId {
8
8
  constructor(value) {
9
9
  if (typeof value !== 'string' && typeof value !== 'number') {
10
- throw new utils_js_1.RuntimeExecutionError("Invalid value for PinId: " + value);
10
+ throw new errors_js_1.RuntimeExecutionError("Invalid value for PinId: " + value);
11
11
  }
12
12
  this.value = value;
13
13
  this.type = typeof value === 'number' ? PinIdType.Int : PinIdType.Str;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportFunctionHandling = exports.ImportedLibrary = exports.NetTypes = exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
4
4
  const globals_js_1 = require("../globals.js");
5
- const utils_js_1 = require("../utils.js");
5
+ const errors_js_1 = require("../errors.js");
6
6
  class CFunctionEntry {
7
7
  constructor(namespace, name, execute, source, uniqueId) {
8
8
  this.lazyLoaded = false;
@@ -31,7 +31,7 @@ class AnyReference {
31
31
  this.referenceName = 'AnyReference';
32
32
  if (refType.value instanceof AnyReference
33
33
  && refType.value.type !== globals_js_1.ReferenceTypes.function) {
34
- throw new utils_js_1.RuntimeExecutionError("Nested reference types!");
34
+ throw new errors_js_1.RuntimeExecutionError("Nested reference types!");
35
35
  }
36
36
  this.found = refType.found;
37
37
  this.name = refType.name;
@@ -4,6 +4,7 @@ exports.CircuitscriptParserErrorListener = exports.parseFileWithVisitor = void 0
4
4
  const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
5
5
  const lexer_js_1 = require("./lexer.js");
6
6
  const utils_js_1 = require("./utils.js");
7
+ const errors_js_1 = require("./errors.js");
7
8
  const antlr4ng_1 = require("antlr4ng");
8
9
  function parseFileWithVisitor(visitor, data, options) {
9
10
  const lexerErrorListener = new CircuitscriptParserErrorListener(visitor.onErrorHandler);
@@ -42,7 +43,7 @@ function parseFileWithVisitor(visitor, data, options) {
42
43
  }
43
44
  catch (error) {
44
45
  if (visitor.onErrorHandler) {
45
- if (error instanceof utils_js_1.RuntimeExecutionError) {
46
+ if (error instanceof errors_js_1.RuntimeExecutionError) {
46
47
  visitor.onErrorHandler(error.message, null, error);
47
48
  }
48
49
  else {
@@ -78,7 +79,7 @@ class CircuitscriptParserErrorListener {
78
79
  else {
79
80
  if (offendingSymbol && msg.match("extraneous input 'import' expecting")) {
80
81
  msg = "Invalid import statement";
81
- throw new utils_js_1.ParseSyntaxError("Invalid import statement", offendingSymbol);
82
+ throw new errors_js_1.ParseSyntaxError("Invalid import statement", offendingSymbol);
82
83
  }
83
84
  console.log("Syntax error at line", line, ':', column, ' - ', msg);
84
85
  }