circuitscript 0.1.4 → 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 +149 -80
- package/dist/cjs/SemanticTokenVisitor.js +19 -13
- package/dist/cjs/antlr/CircuitScriptParser.js +711 -671
- package/dist/cjs/builtinMethods.js +48 -22
- package/dist/cjs/draw_symbols.js +4 -1
- package/dist/cjs/environment.js +118 -0
- package/dist/cjs/execute.js +98 -46
- package/dist/cjs/geometry.js +1 -0
- package/dist/cjs/globals.js +14 -7
- package/dist/cjs/helpers.js +142 -150
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/layout.js +39 -14
- package/dist/cjs/main.js +34 -21
- package/dist/cjs/objects/ClassComponent.js +4 -1
- package/dist/cjs/objects/ExecutionScope.js +40 -2
- 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 +10 -60
- package/dist/cjs/utils.js +148 -17
- 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 +149 -31
- package/dist/esm/{BaseVisitor.mjs → BaseVisitor.js} +124 -56
- 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} +40 -14
- package/dist/esm/{draw_symbols.mjs → draw_symbols.js} +11 -8
- package/dist/esm/environment.js +110 -0
- package/dist/esm/{execute.mjs → execute.js} +111 -58
- 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} +9 -2
- package/dist/esm/helpers.js +377 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/{layout.mjs → layout.js} +44 -22
- package/dist/esm/{lexer.mjs → lexer.js} +2 -2
- package/dist/esm/{main.mjs → main.js} +36 -23
- package/dist/esm/objects/{ClassComponent.mjs → ClassComponent.js} +9 -5
- package/dist/esm/objects/{ExecutionScope.mjs → ExecutionScope.js} +40 -2
- 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} +11 -36
- package/dist/esm/utils.js +286 -0
- 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} +160 -42
- 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 +36 -22
- 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/draw_symbols.d.ts +2 -6
- package/dist/types/environment.d.ts +31 -0
- package/dist/types/execute.d.ts +2 -3
- package/dist/types/globals.d.ts +7 -2
- package/dist/types/helpers.d.ts +12 -14
- package/dist/types/index.d.ts +5 -0
- package/dist/types/objects/ClassComponent.d.ts +2 -3
- package/dist/types/objects/ExecutionScope.d.ts +20 -6
- 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 +33 -4
- 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/libs/lib.cst +12 -22
- 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 -380
- package/dist/esm/index.mjs +0 -15
- package/dist/esm/parser.mjs +0 -64
- package/dist/esm/utils.mjs +0 -169
- 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/types/helpers.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseError } from "./utils.js";
|
|
2
|
+
import { SymbolValidatorVisitor } from "./validate/SymbolValidatorVisitor.js";
|
|
2
3
|
import { CommonTokenStream, DefaultErrorStrategy, Parser } from "antlr4ng";
|
|
3
4
|
import { CircuitScriptParser } from "./antlr/CircuitScriptParser.js";
|
|
4
5
|
import { CircuitScriptLexer } from "./antlr/CircuitScriptLexer.js";
|
|
5
6
|
import { IParsedToken, SemanticTokensVisitor } from "./SemanticTokenVisitor.js";
|
|
6
7
|
import { LengthUnit } from "./globals.js";
|
|
8
|
+
export type SVGWindow = any;
|
|
7
9
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
10
|
+
import { NodeScriptEnvironment } from "./environment.js";
|
|
8
11
|
export declare enum JSModuleType {
|
|
9
12
|
CommonJs = "cjs",
|
|
10
13
|
ESM = "mjs"
|
|
11
14
|
}
|
|
12
15
|
export type ScriptOptions = {
|
|
13
|
-
currentDirectory: string | null;
|
|
14
|
-
defaultLibsPath: string;
|
|
15
16
|
dumpNets: boolean;
|
|
16
17
|
dumpData: boolean;
|
|
17
18
|
showStats: boolean;
|
|
19
|
+
environment: NodeScriptEnvironment;
|
|
18
20
|
};
|
|
19
21
|
export declare function prepareFile(textData: string): {
|
|
20
22
|
parser: CircuitScriptParser;
|
|
@@ -22,23 +24,19 @@ export declare function prepareFile(textData: string): {
|
|
|
22
24
|
lexerTimeTaken: number;
|
|
23
25
|
tokens: CommonTokenStream;
|
|
24
26
|
};
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function getSemanticTokens(scriptData: string, options: ScriptOptions): {
|
|
27
|
+
export declare function getSemanticTokens(scriptData: string, options: ScriptOptions): Promise<{
|
|
27
28
|
visitor: SemanticTokensVisitor;
|
|
28
29
|
parsedTokens: IParsedToken[];
|
|
29
|
-
}
|
|
30
|
+
}>;
|
|
30
31
|
export declare class ParseErrorStrategy extends DefaultErrorStrategy {
|
|
31
32
|
reportUnwantedToken(recognizer: Parser): void;
|
|
32
33
|
}
|
|
33
|
-
export declare function validateScript(scriptData: string, options: ScriptOptions): SymbolValidatorVisitor
|
|
34
|
-
export declare function renderScript(scriptData: string, outputPath: string, options: ScriptOptions):
|
|
34
|
+
export declare function validateScript(filePath: string, scriptData: string, options: ScriptOptions): Promise<SymbolValidatorVisitor>;
|
|
35
|
+
export declare function renderScript(scriptData: string, outputPath: string | null, options: ScriptOptions): Promise<{
|
|
36
|
+
svgOutput: string | null;
|
|
37
|
+
errors: BaseError[];
|
|
38
|
+
}>;
|
|
35
39
|
export declare function detectJSModuleType(): JSModuleType;
|
|
36
|
-
export declare function getCurrentPath(): {
|
|
37
|
-
filePath: string;
|
|
38
|
-
};
|
|
39
|
-
export declare function getFontsPath(): string;
|
|
40
|
-
export declare function getDefaultLibsPath(): string;
|
|
41
|
-
export declare function getPackageVersion(): string;
|
|
42
40
|
export declare class UnitDimension {
|
|
43
41
|
type: LengthUnit;
|
|
44
42
|
value: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,3 +13,8 @@ export * from './utils.js';
|
|
|
13
13
|
export * from './visitor.js';
|
|
14
14
|
export * from './sizing.js';
|
|
15
15
|
export * from './objects/types.js';
|
|
16
|
+
export * from './builtinMethods.js';
|
|
17
|
+
export * from './validate/SymbolTable.js';
|
|
18
|
+
export * from './validate/SymbolValidatorResolveVisitor.js';
|
|
19
|
+
export * from './validate/SymbolValidatorVisitor.js';
|
|
20
|
+
export * from './environment.js';
|
|
@@ -12,13 +12,12 @@ export declare class ClassComponent {
|
|
|
12
12
|
pins: Map<number, PinDefinition>;
|
|
13
13
|
pinNets: Map<number, Net>;
|
|
14
14
|
pinWires: Map<number, WireSegment[]>;
|
|
15
|
-
pinsMaxPositions:
|
|
16
|
-
[key: string]: number;
|
|
17
|
-
};
|
|
15
|
+
pinsMaxPositions: Map<string, number>;
|
|
18
16
|
_cachedPins: string;
|
|
19
17
|
_cachedParams: string;
|
|
20
18
|
_copyID?: number;
|
|
21
19
|
_copyFrom?: ClassComponent;
|
|
20
|
+
_pointLinkComponent?: ClassComponent;
|
|
22
21
|
arrangeProps: Map<string, NumericValue[]> | null;
|
|
23
22
|
displayProp: SymbolDrawingCommands | null;
|
|
24
23
|
widthProp: number | null;
|
|
@@ -5,6 +5,8 @@ import { LayoutDirection } from '../globals.js';
|
|
|
5
5
|
import { Wire, WireSegment } from './Wire.js';
|
|
6
6
|
import { Frame } from './Frame.js';
|
|
7
7
|
import { ParserRuleContext } from 'antlr4ng';
|
|
8
|
+
type OnPropertyHandler = (path: PropertyTreeKey[], value: any, valueContext: ParserRuleContext) => void;
|
|
9
|
+
export type PropertyTreeKey = [ctx: ParserRuleContext, value: any] | ['index', number];
|
|
8
10
|
export declare class ExecutionScope {
|
|
9
11
|
scopeId: number;
|
|
10
12
|
private nets;
|
|
@@ -15,6 +17,8 @@ export declare class ExecutionScope {
|
|
|
15
17
|
type: ParseSymbolType;
|
|
16
18
|
}>;
|
|
17
19
|
blockStack: Map<number, any>;
|
|
20
|
+
contextStack: ParserRuleContext[];
|
|
21
|
+
onPropertyHandler: OnPropertyHandler[];
|
|
18
22
|
breakStack: ParserRuleContext[];
|
|
19
23
|
wires: Wire[];
|
|
20
24
|
frames: Frame[];
|
|
@@ -25,8 +29,6 @@ export declare class ExecutionScope {
|
|
|
25
29
|
currentPin: number | null;
|
|
26
30
|
currentWireId: number;
|
|
27
31
|
currentFrameId: number;
|
|
28
|
-
netGnd: Net | null;
|
|
29
|
-
componentGnd: ClassComponent | null;
|
|
30
32
|
componentRoot: ClassComponent | null;
|
|
31
33
|
copyIDs: Map<string, number>;
|
|
32
34
|
sequence: SequenceItem[];
|
|
@@ -35,6 +37,7 @@ export declare class ExecutionScope {
|
|
|
35
37
|
static create(): ExecutionScope;
|
|
36
38
|
private findNet;
|
|
37
39
|
getNetWithName(name: string): Net;
|
|
40
|
+
getNetWithNamespacePath(namespace: string, name: string): Net | null;
|
|
38
41
|
hasNet(component: ClassComponent, pin: number): boolean;
|
|
39
42
|
getNet(component: ClassComponent, pin: number): Net | null;
|
|
40
43
|
setNet(component: ClassComponent, pin: number, net: Net): void;
|
|
@@ -45,13 +48,20 @@ export declare class ExecutionScope {
|
|
|
45
48
|
setActive(type: ActiveObject, item: any): void;
|
|
46
49
|
clearActive(): void;
|
|
47
50
|
setCurrent(component: ClassComponent | null, pin?: number | null): void;
|
|
51
|
+
enterContext(context: ParserRuleContext): void;
|
|
52
|
+
exitContext(): ParserRuleContext;
|
|
53
|
+
findPropertyKeyTree(): PropertyTreeKey[];
|
|
54
|
+
setOnPropertyHandler(handler: OnPropertyHandler): void;
|
|
55
|
+
popOnPropertyHandler(): OnPropertyHandler;
|
|
56
|
+
triggerPropertyHandler(value: any, valueCtx: ParserRuleContext): void;
|
|
48
57
|
}
|
|
49
58
|
export declare enum SequenceAction {
|
|
50
59
|
To = "to",
|
|
51
60
|
At = "at",
|
|
52
61
|
Wire = "wire",
|
|
53
62
|
WireJump = "wire-jump",
|
|
54
|
-
Frame = "frame"
|
|
63
|
+
Frame = "frame",
|
|
64
|
+
Assign = "assign"
|
|
55
65
|
}
|
|
56
66
|
export declare enum FrameAction {
|
|
57
67
|
Enter = "enter",
|
|
@@ -61,10 +71,14 @@ export declare enum ActiveObject {
|
|
|
61
71
|
Frame = "frame",
|
|
62
72
|
Wire = "wire"
|
|
63
73
|
}
|
|
64
|
-
export type
|
|
74
|
+
export type SequenceActionAtTo = [
|
|
65
75
|
SequenceAction.To | SequenceAction.At,
|
|
66
76
|
ClassComponent,
|
|
67
|
-
number,
|
|
77
|
+
pinId: number,
|
|
68
78
|
LayoutDirection?,
|
|
69
79
|
string?
|
|
70
|
-
]
|
|
80
|
+
];
|
|
81
|
+
export type SequenceActionWire = [SequenceAction.Wire, wireId: number, WireSegment[]];
|
|
82
|
+
export type SequenceActionAssign = [SequenceAction.Assign, variable: string, ClassComponent];
|
|
83
|
+
export type SequenceItem = SequenceActionAtTo | SequenceActionWire | [SequenceAction.WireJump, wireId: number, pinId: number] | [SequenceAction.Frame, Frame, "enter" | "exit"] | SequenceActionAssign;
|
|
84
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Token } from 'antlr4ng';
|
|
1
2
|
import { ExecutionContext } from '../execute.js';
|
|
2
3
|
import { ClassComponent } from './ClassComponent.js';
|
|
3
4
|
import { Net } from './Net.js';
|
|
@@ -35,7 +36,11 @@ export type CallableParameter = [
|
|
|
35
36
|
key: number,
|
|
36
37
|
value: ValueType
|
|
37
38
|
];
|
|
38
|
-
export type FunctionDefinedParameter = [
|
|
39
|
+
export type FunctionDefinedParameter = [
|
|
40
|
+
name: string,
|
|
41
|
+
token: Token,
|
|
42
|
+
defaultValue: ValueType
|
|
43
|
+
] | [name: string, token: Token];
|
|
39
44
|
export declare class UndeclaredReference {
|
|
40
45
|
reference: ReferenceType;
|
|
41
46
|
constructor(reference: ReferenceType);
|
package/dist/types/parser.d.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { CircuitScriptParser, ScriptContext } from './antlr/CircuitScriptParser.js';
|
|
2
|
-
import { ANTLRErrorListener, ATNConfigSet, ATNSimulator, BitSet,
|
|
3
|
-
import { BaseVisitor,
|
|
4
|
-
export declare function parseFileWithVisitor(visitor: BaseVisitor, data: string): {
|
|
2
|
+
import { ANTLRErrorListener, ATNConfigSet, ATNSimulator, BitSet, DFA, Parser, RecognitionException, Recognizer, Token } from 'antlr4ng';
|
|
3
|
+
import { BaseVisitor, OnErrorHandler } from './BaseVisitor.js';
|
|
4
|
+
export declare function parseFileWithVisitor(visitor: BaseVisitor, data: string): Promise<{
|
|
5
5
|
tree: ScriptContext;
|
|
6
6
|
parser: CircuitScriptParser;
|
|
7
7
|
hasError: boolean;
|
|
8
8
|
hasParseError: boolean;
|
|
9
9
|
parserTimeTaken: number;
|
|
10
10
|
lexerTimeTaken: number;
|
|
11
|
-
}
|
|
12
|
-
export declare class TempErrorStrategy extends DefaultErrorStrategy {
|
|
13
|
-
recover(recognizer: Parser, e: RecognitionException): void;
|
|
14
|
-
reportError(recognizer: Parser, e: RecognitionException): void;
|
|
15
|
-
}
|
|
11
|
+
}>;
|
|
16
12
|
export declare class CircuitscriptParserErrorListener implements ANTLRErrorListener {
|
|
17
13
|
syntaxErrorCounter: number;
|
|
18
|
-
onErrorHandler:
|
|
19
|
-
constructor(onErrorHandler?:
|
|
20
|
-
syntaxError<S extends Token, T extends ATNSimulator>(recognizer: Recognizer<T>, offendingSymbol: S | null, line: number,
|
|
14
|
+
onErrorHandler: OnErrorHandler | null;
|
|
15
|
+
constructor(onErrorHandler?: OnErrorHandler | null);
|
|
16
|
+
syntaxError<S extends Token, T extends ATNSimulator>(recognizer: Recognizer<T>, offendingSymbol: S | null, line: number, column: number, msg: string, e: RecognitionException | null): void;
|
|
21
17
|
reportAmbiguity(recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, exact: boolean, ambigAlts: BitSet | undefined, configs: ATNConfigSet): void;
|
|
22
18
|
reportAttemptingFullContext(recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, conflictingAlts: BitSet | undefined, configs: ATNConfigSet): void;
|
|
23
19
|
reportContextSensitivity(recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, prediction: number, configs: ATNConfigSet): void;
|
package/dist/types/sizing.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Box, SVGTypeMapping } from '@svgdotjs/svg.js';
|
|
2
2
|
import { HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
3
|
-
import { SVGWindow } from 'svgdom';
|
|
4
|
-
export declare function prepareSVGEnvironment(fontsPath: string | null): Promise<void>;
|
|
5
|
-
export declare function getCreateSVGWindow(): () => SVGWindow;
|
|
6
3
|
export declare function applyFontsToSVG(canvas: SVGTypeMapping): void;
|
|
7
4
|
export declare function measureTextSize2(text: string, fontFamily: string, fontSize: number, fontWeight?: string, anchor?: HorizontalAlign, vanchor?: VerticalAlign): {
|
|
8
5
|
width: number;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Big } from 'big.js';
|
|
2
|
-
import { ParserRuleContext } from "antlr4ng";
|
|
3
|
-
import { ClassComponent } from "./objects/ClassComponent";
|
|
4
|
-
import { NumericValue } from "./objects/ParamDefinition";
|
|
2
|
+
import { ParserRuleContext, Token } from "antlr4ng";
|
|
3
|
+
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
4
|
+
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
5
|
+
import { SequenceAction, SequenceItem } from './objects/ExecutionScope.js';
|
|
6
|
+
import { BlockTypes } from './globals.js';
|
|
5
7
|
export declare class SimpleStopwatch {
|
|
6
8
|
startTime: Date;
|
|
7
9
|
constructor();
|
|
@@ -29,10 +31,37 @@ export declare function getBoundsSize(bounds: BoundBox): {
|
|
|
29
31
|
};
|
|
30
32
|
export declare function getPortType(component: ClassComponent): string | null;
|
|
31
33
|
export declare function roundValue(value: NumericValue): NumericValue;
|
|
32
|
-
export declare function throwWithContext(context: ParserRuleContext,
|
|
34
|
+
export declare function throwWithContext(context: ParserRuleContext, messageOrError: string | BaseError): void;
|
|
35
|
+
export declare function throwWithToken(message: string, token: Token): void;
|
|
36
|
+
export declare function throwWithTokenRange(message: string, startToken: Token, endToken?: Token): void;
|
|
33
37
|
export declare function combineMaps(map1: Map<string, any>, map2: Map<string, any>): Map<string, any>;
|
|
34
38
|
export declare function getNumberExponential(value: string): number;
|
|
35
39
|
export declare function getNumberExponentialText(value: number): string;
|
|
36
40
|
export declare function resolveToNumericValue(value: Big): NumericValue;
|
|
37
41
|
export declare function isPointWithinArea(point: [x: number, y: number], bounds: BoundBox2): boolean;
|
|
38
42
|
export declare function areasOverlap(area1: BoundBox2, area2: BoundBox2): boolean;
|
|
43
|
+
export declare function sequenceActionString(sequenceAction: SequenceAction): string;
|
|
44
|
+
export declare function generateDebugSequenceAction(sequence: SequenceItem[]): string[];
|
|
45
|
+
export declare function getBlockTypeString(type: BlockTypes): string;
|
|
46
|
+
export declare class BaseError extends Error {
|
|
47
|
+
name: string;
|
|
48
|
+
message: string;
|
|
49
|
+
startToken?: Token;
|
|
50
|
+
endToken?: Token;
|
|
51
|
+
filePath?: string;
|
|
52
|
+
constructor(message: string, startToken?: Token, endToken?: Token, filePath?: string);
|
|
53
|
+
toString(): string;
|
|
54
|
+
}
|
|
55
|
+
export declare class ParseSyntaxError extends BaseError {
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
export declare class ParseError extends ParseSyntaxError {
|
|
59
|
+
name: string;
|
|
60
|
+
}
|
|
61
|
+
export declare class RuntimeExecutionError extends BaseError {
|
|
62
|
+
name: string;
|
|
63
|
+
}
|
|
64
|
+
export declare class RenderError extends Error {
|
|
65
|
+
stage?: string;
|
|
66
|
+
constructor(message: string, stage?: string);
|
|
67
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TerminalNode, Token } from "antlr4ng";
|
|
2
|
+
import { ExecutionContext } from "../execute.js";
|
|
3
|
+
import { FunctionDefinedParameter, ParseSymbolType, ValueType } from "../objects/types.js";
|
|
4
|
+
export declare class SymbolTable {
|
|
5
|
+
protected symbols: Map<string, SymbolTableItem>;
|
|
6
|
+
executonContextsNamespaces: string[];
|
|
7
|
+
getSymbols(): Map<string, SymbolTableItem>;
|
|
8
|
+
addFunction(token: Token | null, fileName: string, executionContext: ExecutionContext, id: string, funcDefinedParameters: FunctionDefinedParameter[]): SymbolTableItem;
|
|
9
|
+
addVariable(token: Token, fileName: string, executionContext: ExecutionContext, id: string, variableValue: SymbolTableItem | ValueType | null): SymbolTableItem;
|
|
10
|
+
addUndefined(filePath: string, executionContext: ExecutionContext, id: string, token: Token): SymbolTableItem;
|
|
11
|
+
add(fileName: string, executionContext: ExecutionContext, id: string, type: ParseSymbolType, extra: SymbolTableItemExtra, token: Token | null): SymbolTableItem;
|
|
12
|
+
protected idName(executionContext: ExecutionContext, id: string): string;
|
|
13
|
+
dumpSymbols(): void;
|
|
14
|
+
exists(executionContext: ExecutionContext, id: string): boolean;
|
|
15
|
+
existsAny(executionContext: ExecutionContext, id: string): boolean;
|
|
16
|
+
get(executionContext: ExecutionContext, id: string): SymbolTableItem;
|
|
17
|
+
getParentContexts(executionContext: ExecutionContext, contextsNamespace: string[]): string[];
|
|
18
|
+
searchParentContext(executionContext: ExecutionContext, id: string): ExecutionContext | null;
|
|
19
|
+
clearUndefined(): void;
|
|
20
|
+
}
|
|
21
|
+
export type SymbolTableItemDefined = {
|
|
22
|
+
id: string;
|
|
23
|
+
type: ParseSymbolType;
|
|
24
|
+
context: ExecutionContext;
|
|
25
|
+
fileName: string;
|
|
26
|
+
token: Token | null;
|
|
27
|
+
extra: SymbolTableItemExtra;
|
|
28
|
+
instances: Token[];
|
|
29
|
+
};
|
|
30
|
+
export type SymbolTableItemUndefined = {
|
|
31
|
+
type: ParseSymbolType.Undefined;
|
|
32
|
+
extra: SymbolTableItemExtra;
|
|
33
|
+
token: Token | null;
|
|
34
|
+
};
|
|
35
|
+
export type SymbolTableItem = SymbolTableItemDefined | SymbolTableItemUndefined;
|
|
36
|
+
export type SymbolTableItemExtra = {
|
|
37
|
+
funcDefinedParameters?: FunctionDefinedParameter[];
|
|
38
|
+
variableValue?: SymbolTableItem | ValueType | null;
|
|
39
|
+
node?: TerminalNode;
|
|
40
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Token } from "antlr4ng";
|
|
2
|
+
import { ComplexType, FunctionDefinedParameter } from "../objects/types.js";
|
|
3
|
+
import { SymbolValidatorVisitor } from "./SymbolValidatorVisitor.js";
|
|
4
|
+
export declare class SymbolValidatorResolveVisitor extends SymbolValidatorVisitor {
|
|
5
|
+
protected addSymbolVariable(token: Token, name: string, value: ComplexType): void;
|
|
6
|
+
protected addSymbolFunction(token: Token, functionName: string, funcDefinedParameters: FunctionDefinedParameter[]): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TerminalNode, Token } from "antlr4ng";
|
|
2
|
+
import { Import_exprContext, Assignment_exprContext, Atom_exprContext, Function_call_exprContext, ValueAtomExprContext, UnaryOperatorExprContext, MultiplyExprContext, AdditionExprContext, BinaryOperatorExprContext, DataExprContext, Function_def_exprContext } from "src/antlr/CircuitScriptParser";
|
|
3
|
+
import { ExecutionContext } from "../execute.js";
|
|
4
|
+
import { ComplexType, FunctionDefinedParameter } from "../objects/types.js";
|
|
5
|
+
import { SymbolTableItem } from "./SymbolTable.js";
|
|
6
|
+
import { SymbolTable } from "./SymbolTable.js";
|
|
7
|
+
import { BaseVisitor } from "../BaseVisitor.js";
|
|
8
|
+
export declare class SymbolValidatorVisitor extends BaseVisitor {
|
|
9
|
+
symbolTable: SymbolTable;
|
|
10
|
+
filePathStack: string[];
|
|
11
|
+
enterFile(filePath: string): void;
|
|
12
|
+
exitFile(): void;
|
|
13
|
+
getCurrentFile(): string;
|
|
14
|
+
protected addSymbolVariable(token: Token, name: string, value: ComplexType, executor?: ExecutionContext | null): void;
|
|
15
|
+
protected addSymbolFunction(token: Token, functionName: string, funcDefinedParameters: FunctionDefinedParameter[]): void;
|
|
16
|
+
protected handleAtomSymbol(atom: TerminalNode): SymbolTableItem;
|
|
17
|
+
protected addSymbolInstance(symbol: SymbolTableItem, token: Token): void;
|
|
18
|
+
setSymbols(symbolTable: SymbolTable): void;
|
|
19
|
+
visitImport_expr: (ctx: Import_exprContext) => void;
|
|
20
|
+
visitAssignment_expr: (ctx: Assignment_exprContext) => ComplexType;
|
|
21
|
+
visitAtom_expr: (ctx: Atom_exprContext) => void;
|
|
22
|
+
visitFunction_call_expr: (ctx: Function_call_exprContext) => void;
|
|
23
|
+
visitValueAtomExpr: (ctx: ValueAtomExprContext) => void;
|
|
24
|
+
visitUnaryOperatorExpr: (ctx: UnaryOperatorExprContext) => void;
|
|
25
|
+
visitMultiplyExpr: (ctx: MultiplyExprContext) => void;
|
|
26
|
+
visitAdditionExpr: (ctx: AdditionExprContext) => void;
|
|
27
|
+
visitBinaryOperatorExpr: (ctx: BinaryOperatorExprContext) => void;
|
|
28
|
+
visitDataExpr: (ctx: DataExprContext) => void;
|
|
29
|
+
visitFunction_def_expr: (ctx: Function_def_exprContext) => void;
|
|
30
|
+
getSymbols(): SymbolTable;
|
|
31
|
+
dumpSymbols(): void;
|
|
32
|
+
}
|
package/dist/types/validate.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
export
|
|
2
|
+
export default function validate(): Promise<void>;
|
package/libs/lib.cst
CHANGED
|
@@ -15,18 +15,8 @@ def net(net_name):
|
|
|
15
15
|
priority: 10
|
|
16
16
|
|
|
17
17
|
def supply(net_name):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
copy: true
|
|
21
|
-
angle: -90
|
|
22
|
-
display: create graphic (params):
|
|
23
|
-
hline: -50, 0, 100
|
|
24
|
-
vpin: 1, 0, 50, -50, display_pin_id=false
|
|
25
|
-
label: params.net_name, 0, -15, fontSize=50, anchor="middle"
|
|
26
|
-
type: "net"
|
|
27
|
-
params:
|
|
28
|
-
net_name: net_name
|
|
29
|
-
priority: 20
|
|
18
|
+
net_obj = net(net_name)
|
|
19
|
+
return net_obj
|
|
30
20
|
|
|
31
21
|
def label(value, anchor="left"):
|
|
32
22
|
return create component:
|
|
@@ -97,21 +87,21 @@ def cap(value):
|
|
|
97
87
|
footprint: "Capacitor_SMD:C_0402_1005Metric"
|
|
98
88
|
|
|
99
89
|
def ind(value):
|
|
100
|
-
width =
|
|
101
|
-
height =
|
|
90
|
+
width = 200
|
|
91
|
+
height = 100
|
|
102
92
|
|
|
103
93
|
return create component:
|
|
104
94
|
pins: 2
|
|
105
95
|
type: "ind"
|
|
106
96
|
display: create graphic (params):
|
|
107
|
-
arc: -
|
|
108
|
-
arc: -
|
|
109
|
-
arc:
|
|
110
|
-
arc:
|
|
111
|
-
hpin: 1, -width/2 -
|
|
112
|
-
hpin: 2, width/2 +
|
|
113
|
-
label: (params.refdes, -width/2, -height/2 -
|
|
114
|
-
label: (params.value, 0,
|
|
97
|
+
arc: -75, 0, 25, 180, 360
|
|
98
|
+
arc: -25, 0, 25, 180, 360
|
|
99
|
+
arc: 25, 0, 25, 180, 360
|
|
100
|
+
arc: 75, 0, 25, 180, 360
|
|
101
|
+
hpin: 1, -width/2 - 100, 0, 100
|
|
102
|
+
hpin: 2, width/2 + 100, 0, -100
|
|
103
|
+
label: (params.refdes, -width/2, -height/2 - 25 , fontSize=50, anchor="left")
|
|
104
|
+
label: (params.value, 0, 50, fontSize=50, anchor="middle", vanchor="middle")
|
|
115
105
|
params:
|
|
116
106
|
value: value
|
|
117
107
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circuitscript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Interpreter for the circuitscript language",
|
|
5
5
|
"homepage": "https://circuitscript.net",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=16.0"
|
|
8
8
|
},
|
|
9
9
|
"main": "./dist/cjs/index.js",
|
|
10
|
-
"module": "./dist/esm/index.
|
|
10
|
+
"module": "./dist/esm/index.js",
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"bin": {
|
|
13
13
|
"circuitscript": "./dist/cjs/main.js"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
17
|
"require": "./dist/cjs/index.js",
|
|
18
|
-
"import": "./dist/esm/index.
|
|
18
|
+
"import": "./dist/esm/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
@@ -49,30 +49,31 @@
|
|
|
49
49
|
"scripts": {
|
|
50
50
|
"start": "node build/src/main.js",
|
|
51
51
|
"clean": "rimraf coverage build tmp dist",
|
|
52
|
-
"build": "npm run build:cjs
|
|
52
|
+
"build": "npm run copy-assets ; npm run build:cjs ; npm run build:esm",
|
|
53
53
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
54
54
|
"build:release:cjs": "tsc -p tsconfig.release.cjs.json",
|
|
55
|
-
"build:esm": "tsc -p tsconfig.esm.json
|
|
56
|
-
"build:release:esm": "tsc -p tsconfig.release.esm.json
|
|
55
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
56
|
+
"build:release:esm": "tsc -p tsconfig.release.esm.json",
|
|
57
57
|
"rename:esm": "npx ts2mjs ./dist/esm && rm -rf ./dist/esm/*.js && rm -rf ./dist/esm/**/*.js",
|
|
58
58
|
"build:watch": "tsc -w -p tsconfig.esm.json",
|
|
59
59
|
"build:watch:cjs": "tsc -w -p tsconfig.cjs.json",
|
|
60
|
-
"build:release": "npm run clean && npm run build:release:cjs || npm run build:release:esm",
|
|
60
|
+
"build:release": "npm run clean && npm run copy-assets && npm run build:release:cjs || npm run build:release:esm",
|
|
61
61
|
"prebuild": "npm run lint || true",
|
|
62
62
|
"lint": "eslint . --ext .ts --ext .mts",
|
|
63
|
-
"test": "jest",
|
|
64
|
-
"test-coverage": "jest --coverage",
|
|
63
|
+
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
64
|
+
"test-coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
|
|
65
65
|
"prettier": "prettier --config .prettierrc --write .",
|
|
66
|
-
"test:watch": "jest --watch",
|
|
66
|
+
"test:watch": "node --experimental-vm-modules node_modules/.bin/jest --watch",
|
|
67
67
|
"antlr": "antlr4 -Dlanguage=TypeScript ./src/antlr/CircuitScript.g4 -no-listener -visitor",
|
|
68
68
|
"antlr4ng": "npx antlr4ng -Dlanguage=TypeScript -o src/antlr -visitor -no-listener -Xexact-output-dir src/antlr/CircuitScript.g4",
|
|
69
69
|
"profile": "node --prof build/src/main.js examples/example_garden_pump.cst",
|
|
70
70
|
"profile-flame": "node --prof-process --preprocess -j isolate*.log | flamebearer",
|
|
71
71
|
"server": "node server.js",
|
|
72
|
-
"pack-local": "npm pack; rm circuitscript-install.tgz; mv `ls | grep circuitscript
|
|
72
|
+
"pack-local": "npm run build; npm pack; rm circuitscript-install.tgz; mv `ls | grep circuitscript-` circuitscript-install.tgz; cp circuitscript-install.tgz ../circuitscript-vscode/client; cp circuitscript-install.tgz ../circuitscript-vscode/server && echo 'OK'",
|
|
73
73
|
"changelog": "auto-changelog --handlebars-setup ../changelog/helper.js -p",
|
|
74
74
|
"preversion": "npm run test",
|
|
75
|
-
"version": "npm run changelog && git add CHANGELOG.md"
|
|
75
|
+
"version": "npm run changelog && git add CHANGELOG.md",
|
|
76
|
+
"copy-assets": "mkdir -p dist/fonts && mkdir -p dist/libs && cp -r fonts dist/ && cp -r libs dist/"
|
|
76
77
|
},
|
|
77
78
|
"boilerplate_author": "Jakub Synowiec <jsynowiec@users.noreply.github.com>",
|
|
78
79
|
"license": "MIT",
|
|
@@ -88,7 +89,7 @@
|
|
|
88
89
|
"lodash": "^4.17.21",
|
|
89
90
|
"pdfkit": "^0.15.1",
|
|
90
91
|
"svg-to-pdfkit": "^0.1.8",
|
|
91
|
-
"svgdom": "^0.1.
|
|
92
|
+
"svgdom": "^0.1.22",
|
|
92
93
|
"this-file": "^2.0.3",
|
|
93
94
|
"tslib": "~2.5",
|
|
94
95
|
"ws": "^8.14.2"
|