circuitscript 0.0.21 → 0.0.22

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.
@@ -0,0 +1,115 @@
1
+ import { ParseTreeVisitor } from 'antlr4';
2
+ import { ScriptContext } from "./CircuitScriptParser";
3
+ import { ExpressionContext } from "./CircuitScriptParser";
4
+ import { Path_blocksContext } from "./CircuitScriptParser";
5
+ import { Path_block_innerContext } from "./CircuitScriptParser";
6
+ import { Property_set_expr2Context } from "./CircuitScriptParser";
7
+ import { Assignment_expr2Context } from "./CircuitScriptParser";
8
+ import { Data_expr_with_assignmentContext } from "./CircuitScriptParser";
9
+ import { Add_component_exprContext } from "./CircuitScriptParser";
10
+ import { Component_select_exprContext } from "./CircuitScriptParser";
11
+ import { Pin_select_exprContext } from "./CircuitScriptParser";
12
+ import { Pin_select_expr2Context } from "./CircuitScriptParser";
13
+ import { At_component_exprContext } from "./CircuitScriptParser";
14
+ import { To_component_exprContext } from "./CircuitScriptParser";
15
+ import { At_to_multiple_exprContext } from "./CircuitScriptParser";
16
+ import { At_to_multiple_line_exprContext } from "./CircuitScriptParser";
17
+ import { At_to_multiple_line_expr_to_pinContext } from "./CircuitScriptParser";
18
+ import { At_blockContext } from "./CircuitScriptParser";
19
+ import { At_block_expressionsContext } from "./CircuitScriptParser";
20
+ import { At_block_pin_exprContext } from "./CircuitScriptParser";
21
+ import { At_block_pin_expression_simpleContext } from "./CircuitScriptParser";
22
+ import { At_block_pin_expression_complexContext } from "./CircuitScriptParser";
23
+ import { Break_keywordContext } from "./CircuitScriptParser";
24
+ import { Assignment_exprContext } from "./CircuitScriptParser";
25
+ import { Keyword_assignment_exprContext } from "./CircuitScriptParser";
26
+ import { ParametersContext } from "./CircuitScriptParser";
27
+ import { Property_set_exprContext } from "./CircuitScriptParser";
28
+ import { Double_dot_property_set_exprContext } from "./CircuitScriptParser";
29
+ import { AdditionExprContext } from "./CircuitScriptParser";
30
+ import { MultiplyExprContext } from "./CircuitScriptParser";
31
+ import { DataExprContext } from "./CircuitScriptParser";
32
+ import { UnaryOperatorExprContext } from "./CircuitScriptParser";
33
+ import { ValueAtomExprContext } from "./CircuitScriptParser";
34
+ import { BinaryOperatorExprContext } from "./CircuitScriptParser";
35
+ import { RoundedBracketsExprContext } from "./CircuitScriptParser";
36
+ import { Binary_operatorContext } from "./CircuitScriptParser";
37
+ import { Unary_operatorContext } from "./CircuitScriptParser";
38
+ import { Value_exprContext } from "./CircuitScriptParser";
39
+ import { Function_def_exprContext } from "./CircuitScriptParser";
40
+ import { Function_exprContext } from "./CircuitScriptParser";
41
+ import { Function_args_exprContext } from "./CircuitScriptParser";
42
+ import { Atom_exprContext } from "./CircuitScriptParser";
43
+ import { Trailer_exprContext } from "./CircuitScriptParser";
44
+ import { Net_namespace_exprContext } from "./CircuitScriptParser";
45
+ import { Function_return_exprContext } from "./CircuitScriptParser";
46
+ import { Create_component_exprContext } from "./CircuitScriptParser";
47
+ import { Create_graphic_exprContext } from "./CircuitScriptParser";
48
+ import { Sub_exprContext } from "./CircuitScriptParser";
49
+ import { Property_exprContext } from "./CircuitScriptParser";
50
+ import { Property_key_exprContext } from "./CircuitScriptParser";
51
+ import { Nested_propertiesContext } from "./CircuitScriptParser";
52
+ import { Single_line_propertyContext } from "./CircuitScriptParser";
53
+ import { Blank_exprContext } from "./CircuitScriptParser";
54
+ import { Wire_exprContext } from "./CircuitScriptParser";
55
+ import { Point_exprContext } from "./CircuitScriptParser";
56
+ import { Import_exprContext } from "./CircuitScriptParser";
57
+ import { Frame_exprContext } from "./CircuitScriptParser";
58
+ export default class CircuitScriptVisitor<Result> extends ParseTreeVisitor<Result> {
59
+ visitScript?: (ctx: ScriptContext) => Result;
60
+ visitExpression?: (ctx: ExpressionContext) => Result;
61
+ visitPath_blocks?: (ctx: Path_blocksContext) => Result;
62
+ visitPath_block_inner?: (ctx: Path_block_innerContext) => Result;
63
+ visitProperty_set_expr2?: (ctx: Property_set_expr2Context) => Result;
64
+ visitAssignment_expr2?: (ctx: Assignment_expr2Context) => Result;
65
+ visitData_expr_with_assignment?: (ctx: Data_expr_with_assignmentContext) => Result;
66
+ visitAdd_component_expr?: (ctx: Add_component_exprContext) => Result;
67
+ visitComponent_select_expr?: (ctx: Component_select_exprContext) => Result;
68
+ visitPin_select_expr?: (ctx: Pin_select_exprContext) => Result;
69
+ visitPin_select_expr2?: (ctx: Pin_select_expr2Context) => Result;
70
+ visitAt_component_expr?: (ctx: At_component_exprContext) => Result;
71
+ visitTo_component_expr?: (ctx: To_component_exprContext) => Result;
72
+ visitAt_to_multiple_expr?: (ctx: At_to_multiple_exprContext) => Result;
73
+ visitAt_to_multiple_line_expr?: (ctx: At_to_multiple_line_exprContext) => Result;
74
+ visitAt_to_multiple_line_expr_to_pin?: (ctx: At_to_multiple_line_expr_to_pinContext) => Result;
75
+ visitAt_block?: (ctx: At_blockContext) => Result;
76
+ visitAt_block_expressions?: (ctx: At_block_expressionsContext) => Result;
77
+ visitAt_block_pin_expr?: (ctx: At_block_pin_exprContext) => Result;
78
+ visitAt_block_pin_expression_simple?: (ctx: At_block_pin_expression_simpleContext) => Result;
79
+ visitAt_block_pin_expression_complex?: (ctx: At_block_pin_expression_complexContext) => Result;
80
+ visitBreak_keyword?: (ctx: Break_keywordContext) => Result;
81
+ visitAssignment_expr?: (ctx: Assignment_exprContext) => Result;
82
+ visitKeyword_assignment_expr?: (ctx: Keyword_assignment_exprContext) => Result;
83
+ visitParameters?: (ctx: ParametersContext) => Result;
84
+ visitProperty_set_expr?: (ctx: Property_set_exprContext) => Result;
85
+ visitDouble_dot_property_set_expr?: (ctx: Double_dot_property_set_exprContext) => Result;
86
+ visitAdditionExpr?: (ctx: AdditionExprContext) => Result;
87
+ visitMultiplyExpr?: (ctx: MultiplyExprContext) => Result;
88
+ visitDataExpr?: (ctx: DataExprContext) => Result;
89
+ visitUnaryOperatorExpr?: (ctx: UnaryOperatorExprContext) => Result;
90
+ visitValueAtomExpr?: (ctx: ValueAtomExprContext) => Result;
91
+ visitBinaryOperatorExpr?: (ctx: BinaryOperatorExprContext) => Result;
92
+ visitRoundedBracketsExpr?: (ctx: RoundedBracketsExprContext) => Result;
93
+ visitBinary_operator?: (ctx: Binary_operatorContext) => Result;
94
+ visitUnary_operator?: (ctx: Unary_operatorContext) => Result;
95
+ visitValue_expr?: (ctx: Value_exprContext) => Result;
96
+ visitFunction_def_expr?: (ctx: Function_def_exprContext) => Result;
97
+ visitFunction_expr?: (ctx: Function_exprContext) => Result;
98
+ visitFunction_args_expr?: (ctx: Function_args_exprContext) => Result;
99
+ visitAtom_expr?: (ctx: Atom_exprContext) => Result;
100
+ visitTrailer_expr?: (ctx: Trailer_exprContext) => Result;
101
+ visitNet_namespace_expr?: (ctx: Net_namespace_exprContext) => Result;
102
+ visitFunction_return_expr?: (ctx: Function_return_exprContext) => Result;
103
+ visitCreate_component_expr?: (ctx: Create_component_exprContext) => Result;
104
+ visitCreate_graphic_expr?: (ctx: Create_graphic_exprContext) => Result;
105
+ visitSub_expr?: (ctx: Sub_exprContext) => Result;
106
+ visitProperty_expr?: (ctx: Property_exprContext) => Result;
107
+ visitProperty_key_expr?: (ctx: Property_key_exprContext) => Result;
108
+ visitNested_properties?: (ctx: Nested_propertiesContext) => Result;
109
+ visitSingle_line_property?: (ctx: Single_line_propertyContext) => Result;
110
+ visitBlank_expr?: (ctx: Blank_exprContext) => Result;
111
+ visitWire_expr?: (ctx: Wire_exprContext) => Result;
112
+ visitPoint_expr?: (ctx: Point_exprContext) => Result;
113
+ visitImport_expr?: (ctx: Import_exprContext) => Result;
114
+ visitFrame_expr?: (ctx: Frame_exprContext) => Result;
115
+ }
@@ -0,0 +1,162 @@
1
+ import { G } from "@svgdotjs/svg.js";
2
+ import { Feature, GeometryProp, HorizontalAlign, Label, LabelStyle, VerticalAlign } from "./geometry.js";
3
+ import { Logger } from "./logger.js";
4
+ export declare abstract class SymbolGraphic {
5
+ drawPortsName: boolean;
6
+ displayBounds: boolean;
7
+ drawing: SymbolDrawing;
8
+ _angle: number;
9
+ width: number;
10
+ height: number;
11
+ labelTexts: Map<string, string>;
12
+ get angle(): number;
13
+ set angle(value: number);
14
+ refreshDrawing(calculateSize?: boolean): void;
15
+ calculateSize(): void;
16
+ abstract generateDrawing(): void;
17
+ size(): {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ draw(group: G, extra?: {}): void;
22
+ drawPlaceRemove(group: G, extra?: {
23
+ place?: boolean;
24
+ }): void;
25
+ pinPosition(id: number): {
26
+ x: number;
27
+ y: number;
28
+ angle: number;
29
+ };
30
+ protected drawBounds(group: G): void;
31
+ protected drawBody(group: G): void;
32
+ protected drawPins(group: G): void;
33
+ protected drawLabels(group: G): void;
34
+ flipTextAnchor(value: HorizontalAlign): HorizontalAlign;
35
+ flipDominantBaseline(value: VerticalAlign): VerticalAlign;
36
+ setLabelValue(labelId: string, labelValue: string): void;
37
+ getLabelValue(labelId: string): string;
38
+ }
39
+ export declare function SymbolFactory(name: string): SymbolGraphic | null;
40
+ export declare class SymbolPointHidden extends SymbolGraphic {
41
+ generateDrawing(): void;
42
+ }
43
+ export declare class SymbolText extends SymbolGraphic {
44
+ text: string;
45
+ fontSize: number;
46
+ fontWeight: string;
47
+ constructor(text: string);
48
+ generateDrawing(): void;
49
+ }
50
+ export declare class SymbolPlaceholder extends SymbolGraphic {
51
+ generateDrawing(): void;
52
+ drawPinParams(drawing: SymbolDrawingCommands, commandName: string, keywordParams: Map<string, any>, positionParams: any[]): void;
53
+ constructor(drawing: SymbolDrawing);
54
+ }
55
+ export declare enum PlaceHolderCommands {
56
+ arc = "arc",
57
+ circle = "circle",
58
+ rect = "rect",
59
+ triangle = "triangle",
60
+ pin = "pin",
61
+ hpin = "hpin",
62
+ vpin = "vpin",
63
+ hline = "hline",
64
+ vline = "vline",
65
+ line = "line",
66
+ label = "label",
67
+ path = "path",
68
+ lineWidth = "lineWidth",
69
+ fill = "fill",
70
+ lineColor = "lineColor"
71
+ }
72
+ export declare class SymbolCustom extends SymbolGraphic {
73
+ pinDefinition: SymbolPinDefintion[];
74
+ bodyWidth: number;
75
+ pinLength: number;
76
+ width: number;
77
+ height: number;
78
+ pinSpacing: number;
79
+ pinTextPadding: number;
80
+ pins: SymbolPinLayout[];
81
+ _cacheLeftPins: SymbolPinDefintion[];
82
+ _cacheRightPins: SymbolPinDefintion[];
83
+ constructor(pinDefinition: SymbolPinDefintion[]);
84
+ generateDrawing(): void;
85
+ calculateSize(): void;
86
+ }
87
+ export declare class SymbolDrawing {
88
+ items: (Feature | GeometryProp)[];
89
+ pins: [number, Feature, number][];
90
+ angle: number;
91
+ mainOrigin: [number, number];
92
+ logger: Logger;
93
+ clear(): void;
94
+ log(...params: any[]): void;
95
+ addLine(startX: number, startY: number, endX: number, endY: number): SymbolDrawing;
96
+ addPin(pinId: number, startX: number, startY: number, endX: number, endY: number): SymbolDrawing;
97
+ addVLine(startX: number, startY: number, value: number): SymbolDrawing;
98
+ addHLine(startX: number, startY: number, value: number): SymbolDrawing;
99
+ addRect(centerX: number, centerY: number, width: number, height: number): SymbolDrawing;
100
+ addTriangle(startX: number, startY: number, endX: number, endY: number, width: number): SymbolDrawing;
101
+ addRect2(x: number, y: number, x2: number, y2: number): SymbolDrawing;
102
+ addLabel(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
103
+ addLabelId(id: string, x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
104
+ addPath(...pathParts: any): SymbolDrawing;
105
+ addSetLineWidth(value: number): SymbolDrawing;
106
+ addSetLineColor(value: string): SymbolDrawing;
107
+ addSetFillColor(value: string): SymbolDrawing;
108
+ addArc(x: number, y: number, radius: number, startAngle: number, endAngle: number): SymbolDrawing;
109
+ getPaths(): {
110
+ path: string;
111
+ fillColor: string;
112
+ lineColor: string;
113
+ lineWidth: number;
114
+ }[];
115
+ getPinsPath(): string;
116
+ getLabels(): Label[];
117
+ private featuresToPath;
118
+ getBoundingBox(excludeLabels?: boolean): {
119
+ width: number;
120
+ height: number;
121
+ start: SimplePoint;
122
+ end: SimplePoint;
123
+ };
124
+ getPinPosition(pinId: number): {
125
+ start: [number, number];
126
+ end: [number, number];
127
+ angle: number;
128
+ };
129
+ }
130
+ export type SubExpressionCommand = [
131
+ commandName: string,
132
+ positionParams: any[],
133
+ keywordParams: Map<string, any>
134
+ ];
135
+ export declare class SymbolDrawingCommands extends SymbolDrawing {
136
+ id: string;
137
+ private commands;
138
+ constructor(commands: SubExpressionCommand[]);
139
+ getCommands(): SubExpressionCommand[];
140
+ clone(): SymbolDrawingCommands;
141
+ }
142
+ type SimplePoint = [x: number, y: number];
143
+ type SymbolPinLayout = {
144
+ pinId: number;
145
+ angle: number;
146
+ text: string;
147
+ start: {
148
+ x: number;
149
+ y: number;
150
+ };
151
+ end: {
152
+ x: number;
153
+ y: number;
154
+ };
155
+ };
156
+ export type SymbolPinDefintion = {
157
+ side: string;
158
+ pinId: number;
159
+ text: string;
160
+ position: number;
161
+ };
162
+ export {};
@@ -0,0 +1,85 @@
1
+ import { BlockTypes } from './globals.js';
2
+ import { ClassComponent } from './objects/ClassComponent.js';
3
+ import { ExecutionScope } from './objects/ExecutionScope.js';
4
+ import { Net } from './objects/Net.js';
5
+ import { ParamDefinition } from './objects/ParamDefinition.js';
6
+ import { PinDefinition } from './objects/PinDefinition.js';
7
+ import { CFunction, CFunctionResult, CallableParameter, ComponentPin, ReferenceType } from './objects/types.js';
8
+ import { Logger } from './logger.js';
9
+ export declare class ExecutionContext {
10
+ name: string;
11
+ namespace: string;
12
+ netNamespace: string;
13
+ executionLevel: number;
14
+ scope: ExecutionScope;
15
+ tmpPointId: number;
16
+ resolveNet: (name: string, netNamespace: string) => ({
17
+ found: boolean;
18
+ net?: Net;
19
+ });
20
+ stopFurtherExpressions: boolean;
21
+ returnValue: any;
22
+ silent: boolean;
23
+ logger: Logger;
24
+ __functionCache: {};
25
+ constructor(name: string, namespace: string, netNamespace: string, executionLevel: number, indentLevel: number, silent: boolean, logger: Logger);
26
+ print(...params: any[]): void;
27
+ private setupRoot;
28
+ instanceExists(instanceName: string): boolean;
29
+ getComponent(instanceName: string): ClassComponent;
30
+ getUniqueInstanceName(className: string): string;
31
+ getUniqueNetName(): string;
32
+ getCurrentPoint(): ComponentPin;
33
+ private linkComponentPinNet;
34
+ private mergeNets;
35
+ createComponent(instanceName: string, pins: PinDefinition[], params: ParamDefinition[], props: {
36
+ arrange?: Map<string, number[]>;
37
+ display?: string;
38
+ type?: string;
39
+ width?: number;
40
+ }): ClassComponent;
41
+ printPoint(extra?: string): void;
42
+ addComponentExisting(component: ClassComponent, pin: number): ComponentPin;
43
+ toComponent(component: ClassComponent, pinId: number | null, options?: {
44
+ addSequence?: boolean;
45
+ cloneNetComponent?: boolean;
46
+ }): ComponentPin;
47
+ atComponent(component: ClassComponent, pinId: number | null, options?: {
48
+ addSequence?: boolean;
49
+ cloneNetComponent?: boolean;
50
+ }): ComponentPin;
51
+ private isNetOnlyComponent;
52
+ private cloneComponent;
53
+ enterBlocks(blockType: BlockTypes): void;
54
+ exitBlocks(): void;
55
+ enterBlock(blockIndex: number): void;
56
+ exitBlock(blockIndex: number): void;
57
+ atPointBlock(): void;
58
+ toPointBlock(): void;
59
+ getPointBlockLocation(): [component: ClassComponent, pin: number, wireId: number];
60
+ breakBranch(): void;
61
+ createFunction(functionName: string, __runFunc: CFunction): void;
62
+ hasFunction(functionName: string): boolean;
63
+ getFunction(functionName: string): CFunction;
64
+ resolveVariable(executionStack: ExecutionContext[], idName: string): ReferenceType;
65
+ callFunction(functionName: string, functionParams: CallableParameter[], executionStack: ExecutionContext[], netNamespace: string): CFunctionResult;
66
+ mergeScope(childScope: ExecutionScope, namespace: string): void;
67
+ addWire(segments: [string, number?][]): void;
68
+ addPoint(pointId: string, userDefined?: boolean): ComponentPin;
69
+ setProperty(nameWithProp: string, value: any): void;
70
+ setCurrentComponentStyle(styles: {
71
+ [key: string]: number | string;
72
+ }): void;
73
+ enterFrame(): number;
74
+ exitFrame(frameId: number): void;
75
+ }
76
+ export declare function isNetComponent(component: ClassComponent): boolean;
77
+ export declare function isLabelComponent(component: ClassComponent): boolean;
78
+ export declare function getPortSide(pins: Map<number, PinDefinition>, arrangeProps: null | Map<string, number[]>): PortSideItem[];
79
+ type PortSideItem = {
80
+ pinId: number;
81
+ side: string;
82
+ order: number;
83
+ position: number;
84
+ };
85
+ export {};
@@ -0,0 +1,2 @@
1
+ import { NetListItem } from "./visitor.js";
2
+ export declare function generateKiCADNetList(netlist: NetListItem[]): string;