Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/@types/elements.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TData, TDataName } from './data';
import { TElementName, TElementKind, TElementType } from './specification';
import { TElementKind, TElementType } from './specification';

// -------------------------------------------------------------------------------------------------

/** Interface for the class that implements a syntax element. */
export interface IElementSyntax {
/** Name of the syntax element. */
name: TElementName;
name: string;
/** Display name of the syntax element. */
label: string;
/** Kind (`Argument`, `Instruction`) of the syntax element. */
Expand Down
88 changes: 23 additions & 65 deletions src/@types/specification.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,12 @@ export type TElementKind = 'Argument' | 'Instruction';
/** Type (`Data`, `Expression`, `Statement`, `Block`) of the syntax element. */
export type TElementType = 'Data' | 'Expression' | 'Statement' | 'Block';

/** Names of factory list of data elements. */
export type TElementNameData =
// value elements
| 'value-boolean'
| 'value-number'
| 'value-string'
// box identifier elements
| 'boxidentifier-generic'
| 'boxidentifier-boolean'
| 'boxidentifier-number'
| 'boxidentifier-string';

/** Names of factory list of expression elements. */
export type TElementNameExpression =
// math operator elements
| 'operator-math-plus'
| 'operator-math-minus'
| 'operator-math-times'
| 'operator-math-divide'
| 'operator-math-modulus';

/** Names of factory list of statement elements. */
export type TElementNameStatement =
// box elements
| 'box-generic'
| 'box-boolean'
| 'box-number'
| 'box-string'
// print element
| 'print';

/** Names of factory list of block elements. */
export type TElementNameBlock = 'process' | 'routine' | 'repeat' | 'if';

/** Names of factory list of syntax elements. */
export type TElementName =
| 'dummy'
| TElementNameData
| TElementNameExpression
| TElementNameStatement
| TElementNameBlock;

/** Type for the specification object for data elements. */
export interface IElementSpecificationData {
label: string;
type: 'Data';
category: string;
prototype: (name: TElementNameData, label: string) => IElementData<TData>;
prototype: (name: string, label: string) => IElementData<TData>;
}

/** Type for the specification entry object for data elements. */
Expand All @@ -77,7 +35,7 @@ export interface IElementSpecificationExpression {
label: string;
type: 'Expression';
category: string;
prototype: (name: TElementNameExpression, label: string) => IElementExpression<TData>;
prototype: (name: string, label: string) => IElementExpression<TData>;
}

/** Type for the specification object for expression elements. */
Expand All @@ -90,21 +48,21 @@ export interface IElementSpecificationEntryExpression extends IElementSpecificat

/** Type for the specification object for instruction elements. */
interface IElementSpecificationInstruction {
allowAbove?: TElementName[] | boolean;
allowBelow?: TElementName[] | boolean;
forbidAbove?: TElementName[];
forbidBelow?: TElementName[];
allowAbove?: string[] | boolean;
allowBelow?: string[] | boolean;
forbidAbove?: string[];
forbidBelow?: string[];
allowedNestLevel?: number[] | 'any';
allowedNestInside?: TElementNameBlock[] | boolean;
forbiddenNestInside?: TElementNameBlock[];
allowedNestInside?: string[] | boolean;
forbiddenNestInside?: string[];
}

/** Type for the specification object for statement elements. */
export type IElementSpecificationStatement = IElementSpecificationInstruction & {
label: string;
type: 'Statement';
category: string;
prototype: (name: TElementNameStatement, label: string) => IElementStatement;
prototype: (name: string, label: string) => IElementStatement;
};

/** Type for the specification object for statement elements. */
Expand All @@ -120,9 +78,9 @@ export type IElementSpecificationBlock = IElementSpecificationInstruction & {
label: string;
type: 'Block';
category: string;
prototype: (name: TElementNameBlock, label: string) => IElementBlock;
allowNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
forbidNestInside?: (TElementNameStatement | TElementNameBlock)[];
prototype: (name: string, label: string) => IElementBlock;
allowNestInside?: string[] | boolean;
forbidNestInside?: string[];
};

/** Type for the specification entry object for block elements. */
Expand All @@ -131,22 +89,22 @@ export type IElementSpecificationEntryBlock = IElementSpecificationInstruction &
type: 'Block';
category: string;
prototype: typeof IElementBlock;
allowNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
forbidNestInside?: (TElementNameStatement | TElementNameBlock)[];
allowNestInside?: string[] | boolean;
forbidNestInside?: string[];
};

export interface IElementSpecification {
label: string;
type: TElementType;
category: string;
prototype: new (name: TElementName, label: string) => IElementSyntax;
allowAbove?: TElementName[] | boolean;
allowBelow?: TElementName[] | boolean;
forbidAbove?: TElementName[];
forbidBelow?: TElementName[];
prototype: new (name: string, label: string) => IElementSyntax;
allowAbove?: string[] | boolean;
allowBelow?: string[] | boolean;
forbidAbove?: string[];
forbidBelow?: string[];
allowedNestLevel?: number[] | 'any';
allowedNestInside?: TElementNameBlock[] | boolean;
forbiddenNestInside?: TElementNameBlock[];
allowNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
forbidNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
allowedNestInside?: string[] | boolean;
forbiddenNestInside?: string[];
allowNestInside?: string[] | boolean;
forbidNestInside?: string[] | boolean;
}
18 changes: 5 additions & 13 deletions src/@types/syntaxTree.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import {
TElementNameData,
TElementNameExpression,
TElementNameStatement,
TElementNameBlock,
TElementName,
} from './specification';

// -- snapshots ------------------------------------------------------------------------------------

/** Type definition for the snapshot input of a data element. */
Expand Down Expand Up @@ -105,7 +97,7 @@ export interface ITreeSnapshot {
/** Type definition for the class that implements a generic syntax tree node. */
interface ITreeNode {
/** Name of the syntax element. */
elementName: TElementName;
elementName: string;
/** Node ID of the syntax tree node instance. */
nodeID: string;
/** Warehouse ID of the syntax element instance. */
Expand All @@ -121,15 +113,15 @@ export interface ITreeNodeArgument extends ITreeNode {
/** Type definition for the class that implements a syntax tree data node. */
export interface ITreeNodeData extends ITreeNodeArgument {
/** Name of the data element. */
elementName: TElementNameData;
elementName: string;
/** Returns a snapshot of the syntax tree data node. */
snapshot: ITreeSnapshotData;
}

/** Type definition for the class that implements a syntax tree expression node. */
export interface ITreeNodeExpression extends ITreeNodeArgument {
/** Name of the expression element. */
elementName: TElementNameExpression;
elementName: string;
/** Returns a snapshot of the syntax tree expression node. */
snapshot: ITreeSnapshotExpression;
/** Object with key-value pairs of argument names and corresponding argument nodes. */
Expand Down Expand Up @@ -175,15 +167,15 @@ export interface ITreeNodeInstruction extends ITreeNode {
/** Type definition for the class that implements a syntax tree statement node. */
export interface ITreeNodeStatement extends ITreeNodeInstruction {
/** Name of the statement element. */
elementName: TElementNameStatement;
elementName: string;
/** Returns a snapshot of the syntax tree statement node. */
snapshot: ITreeSnapshotStatement;
}

/** Type definition for the class that implements a syntax tree block node. */
export interface ITreeNodeBlock extends ITreeNodeInstruction {
/** Name of the block element. */
elementName: TElementNameBlock;
elementName: string;
/** Returns a snapshot of the syntax tree block node. */
snapshot: ITreeSnapshotBlock;
/** Syntax tree node reference of the first nested instruction element. */
Expand Down
5 changes: 2 additions & 3 deletions src/execution/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { getInstance } from '../syntax/warehouse/warehouse';
import { TData } from '../@types/data';
import { ElementData, ElementExpression } from '../syntax/elements/elementArgument';
import { ElementBlock, ElementStatement } from '../syntax/elements/elementInstruction';
import { TElementName } from '../@types/specification';

// -- private variables ----------------------------------------------------------------------------

Expand Down Expand Up @@ -528,10 +527,10 @@ export function getNextElement(): IParsedElement | null {
*/
export function stackTrace():
| {
elementName: TElementName | null;
elementName: string | null;
nodeID: string | null;
pages:
| { elementName: TElementName | null; nodeID: string | null; marker: string | null }[]
| { elementName: string | null; nodeID: string | null; marker: string | null }[]
| null;
}[]
| null {
Expand Down
11 changes: 5 additions & 6 deletions src/library/elements/elementBox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TData, TDataName } from '../../@types/data';
import { TElementName } from '../../@types/specification';

import { ElementStatement } from '../../syntax/elements/elementInstruction';
import { declareVariable } from '../../execution/interpreter';
Expand All @@ -15,7 +14,7 @@ import { declareVariable } from '../../execution/interpreter';
* Box elements add (declare) variables to the symbol table.
*/
abstract class ElementBox extends ElementStatement {
constructor(name: TElementName, label: string, types: TDataName[]) {
constructor(name: string, label: string, types: TDataName[]) {
super(name, label, {
name: ['string'],
value: types,
Expand Down Expand Up @@ -45,7 +44,7 @@ abstract class ElementBox extends ElementStatement {
* Defines a box element that declares a variable of any data type.
*/
export class ElementBoxGeneric extends ElementBox {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['boolean', 'number', 'string']);
}

Expand All @@ -60,7 +59,7 @@ export class ElementBoxGeneric extends ElementBox {
* Defines a box element that declares a variable of boolean type.
*/
export class ElementBoxBoolean extends ElementBox {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['boolean']);
}

Expand All @@ -75,7 +74,7 @@ export class ElementBoxBoolean extends ElementBox {
* Defines a box element that declares a variable of number type.
*/
export class ElementBoxNumber extends ElementBox {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['number']);
}

Expand All @@ -90,7 +89,7 @@ export class ElementBoxNumber extends ElementBox {
* Defines a box element that declares a variable of string type.
*/
export class ElementBoxString extends ElementBox {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['string']);
}

Expand Down
19 changes: 9 additions & 10 deletions src/library/elements/elementBoxIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TData, TDataName } from '../../@types/data';
import { TElementName } from '../../@types/specification';

import { ElementData } from '../../syntax/elements/elementArgument';
import { queryVariable } from '../../execution/interpreter';
Expand All @@ -15,16 +14,16 @@ import { queryVariable } from '../../execution/interpreter';
* @throws `Error` (ItemNotFoundError)
*/
abstract class ElementBoxIdentifier<T> extends ElementData<T> {
constructor(name: TElementName, label: string, returnType: ['boolean'], initialValue: boolean);
constructor(name: TElementName, label: string, returnType: ['number'], initialValue: number);
constructor(name: TElementName, label: string, returnType: ['string'], initialValue: string);
constructor(name: string, label: string, returnType: ['boolean'], initialValue: boolean);
constructor(name: string, label: string, returnType: ['number'], initialValue: number);
constructor(name: string, label: string, returnType: ['string'], initialValue: string);
constructor(
name: TElementName,
name: string,
label: string,
returnType: ['boolean', 'number', 'string'],
initialValue: TData
);
constructor(name: TElementName, label: string, returnType: TDataName[], initialValue: T) {
constructor(name: string, label: string, returnType: TDataName[], initialValue: T) {
super(name, label, {}, returnType, initialValue);
}

Expand Down Expand Up @@ -59,7 +58,7 @@ abstract class ElementBoxIdentifier<T> extends ElementData<T> {
* @throws `Error` (ItemNotFoundError)
*/
export class ElementBoxIdentifierGeneric extends ElementBoxIdentifier<TData> {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['boolean', 'number', 'string'], '');
}
}
Expand All @@ -70,7 +69,7 @@ export class ElementBoxIdentifierGeneric extends ElementBoxIdentifier<TData> {
* @throws `Error` (ItemNotFoundError)
*/
export class ElementBoxIdentifierBoolean extends ElementBoxIdentifier<boolean> {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['boolean'], true);
}
}
Expand All @@ -81,7 +80,7 @@ export class ElementBoxIdentifierBoolean extends ElementBoxIdentifier<boolean> {
* @throws `Error` (ItemNotFoundError)
*/
export class ElementBoxIdentifierNumber extends ElementBoxIdentifier<number> {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['number'], 0);
}
}
Expand All @@ -92,7 +91,7 @@ export class ElementBoxIdentifierNumber extends ElementBoxIdentifier<number> {
* @throws `Error` (ItemNotFoundError)
*/
export class ElementBoxIdentifierString extends ElementBoxIdentifier<string> {
constructor(name: TElementName, label: string) {
constructor(name: string, label: string) {
super(name, label, ['string'], '');
}
}
3 changes: 1 addition & 2 deletions src/library/elements/elementConditional.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TElementNameBlock } from '../../@types/specification';
import { ElementBlock } from '../../syntax/elements/elementInstruction';

import { overrideProgramCounter } from '../../execution/interpreter';
Expand All @@ -12,7 +11,7 @@ import { overrideProgramCounter } from '../../execution/interpreter';
* Allows entry to scope only if condition is satisfied.
*/
export class ElementIf extends ElementBlock {
constructor(name: TElementNameBlock, label: string) {
constructor(name: string, label: string) {
super(name, label, { condition: ['boolean'] });
}

Expand Down
3 changes: 1 addition & 2 deletions src/library/elements/elementLoop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TElementNameBlock } from '../../@types/specification';
import { ElementBlock } from '../../syntax/elements/elementInstruction';

import { overrideProgramCounter } from '../../execution/interpreter';
Expand All @@ -12,7 +11,7 @@ import { overrideProgramCounter } from '../../execution/interpreter';
* Repeats the scope as many times as the parameter provided.
*/
export class ElementRepeat extends ElementBlock {
constructor(name: TElementNameBlock, label: string) {
constructor(name: string, label: string) {
super(name, label, { times: ['number'] });
}

Expand Down
Loading