circuitscript 0.0.26 → 0.0.28

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.
@@ -4,7 +4,7 @@ import { ExecutionContext } from "./execute";
4
4
  import { Logger } from "./logger";
5
5
  import { ClassComponent } from "./objects/ClassComponent";
6
6
  import { Net } from "./objects/Net";
7
- import { CallableParameter, CFunctionOptions, ComplexType, FunctionDefinedParameter, ReferenceType } from "./objects/types";
7
+ import { CallableParameter, CFunctionOptions, ComplexType, Direction, FunctionDefinedParameter, ReferenceType } from "./objects/types";
8
8
  import { ParserRuleContext } from 'antlr4ng';
9
9
  export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | ReferenceType | any> {
10
10
  indentLevel: number;
@@ -16,7 +16,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | Refe
16
16
  defaultLibsPath: string;
17
17
  printStream: string[];
18
18
  printToConsole: boolean;
19
- acceptedDirections: string[];
19
+ acceptedDirections: Direction[];
20
20
  acceptedFlip: string[];
21
21
  protected resultData: Map<ParserRuleContext, any>;
22
22
  protected paramData: Map<ParserRuleContext, any>;
@@ -99,19 +99,20 @@ export declare class CircuitScriptParser extends antlr.Parser {
99
99
  static readonly RULE_function_return_expr = 39;
100
100
  static readonly RULE_create_component_expr = 40;
101
101
  static readonly RULE_create_graphic_expr = 41;
102
- static readonly RULE_graphic_expr = 42;
103
- static readonly RULE_property_expr = 43;
104
- static readonly RULE_property_key_expr = 44;
105
- static readonly RULE_property_value_expr = 45;
106
- static readonly RULE_blank_expr = 46;
107
- static readonly RULE_wire_atom_expr = 47;
108
- static readonly RULE_wire_expr = 48;
109
- static readonly RULE_point_expr = 49;
110
- static readonly RULE_import_expr = 50;
111
- static readonly RULE_frame_expr = 51;
112
- static readonly RULE_if_expr = 52;
113
- static readonly RULE_if_inner_expr = 53;
114
- static readonly RULE_else_expr = 54;
102
+ static readonly RULE_nested_properties_inner = 42;
103
+ static readonly RULE_graphic_expr = 43;
104
+ static readonly RULE_property_expr = 44;
105
+ static readonly RULE_property_key_expr = 45;
106
+ static readonly RULE_property_value_expr = 46;
107
+ static readonly RULE_blank_expr = 47;
108
+ static readonly RULE_wire_atom_expr = 48;
109
+ static readonly RULE_wire_expr = 49;
110
+ static readonly RULE_point_expr = 50;
111
+ static readonly RULE_import_expr = 51;
112
+ static readonly RULE_frame_expr = 52;
113
+ static readonly RULE_if_expr = 53;
114
+ static readonly RULE_if_inner_expr = 54;
115
+ static readonly RULE_else_expr = 55;
115
116
  static readonly literalNames: (string | null)[];
116
117
  static readonly symbolicNames: (string | null)[];
117
118
  static readonly ruleNames: string[];
@@ -165,6 +166,7 @@ export declare class CircuitScriptParser extends antlr.Parser {
165
166
  function_return_expr(): Function_return_exprContext;
166
167
  create_component_expr(): Create_component_exprContext;
167
168
  create_graphic_expr(): Create_graphic_exprContext;
169
+ nested_properties_inner(): Nested_properties_innerContext;
168
170
  graphic_expr(): Graphic_exprContext;
169
171
  property_expr(): Property_exprContext;
170
172
  property_key_expr(): Property_key_exprContext;
@@ -639,6 +641,17 @@ export declare class Create_graphic_exprContext extends antlr.ParserRuleContext
639
641
  get ruleIndex(): number;
640
642
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
641
643
  }
644
+ export declare class Nested_properties_innerContext extends antlr.ParserRuleContext {
645
+ constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
646
+ NEWLINE(): antlr.TerminalNode[];
647
+ NEWLINE(i: number): antlr.TerminalNode | null;
648
+ INDENT(): antlr.TerminalNode | null;
649
+ DEDENT(): antlr.TerminalNode | null;
650
+ property_expr(): Property_exprContext[];
651
+ property_expr(i: number): Property_exprContext | null;
652
+ get ruleIndex(): number;
653
+ accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
654
+ }
642
655
  export declare class Graphic_exprContext extends antlr.ParserRuleContext {
643
656
  _command?: Token | null;
644
657
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
@@ -647,6 +660,7 @@ export declare class Graphic_exprContext extends antlr.ParserRuleContext {
647
660
  parameters(): ParametersContext | null;
648
661
  OPEN_PAREN(): antlr.TerminalNode | null;
649
662
  CLOSE_PAREN(): antlr.TerminalNode | null;
663
+ nested_properties_inner(): Nested_properties_innerContext | null;
650
664
  get ruleIndex(): number;
651
665
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
652
666
  }
@@ -678,12 +692,7 @@ export declare class Single_line_propertyContext extends Property_value_exprCont
678
692
  }
679
693
  export declare class Nested_propertiesContext extends Property_value_exprContext {
680
694
  constructor(ctx: Property_value_exprContext);
681
- NEWLINE(): antlr.TerminalNode[];
682
- NEWLINE(i: number): antlr.TerminalNode | null;
683
- INDENT(): antlr.TerminalNode;
684
- DEDENT(): antlr.TerminalNode;
685
- property_expr(): Property_exprContext[];
686
- property_expr(i: number): Property_exprContext | null;
695
+ nested_properties_inner(): Nested_properties_innerContext;
687
696
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
688
697
  }
689
698
  export declare class Blank_exprContext extends antlr.ParserRuleContext {
@@ -49,6 +49,7 @@ import { Net_namespace_exprContext } from "./CircuitScriptParser.js";
49
49
  import { Function_return_exprContext } from "./CircuitScriptParser.js";
50
50
  import { Create_component_exprContext } from "./CircuitScriptParser.js";
51
51
  import { Create_graphic_exprContext } from "./CircuitScriptParser.js";
52
+ import { Nested_properties_innerContext } from "./CircuitScriptParser.js";
52
53
  import { Graphic_exprContext } from "./CircuitScriptParser.js";
53
54
  import { Property_exprContext } from "./CircuitScriptParser.js";
54
55
  import { Property_key_exprContext } from "./CircuitScriptParser.js";
@@ -115,6 +116,7 @@ export declare class CircuitScriptVisitor<Result> extends AbstractParseTreeVisit
115
116
  visitFunction_return_expr?: (ctx: Function_return_exprContext) => Result;
116
117
  visitCreate_component_expr?: (ctx: Create_component_exprContext) => Result;
117
118
  visitCreate_graphic_expr?: (ctx: Create_graphic_exprContext) => Result;
119
+ visitNested_properties_inner?: (ctx: Nested_properties_innerContext) => Result;
118
120
  visitGraphic_expr?: (ctx: Graphic_exprContext) => Result;
119
121
  visitProperty_expr?: (ctx: Property_exprContext) => Result;
120
122
  visitProperty_key_expr?: (ctx: Property_key_exprContext) => Result;
@@ -1,5 +1,5 @@
1
1
  import { G } from "@svgdotjs/svg.js";
2
- import { Feature, GeometryProp, HorizontalAlign, Label, LabelStyle, VerticalAlign } from "./geometry.js";
2
+ import { Feature, GeometryProp, HorizontalAlign, LabelStyle, Textbox, VerticalAlign } from "./geometry.js";
3
3
  import { Logger } from "./logger.js";
4
4
  export declare abstract class SymbolGraphic {
5
5
  drawPortsName: boolean;
@@ -56,6 +56,9 @@ export declare class SymbolText extends SymbolGraphic {
56
56
  }
57
57
  export declare class SymbolPlaceholder extends SymbolGraphic {
58
58
  generateDrawing(): void;
59
+ parseLabelStyle(keywordParams: Map<string, any>): {
60
+ [key: string]: any;
61
+ };
59
62
  drawPinParams(drawing: SymbolDrawingCommands, commandName: string, keywordParams: Map<string, any>, positionParams: any[]): void;
60
63
  constructor(drawing: SymbolDrawing);
61
64
  }
@@ -74,7 +77,8 @@ export declare enum PlaceHolderCommands {
74
77
  path = "path",
75
78
  lineWidth = "lineWidth",
76
79
  fill = "fill",
77
- lineColor = "lineColor"
80
+ lineColor = "lineColor",
81
+ text = "text"
78
82
  }
79
83
  export declare class SymbolCustom extends SymbolGraphic {
80
84
  pinDefinition: SymbolPinDefintion[];
@@ -110,6 +114,7 @@ export declare class SymbolDrawing {
110
114
  addRect2(x: number, y: number, x2: number, y2: number): SymbolDrawing;
111
115
  addLabel(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
112
116
  addLabelId(id: string, x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
117
+ addTextbox(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
113
118
  addPath(...pathParts: any): SymbolDrawing;
114
119
  addSetLineWidth(value: number): SymbolDrawing;
115
120
  addSetLineColor(value: string): SymbolDrawing;
@@ -122,7 +127,7 @@ export declare class SymbolDrawing {
122
127
  lineWidth: number;
123
128
  }[];
124
129
  getPinsPath(): string;
125
- getLabels(): Label[];
130
+ getLabels(): Textbox[];
126
131
  private featuresToPath;
127
132
  getBoundingBox(excludeLabels?: boolean): {
128
133
  width: number;
@@ -23,6 +23,7 @@ export declare class ExecutionContext {
23
23
  logger: Logger;
24
24
  __functionCache: {};
25
25
  parentContext: ExecutionContext;
26
+ componentAngleFollowsWire: boolean;
26
27
  constructor(name: string, namespace: string, netNamespace: string, executionLevel: number | undefined, indentLevel: number | undefined, silent: boolean | undefined, logger: Logger, parent: ExecutionContext);
27
28
  log(...params: any[]): void;
28
29
  private setupRoot;
@@ -37,6 +38,8 @@ export declare class ExecutionContext {
37
38
  type?: string;
38
39
  width?: number;
39
40
  copy: boolean;
41
+ angle?: number;
42
+ followWireOrientation: boolean;
40
43
  }): ClassComponent;
41
44
  printPoint(extra?: string): void;
42
45
  addComponentExisting(component: ClassComponent, pin: number): ComponentPin;
@@ -67,6 +70,7 @@ export declare class ExecutionContext {
67
70
  setCurrentComponentStyle(styles: {
68
71
  [key: string]: number | string;
69
72
  }): void;
73
+ applyComponentAngleFromWire(component: ClassComponent, pin: number): void;
70
74
  enterFrame(): number;
71
75
  exitFrame(frameId: number): void;
72
76
  }
@@ -5,7 +5,7 @@ export type Polygon = Flatten.Polygon;
5
5
  export type Multiline = Flatten.Multiline;
6
6
  export type Line = Flatten.Line;
7
7
  export type Arc = Flatten.Arc;
8
- export type Feature = Segment | Polygon | Label | Arc | Multiline;
8
+ export type Feature = Segment | Polygon | Label | Textbox | Arc | Multiline;
9
9
  export type LabelStyle = {
10
10
  font?: string;
11
11
  fontSize?: number;
@@ -14,7 +14,7 @@ export type LabelStyle = {
14
14
  anchor?: HorizontalAlign.Left | HorizontalAlign.Middle | HorizontalAlign.Right;
15
15
  vanchor?: VerticalAlign.Top | VerticalAlign.Middle | VerticalAlign.Bottom;
16
16
  };
17
- export declare class Label extends Flatten.Polygon {
17
+ export declare class Textbox extends Flatten.Polygon {
18
18
  id: string;
19
19
  text: string;
20
20
  anchorPoint: [number, number];
@@ -26,13 +26,16 @@ export declare class Label extends Flatten.Polygon {
26
26
  font: string;
27
27
  style: LabelStyle;
28
28
  textMeasurementBounds: Box;
29
+ label: boolean;
29
30
  get box(): Flatten.Box;
30
- constructor(id: string, text: string, anchorPoint: [number, number], polygon: Flatten.Polygon, style: LabelStyle, bounds: Box);
31
- static fromPoint(id: string, x: number, y: number, text: string, style: LabelStyle): Label;
32
- rotate(angle: number, origin: Flatten.Point): Label;
33
- transform(matrix: Flatten.Matrix): Label;
31
+ constructor(id: string, text: string, anchorPoint: [number, number], polygon: Flatten.Polygon, style: LabelStyle, bounds: Box, label: boolean);
32
+ static fromPoint(id: string, x: number, y: number, text: string, style: LabelStyle, label: boolean): Textbox;
33
+ rotate(angle: number, origin: Flatten.Point): Textbox;
34
+ transform(matrix: Flatten.Matrix): Textbox;
34
35
  getLabelPosition(): [number, number];
35
36
  }
37
+ export declare class Label extends Textbox {
38
+ }
36
39
  export declare class GeometryProp {
37
40
  name: string;
38
41
  value: string | number;
@@ -41,7 +44,8 @@ export declare class GeometryProp {
41
44
  export declare class Geometry {
42
45
  static point(x: number, y: number): Flatten.Point;
43
46
  static line(x1: number, y1: number, x2: number, y2: number): Flatten.Line;
44
- static label(id: string, x: number, y: number, text: string, style: LabelStyle): Label;
47
+ static label(id: string, x: number, y: number, text: string, style: LabelStyle): Textbox;
48
+ static textbox(id: string | null, x: number, y: number, text: string, style: LabelStyle): Textbox;
45
49
  static segment(start: [number, number], end: [number, number]): Segment;
46
50
  static polygon(coords: [number, number][]): Polygon;
47
51
  static multiline(coords: [number, number][]): Multiline;
@@ -57,9 +61,8 @@ export declare class Geometry {
57
61
  width: number;
58
62
  height: number;
59
63
  };
60
- static getType(feature: Feature): string;
61
64
  static FullCircleRadians: number;
62
- static featuresToPath(items: Feature[]): {
65
+ static featuresToPath(items: Feature[], flipX: number, flipY: number): {
63
66
  path: string;
64
67
  isClosedPolygon: boolean;
65
68
  };
@@ -139,6 +139,11 @@ export declare class RenderJunction {
139
139
  y: number;
140
140
  constructor(x: number, y: number);
141
141
  }
142
+ export declare function CalculatePinPositions(component: ClassComponent): Map<number, {
143
+ x: number;
144
+ y: number;
145
+ angle: number;
146
+ }>;
142
147
  type SubGraphInfo = {
143
148
  firstNodeId: string;
144
149
  components: string[];
@@ -19,6 +19,10 @@ export declare class ClassComponent {
19
19
  widthProp: number | null;
20
20
  typeProp: string | null;
21
21
  copyProp: boolean;
22
+ angleProp: number;
23
+ followWireOrientationProp: boolean;
24
+ wireOrientationAngle: number;
25
+ useWireOrientationAngle: boolean;
22
26
  styles: {
23
27
  [key: string]: number | string;
24
28
  };
@@ -1,10 +1,11 @@
1
1
  import { ClassComponent } from "./ClassComponent.js";
2
+ import { Direction } from "./types.js";
2
3
  export declare class Wire {
3
4
  path: WireSegment[];
4
5
  constructor(path: WireSegment[]);
5
6
  }
6
7
  export type WireSegment = {
7
- direction: 'up' | 'down' | 'left' | 'right' | 'auto' | 'auto_';
8
+ direction: Direction.Up | Direction.Down | Direction.Left | Direction.Right | 'auto' | 'auto_';
8
9
  value: number;
9
10
  valueXY?: [x: number, y: number];
10
11
  until?: [instance: ClassComponent, pin: number];
@@ -52,3 +52,9 @@ export declare enum ParseSymbolType {
52
52
  Function = "function",
53
53
  Undefined = "undefined"
54
54
  }
55
+ export declare enum Direction {
56
+ Left = "left",
57
+ Right = "right",
58
+ Down = "down",
59
+ Up = "up"
60
+ }
@@ -1,4 +1,4 @@
1
- import { Add_component_exprContext, AdditionExprContext, At_blockContext, At_block_pin_exprContext, At_block_pin_expression_complexContext, At_block_pin_expression_simpleContext, At_component_exprContext, BinaryOperatorExprContext, Path_blocksContext, Component_select_exprContext, Create_component_exprContext, Create_graphic_exprContext, DataExprContext, Data_expr_with_assignmentContext, Double_dot_property_set_exprContext, Frame_exprContext, Function_def_exprContext, Keyword_assignment_exprContext, MultiplyExprContext, Nested_propertiesContext, Net_namespace_exprContext, Pin_select_expr2Context, Pin_select_exprContext, Point_exprContext, Property_exprContext, Property_key_exprContext, Property_set_exprContext, Single_line_propertyContext, To_component_exprContext, Wire_exprContext, UnaryOperatorExprContext, Wire_expr_direction_onlyContext, Wire_expr_direction_valueContext, Graphic_exprContext, If_exprContext, If_inner_exprContext, LogicalOperatorExprContext } from './antlr/CircuitScriptParser.js';
1
+ import { Add_component_exprContext, AdditionExprContext, At_blockContext, At_block_pin_exprContext, At_block_pin_expression_complexContext, At_block_pin_expression_simpleContext, At_component_exprContext, BinaryOperatorExprContext, Path_blocksContext, Component_select_exprContext, Create_component_exprContext, Create_graphic_exprContext, DataExprContext, Data_expr_with_assignmentContext, Double_dot_property_set_exprContext, Frame_exprContext, Function_def_exprContext, Keyword_assignment_exprContext, MultiplyExprContext, Nested_propertiesContext, Net_namespace_exprContext, Pin_select_expr2Context, Pin_select_exprContext, Point_exprContext, Property_exprContext, Property_key_exprContext, Property_set_exprContext, Single_line_propertyContext, To_component_exprContext, Wire_exprContext, UnaryOperatorExprContext, Wire_expr_direction_onlyContext, Wire_expr_direction_valueContext, Graphic_exprContext, If_exprContext, If_inner_exprContext, LogicalOperatorExprContext, Nested_properties_innerContext } from './antlr/CircuitScriptParser.js';
2
2
  import { ClassComponent } from './objects/ClassComponent.js';
3
3
  import { PinTypes } from './objects/PinTypes.js';
4
4
  import { ComponentPin, ComponentPinNet } from './objects/types.js';
@@ -8,7 +8,7 @@ import { ParserRuleContext } from 'antlr4ng';
8
8
  export declare class ParserVisitor extends BaseVisitor {
9
9
  visitKeyword_assignment_expr: (ctx: Keyword_assignment_exprContext) => void;
10
10
  visitPin_select_expr: (ctx: Pin_select_exprContext) => void;
11
- visitAdd_component_expr: (ctx: Add_component_exprContext) => ComponentPin;
11
+ visitAdd_component_expr: (ctx: Add_component_exprContext) => void;
12
12
  visitAt_component_expr: (ctx: At_component_exprContext) => ComponentPin;
13
13
  visitTo_component_expr: (ctx: To_component_exprContext) => ComponentPin;
14
14
  visitComponent_select_expr: (ctx: Component_select_exprContext) => void;
@@ -18,6 +18,7 @@ export declare class ParserVisitor extends BaseVisitor {
18
18
  visitGraphic_expr: (ctx: Graphic_exprContext) => void;
19
19
  visitProperty_expr: (ctx: Property_exprContext) => void;
20
20
  visitSingle_line_property: (ctx: Single_line_propertyContext) => void;
21
+ visitNested_properties_inner: (ctx: Nested_properties_innerContext) => void;
21
22
  visitNested_properties: (ctx: Nested_propertiesContext) => void;
22
23
  visitProperty_key_expr: (ctx: Property_key_exprContext) => void;
23
24
  visitData_expr_with_assignment: (ctx: Data_expr_with_assignmentContext) => void;
package/libs/lib.cst CHANGED
@@ -4,6 +4,7 @@ def net(net_name):
4
4
  return create component:
5
5
  pins: 1
6
6
  copy: true
7
+ angle: -90
7
8
  display: create graphic:
8
9
  hline: -15, 0, 30
9
10
  vpin: 1, 0, 10, -10, display_pin_id=0
@@ -17,6 +18,7 @@ def supply(net_name):
17
18
  return create component:
18
19
  pins: 1
19
20
  copy: true
21
+ angle: -90
20
22
  display: create graphic:
21
23
  hline: -15, 0, 30
22
24
  vpin: 1, 0, 10, -10, display_pin_id=0
@@ -26,12 +28,13 @@ def supply(net_name):
26
28
  net_name: net_name
27
29
  priority: 20
28
30
 
29
- def label(value):
31
+ def label(value, anchor="left"):
30
32
  return create component:
31
33
  pins: 1
32
34
  copy: true
35
+ followWireOrientation: false
33
36
  display: create graphic:
34
- label: "value", 0, -2, "?", fontSize=10, anchor="left"
37
+ label: "value", 0, -2, "?", fontSize=10, anchor=anchor
35
38
  pin: 1, 0, 0, 0, 0, display_pin_id=0
36
39
  type: "label"
37
40
  params:
@@ -63,6 +66,7 @@ def cap(value):
63
66
 
64
67
  return create component:
65
68
  pins: 2
69
+ angle: 90
66
70
  display: create graphic:
67
71
  hline: -width/2, -3, width
68
72
  hline: -width/2, 3, width
@@ -139,6 +143,7 @@ def cgnd():
139
143
  return create component:
140
144
  pins: 1
141
145
  copy: true
146
+ angle: 90
142
147
  display: create graphic:
143
148
  hline: -15, 0, 30
144
149
  hline: -10, 5, 20
@@ -157,6 +162,7 @@ def dgnd(net_name="GND"):
157
162
  return create component:
158
163
  pins: 1
159
164
  copy: true
165
+ angle: 90
160
166
  display: create graphic:
161
167
  triangle: 0, 0, 0, height, width
162
168
  vpin: 1, 0, -10, 10, display_pin_id=0
@@ -173,7 +179,6 @@ def marker_point():
173
179
  hline: -5, 0, 10
174
180
  vline: 0, -5, 10
175
181
  pin: 1, 0, 0, 0, 0, display_pin_id=0
176
- type: "net"
177
182
 
178
183
  def arrow_point():
179
184
  return create component:
@@ -181,4 +186,14 @@ def arrow_point():
181
186
  display: create graphic:
182
187
  path: ("M", 15, -5, "L", 20, 0, "L", 15, 5)
183
188
  hpin: 1, 0, 0, 20
184
- type: "net"
189
+
190
+ def text(value, offsetX = 0, offsetY = 0, fontSize = 12):
191
+ return create component:
192
+ pins: 1
193
+ followWireOrientation: false
194
+ display: create graphic:
195
+ pin: 1, 0, 0, 0, 0, display_pin_id=0
196
+ text:
197
+ content: value
198
+ offset: offsetX, offsetY
199
+ fontSize: fontSize
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {