circuitscript 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +127 -73
- package/dist/cjs/SemanticTokenVisitor.js +19 -13
- package/dist/cjs/antlr/CircuitScriptParser.js +711 -671
- package/dist/cjs/builtinMethods.js +29 -25
- package/dist/cjs/environment.js +118 -0
- package/dist/cjs/execute.js +53 -12
- package/dist/cjs/geometry.js +1 -0
- package/dist/cjs/globals.js +11 -6
- package/dist/cjs/helpers.js +135 -127
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/layout.js +37 -12
- package/dist/cjs/main.js +31 -19
- package/dist/cjs/objects/ExecutionScope.js +33 -0
- package/dist/cjs/objects/ParamDefinition.js +15 -15
- package/dist/cjs/parser.js +27 -21
- package/dist/cjs/regenerate-tests.js +9 -6
- package/dist/cjs/render.js +3 -1
- package/dist/cjs/sizing.js +5 -58
- package/dist/cjs/utils.js +85 -30
- package/dist/cjs/validate/SymbolTable.js +96 -0
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +14 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +170 -0
- package/dist/cjs/validate.js +52 -44
- package/dist/cjs/visitor.js +140 -24
- package/dist/esm/{BaseVisitor.mjs → BaseVisitor.js} +98 -45
- package/dist/esm/{SemanticTokenVisitor.mjs → SemanticTokenVisitor.js} +17 -11
- package/dist/esm/antlr/{CircuitScriptParser.mjs → CircuitScriptParser.js} +711 -671
- package/dist/esm/{builtinMethods.mjs → builtinMethods.js} +20 -16
- package/dist/esm/{draw_symbols.mjs → draw_symbols.js} +7 -7
- package/dist/esm/environment.js +110 -0
- package/dist/esm/{execute.mjs → execute.js} +66 -25
- package/dist/esm/{export.mjs → export.js} +2 -2
- package/dist/esm/{geometry.mjs → geometry.js} +6 -5
- package/dist/esm/{globals.mjs → globals.js} +6 -1
- package/dist/esm/helpers.js +377 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/{layout.mjs → layout.js} +42 -20
- package/dist/esm/{lexer.mjs → lexer.js} +2 -2
- package/dist/esm/{main.mjs → main.js} +33 -21
- package/dist/esm/objects/{ClassComponent.mjs → ClassComponent.js} +5 -4
- package/dist/esm/objects/{ExecutionScope.mjs → ExecutionScope.js} +33 -0
- package/dist/esm/objects/{Frame.mjs → Frame.js} +1 -1
- package/dist/esm/objects/{ParamDefinition.mjs → ParamDefinition.js} +1 -1
- package/dist/esm/objects/{PinDefinition.mjs → PinDefinition.js} +1 -1
- package/dist/esm/parser.js +71 -0
- package/dist/esm/{regenerate-tests.mjs → regenerate-tests.js} +10 -7
- package/dist/esm/{render.mjs → render.js} +11 -9
- package/dist/esm/{sizing.mjs → sizing.js} +6 -34
- package/dist/esm/{utils.mjs → utils.js} +61 -17
- package/dist/esm/validate/SymbolTable.js +90 -0
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +10 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +163 -0
- package/dist/esm/validate.js +86 -0
- package/dist/esm/{visitor.mjs → visitor.js} +151 -35
- package/dist/fonts/Arial.ttf +0 -0
- package/dist/fonts/Inter-Bold.ttf +0 -0
- package/dist/fonts/Inter-Regular.ttf +0 -0
- package/dist/fonts/OpenSans-Regular.ttf +0 -0
- package/dist/fonts/Roboto-Regular.ttf +0 -0
- package/dist/libs/lib.cst +423 -0
- package/dist/types/BaseVisitor.d.ts +34 -21
- package/dist/types/SemanticTokenVisitor.d.ts +6 -5
- package/dist/types/antlr/CircuitScriptParser.d.ts +4 -2
- package/dist/types/builtinMethods.d.ts +3 -2
- package/dist/types/environment.d.ts +31 -0
- package/dist/types/globals.d.ts +4 -1
- package/dist/types/helpers.d.ts +12 -14
- package/dist/types/index.d.ts +5 -0
- package/dist/types/objects/ClassComponent.d.ts +1 -0
- package/dist/types/objects/ExecutionScope.d.ts +11 -0
- package/dist/types/objects/types.d.ts +6 -1
- package/dist/types/parser.d.ts +7 -11
- package/dist/types/sizing.d.ts +0 -3
- package/dist/types/utils.d.ts +30 -6
- package/dist/types/validate/SymbolTable.d.ts +40 -0
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +7 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +32 -0
- package/dist/types/validate.d.ts +1 -1
- package/package.json +14 -13
- package/dist/cjs/SymbolValidatorVisitor.js +0 -233
- package/dist/esm/SymbolValidatorVisitor.mjs +0 -222
- package/dist/esm/helpers.mjs +0 -364
- package/dist/esm/index.mjs +0 -15
- package/dist/esm/parser.mjs +0 -64
- package/dist/esm/validate.mjs +0 -74
- package/dist/types/SymbolValidatorVisitor.d.ts +0 -61
- package/dist/types/layout.d.ts +0 -148
- /package/dist/esm/antlr/{CircuitScriptLexer.mjs → CircuitScriptLexer.js} +0 -0
- /package/dist/esm/antlr/{CircuitScriptVisitor.mjs → CircuitScriptVisitor.js} +0 -0
- /package/dist/esm/{fonts.mjs → fonts.js} +0 -0
- /package/dist/esm/{logger.mjs → logger.js} +0 -0
- /package/dist/esm/objects/{Net.mjs → Net.js} +0 -0
- /package/dist/esm/objects/{PinTypes.mjs → PinTypes.js} +0 -0
- /package/dist/esm/objects/{Wire.mjs → Wire.js} +0 -0
- /package/dist/esm/objects/{types.mjs → types.js} +0 -0
- /package/dist/esm/{server.mjs → server.js} +0 -0
package/dist/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';
|
|
@@ -17,6 +17,7 @@ export declare class ClassComponent {
|
|
|
17
17
|
_cachedParams: string;
|
|
18
18
|
_copyID?: number;
|
|
19
19
|
_copyFrom?: ClassComponent;
|
|
20
|
+
_pointLinkComponent?: ClassComponent;
|
|
20
21
|
arrangeProps: Map<string, NumericValue[]> | null;
|
|
21
22
|
displayProp: SymbolDrawingCommands | null;
|
|
22
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[];
|
|
@@ -44,6 +48,12 @@ export declare class ExecutionScope {
|
|
|
44
48
|
setActive(type: ActiveObject, item: any): void;
|
|
45
49
|
clearActive(): void;
|
|
46
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;
|
|
47
57
|
}
|
|
48
58
|
export declare enum SequenceAction {
|
|
49
59
|
To = "to",
|
|
@@ -71,3 +81,4 @@ export type SequenceActionAtTo = [
|
|
|
71
81
|
export type SequenceActionWire = [SequenceAction.Wire, wireId: number, WireSegment[]];
|
|
72
82
|
export type SequenceActionAssign = [SequenceAction.Assign, variable: string, ClassComponent];
|
|
73
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,9 +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";
|
|
5
|
-
import { SequenceAction, SequenceItem } from './objects/ExecutionScope';
|
|
6
|
-
import { BlockTypes } from './globals';
|
|
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';
|
|
7
7
|
export declare class SimpleStopwatch {
|
|
8
8
|
startTime: Date;
|
|
9
9
|
constructor();
|
|
@@ -31,7 +31,9 @@ export declare function getBoundsSize(bounds: BoundBox): {
|
|
|
31
31
|
};
|
|
32
32
|
export declare function getPortType(component: ClassComponent): string | null;
|
|
33
33
|
export declare function roundValue(value: NumericValue): NumericValue;
|
|
34
|
-
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;
|
|
35
37
|
export declare function combineMaps(map1: Map<string, any>, map2: Map<string, any>): Map<string, any>;
|
|
36
38
|
export declare function getNumberExponential(value: string): number;
|
|
37
39
|
export declare function getNumberExponentialText(value: number): string;
|
|
@@ -41,3 +43,25 @@ export declare function areasOverlap(area1: BoundBox2, area2: BoundBox2): boolea
|
|
|
41
43
|
export declare function sequenceActionString(sequenceAction: SequenceAction): string;
|
|
42
44
|
export declare function generateDebugSequenceAction(sequence: SequenceItem[]): string[];
|
|
43
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/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"
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SymbolTable = exports.SymbolValidatorResolveVisitor = exports.SymbolValidatorVisitor = void 0;
|
|
4
|
-
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
5
|
-
const types_js_1 = require("./objects/types.js");
|
|
6
|
-
class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.symbolTable = new SymbolTable();
|
|
10
|
-
this.visitImport_expr = (ctx) => {
|
|
11
|
-
const ID = ctx.ID().toString();
|
|
12
|
-
const { pathExists } = this.handleImportFile(ID, false, ctx);
|
|
13
|
-
if (!pathExists) {
|
|
14
|
-
this.symbolTable.addUndefined(this.getExecutor(), ID, ctx.ID());
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
this.visitAssignment_expr = (ctx) => {
|
|
18
|
-
const atomStr = ctx.atom_expr().getText();
|
|
19
|
-
const ctxDataExpr = ctx.data_expr();
|
|
20
|
-
this.visit(ctxDataExpr);
|
|
21
|
-
const value = this.getResult(ctxDataExpr);
|
|
22
|
-
this.addSymbolVariable(atomStr, value);
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
|
-
this.visitAtom_expr = (ctx) => {
|
|
26
|
-
const tmpSymbol = this.handleAtomSymbol(ctx.ID(0));
|
|
27
|
-
this.setResult(ctx, tmpSymbol);
|
|
28
|
-
};
|
|
29
|
-
this.visitFunction_call_expr = (ctx) => {
|
|
30
|
-
this.handleAtomSymbol(ctx.ID());
|
|
31
|
-
if (ctx.trailer_expr().length > 0) {
|
|
32
|
-
ctx.trailer_expr().forEach(item => {
|
|
33
|
-
if (item.OPEN_PAREN() && item.CLOSE_PAREN()) {
|
|
34
|
-
const params = item.parameters();
|
|
35
|
-
if (params) {
|
|
36
|
-
this.visit(params);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
this.visitValueAtomExpr = (ctx) => {
|
|
43
|
-
let value = null;
|
|
44
|
-
const ctxValueExpr = ctx.value_expr();
|
|
45
|
-
const cxtAtomExpr = ctx.atom_expr();
|
|
46
|
-
if (ctxValueExpr) {
|
|
47
|
-
this.visit(ctxValueExpr);
|
|
48
|
-
value = this.getResult(ctxValueExpr);
|
|
49
|
-
}
|
|
50
|
-
else if (cxtAtomExpr) {
|
|
51
|
-
this.visit(cxtAtomExpr);
|
|
52
|
-
value = this.getResult(cxtAtomExpr);
|
|
53
|
-
}
|
|
54
|
-
this.setResult(ctx, value);
|
|
55
|
-
};
|
|
56
|
-
this.visitUnaryOperatorExpr = (ctx) => {
|
|
57
|
-
this.visit(ctx.data_expr());
|
|
58
|
-
};
|
|
59
|
-
this.visitMultiplyExpr = (ctx) => {
|
|
60
|
-
this.visit(ctx.data_expr(0));
|
|
61
|
-
this.visit(ctx.data_expr(1));
|
|
62
|
-
};
|
|
63
|
-
this.visitAdditionExpr = (ctx) => {
|
|
64
|
-
this.visit(ctx.data_expr(0));
|
|
65
|
-
this.visit(ctx.data_expr(1));
|
|
66
|
-
};
|
|
67
|
-
this.visitBinaryOperatorExpr = (ctx) => {
|
|
68
|
-
this.visit(ctx.data_expr(0));
|
|
69
|
-
this.visit(ctx.data_expr(1));
|
|
70
|
-
};
|
|
71
|
-
this.visitDataExpr = (ctx) => {
|
|
72
|
-
return;
|
|
73
|
-
};
|
|
74
|
-
this.visitFunction_def_expr = (ctx) => {
|
|
75
|
-
const functionName = ctx.ID().getText();
|
|
76
|
-
let funcDefinedParameters = [];
|
|
77
|
-
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
78
|
-
if (ctxFunctionArgsExpr) {
|
|
79
|
-
this.visit(ctxFunctionArgsExpr);
|
|
80
|
-
funcDefinedParameters = this.getResult(ctxFunctionArgsExpr);
|
|
81
|
-
}
|
|
82
|
-
this.addSymbolFunction(functionName, funcDefinedParameters);
|
|
83
|
-
const executionContextName = functionName + '_validate';
|
|
84
|
-
const passedInParamsNull = funcDefinedParameters.map((param, index) => {
|
|
85
|
-
return ['position', index, null];
|
|
86
|
-
});
|
|
87
|
-
const newExecutor = this.enterNewChildContext(this.executionStack, this.getExecutor(), executionContextName, { netNamespace: "" }, funcDefinedParameters, passedInParamsNull);
|
|
88
|
-
funcDefinedParameters.forEach(param => {
|
|
89
|
-
this.addSymbolVariable(param[0], null, newExecutor);
|
|
90
|
-
});
|
|
91
|
-
this.runExpressions(newExecutor, ctx.function_expr());
|
|
92
|
-
this.executionStack.pop();
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
addSymbolVariable(name, value, executor = null) {
|
|
96
|
-
const useExecutor = executor === null ? this.getExecutor() : executor;
|
|
97
|
-
this.symbolTable.addVariable(useExecutor, name, value);
|
|
98
|
-
this.log2('add symbol variable: ' + name);
|
|
99
|
-
}
|
|
100
|
-
addSymbolFunction(functionName, funcDefinedParameters) {
|
|
101
|
-
if (!this.symbolTable.exists(this.getExecutor(), functionName)) {
|
|
102
|
-
this.symbolTable.addFunction(this.getExecutor(), functionName, funcDefinedParameters);
|
|
103
|
-
this.log2('add symbol function: ' + functionName);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
handleAtomSymbol(atom) {
|
|
107
|
-
const atomId = atom.getText();
|
|
108
|
-
const executor = this.getExecutor();
|
|
109
|
-
let tmpSymbol;
|
|
110
|
-
if (this.symbolTable.exists(executor, atomId)) {
|
|
111
|
-
tmpSymbol = this.symbolTable.get(executor, atomId);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
const foundContext = this.symbolTable.searchParentContext(executor, atomId);
|
|
115
|
-
if (foundContext === null) {
|
|
116
|
-
tmpSymbol = this.symbolTable.addUndefined(executor, atomId, atom);
|
|
117
|
-
this.log2('symbol not found: ' + atomId);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
tmpSymbol = this.symbolTable.get(foundContext, atomId);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return tmpSymbol;
|
|
124
|
-
}
|
|
125
|
-
setSymbols(symbolTable) {
|
|
126
|
-
this.symbolTable = symbolTable;
|
|
127
|
-
}
|
|
128
|
-
getSymbols() {
|
|
129
|
-
return this.symbolTable;
|
|
130
|
-
}
|
|
131
|
-
dumpSymbols() {
|
|
132
|
-
this.symbolTable.dumpSymbols();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.SymbolValidatorVisitor = SymbolValidatorVisitor;
|
|
136
|
-
class SymbolValidatorResolveVisitor extends SymbolValidatorVisitor {
|
|
137
|
-
addSymbolVariable(name, value) {
|
|
138
|
-
}
|
|
139
|
-
addSymbolFunction(functionName, funcDefinedParameters) {
|
|
140
|
-
if (this.symbolTable.exists(this.getExecutor(), functionName)) {
|
|
141
|
-
this.symbolTable.addFunction(this.getExecutor(), functionName, funcDefinedParameters);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.SymbolValidatorResolveVisitor = SymbolValidatorResolveVisitor;
|
|
146
|
-
class SymbolTable {
|
|
147
|
-
constructor() {
|
|
148
|
-
this.symbols = new Map();
|
|
149
|
-
this.executonContextsNamespaces = [];
|
|
150
|
-
}
|
|
151
|
-
getSymbols() {
|
|
152
|
-
return this.symbols;
|
|
153
|
-
}
|
|
154
|
-
addFunction(executionContext, id, funcDefinedParameters) {
|
|
155
|
-
return this.add(executionContext, id, types_js_1.ParseSymbolType.Function, {
|
|
156
|
-
funcDefinedParameters
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
addVariable(executionContext, id, variableValue) {
|
|
160
|
-
return this.add(executionContext, id, types_js_1.ParseSymbolType.Variable, {
|
|
161
|
-
variableValue
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
addUndefined(executionContext, id, node) {
|
|
165
|
-
return this.add(executionContext, id, types_js_1.ParseSymbolType.Undefined, {
|
|
166
|
-
node
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
add(executionContext, id, type, extra) {
|
|
170
|
-
if (this.executonContextsNamespaces.indexOf(executionContext.namespace) === -1) {
|
|
171
|
-
this.executonContextsNamespaces.push(executionContext.namespace);
|
|
172
|
-
}
|
|
173
|
-
const item = {
|
|
174
|
-
id,
|
|
175
|
-
type,
|
|
176
|
-
context: executionContext,
|
|
177
|
-
extra
|
|
178
|
-
};
|
|
179
|
-
this.symbols.set(this.idName(executionContext, id), item);
|
|
180
|
-
return item;
|
|
181
|
-
}
|
|
182
|
-
idName(executionContext, id) {
|
|
183
|
-
return executionContext.namespace + id;
|
|
184
|
-
}
|
|
185
|
-
dumpSymbols() {
|
|
186
|
-
for (const [key, value] of this.symbols) {
|
|
187
|
-
console.log(value.type.padEnd(10, " "), key);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exists(executionContext, id) {
|
|
191
|
-
const name = this.idName(executionContext, id);
|
|
192
|
-
return this.symbols.has(name);
|
|
193
|
-
}
|
|
194
|
-
existsAny(executionContext, id) {
|
|
195
|
-
if (this.exists(executionContext, id)) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
return this.searchParentContext(executionContext, id) !== null;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
get(executionContext, id) {
|
|
203
|
-
const name = this.idName(executionContext, id);
|
|
204
|
-
return this.symbols.get(name);
|
|
205
|
-
}
|
|
206
|
-
getParentContexts(executionContext, contextsNamespace) {
|
|
207
|
-
if (executionContext.parentContext !== null) {
|
|
208
|
-
contextsNamespace.push(executionContext.parentContext.namespace);
|
|
209
|
-
this.getParentContexts(executionContext.parentContext, contextsNamespace);
|
|
210
|
-
}
|
|
211
|
-
return contextsNamespace;
|
|
212
|
-
}
|
|
213
|
-
searchParentContext(executionContext, id) {
|
|
214
|
-
const contextNames = this.getParentContexts(executionContext, []);
|
|
215
|
-
for (const [key,] of this.symbols) {
|
|
216
|
-
if (key.endsWith(`.${id}`)) {
|
|
217
|
-
const { context } = this.symbols.get(key);
|
|
218
|
-
if (contextNames.indexOf(context.namespace) !== -1) {
|
|
219
|
-
return context;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
clearUndefined() {
|
|
226
|
-
for (const [key, value] of this.symbols) {
|
|
227
|
-
if (value.type === types_js_1.ParseSymbolType.Undefined) {
|
|
228
|
-
this.symbols.delete(key);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
exports.SymbolTable = SymbolTable;
|