affinirum 1.0.0
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/LICENSE +661 -0
- package/README.md +301 -0
- package/dst/Affinirum.d.ts +73 -0
- package/dst/Affinirum.js +536 -0
- package/dst/Constant.d.ts +15 -0
- package/dst/Constant.js +26 -0
- package/dst/Constants.d.ts +2 -0
- package/dst/Constants.js +22 -0
- package/dst/Functions.d.ts +2 -0
- package/dst/Functions.js +85 -0
- package/dst/Keywords.d.ts +1 -0
- package/dst/Keywords.js +17 -0
- package/dst/Node.d.ts +13 -0
- package/dst/Node.js +22 -0
- package/dst/ParserFrame.d.ts +13 -0
- package/dst/ParserFrame.js +80 -0
- package/dst/ParserState.d.ts +54 -0
- package/dst/ParserState.js +562 -0
- package/dst/StaticScope.d.ts +13 -0
- package/dst/StaticScope.js +44 -0
- package/dst/Type.d.ts +72 -0
- package/dst/Type.js +196 -0
- package/dst/Value.d.ts +3 -0
- package/dst/Value.js +1 -0
- package/dst/Variable.d.ts +13 -0
- package/dst/Variable.js +25 -0
- package/dst/atom/ArrayAtom.d.ts +11 -0
- package/dst/atom/ArrayAtom.js +38 -0
- package/dst/atom/FunctionAtom.d.ts +17 -0
- package/dst/atom/FunctionAtom.js +54 -0
- package/dst/atom/ObjectAtom.d.ts +11 -0
- package/dst/atom/ObjectAtom.js +44 -0
- package/dst/atom/PrimitiveAtom.d.ts +8 -0
- package/dst/atom/PrimitiveAtom.js +26 -0
- package/dst/cjs/Affinirum.js +540 -0
- package/dst/cjs/Constant.js +30 -0
- package/dst/cjs/Constants.js +25 -0
- package/dst/cjs/Functions.js +88 -0
- package/dst/cjs/Keywords.js +20 -0
- package/dst/cjs/Node.js +26 -0
- package/dst/cjs/ParserFrame.js +84 -0
- package/dst/cjs/ParserState.js +566 -0
- package/dst/cjs/StaticScope.js +48 -0
- package/dst/cjs/Type.js +200 -0
- package/dst/cjs/Value.js +2 -0
- package/dst/cjs/Variable.js +29 -0
- package/dst/cjs/atom/ArrayAtom.js +42 -0
- package/dst/cjs/atom/FunctionAtom.js +58 -0
- package/dst/cjs/atom/ObjectAtom.js +48 -0
- package/dst/cjs/atom/PrimitiveAtom.js +30 -0
- package/dst/cjs/constant/Array.js +93 -0
- package/dst/cjs/constant/Boolean.js +25 -0
- package/dst/cjs/constant/Buffer.js +68 -0
- package/dst/cjs/constant/Enumerable.js +34 -0
- package/dst/cjs/constant/Float.js +85 -0
- package/dst/cjs/constant/Integer.js +104 -0
- package/dst/cjs/constant/Iterable.js +24 -0
- package/dst/cjs/constant/Number.js +59 -0
- package/dst/cjs/constant/Object.js +13 -0
- package/dst/cjs/constant/String.js +197 -0
- package/dst/cjs/constant/Timestamp.js +56 -0
- package/dst/cjs/constant/Unknown.js +101 -0
- package/dst/cjs/constant/notation/AN.js +46 -0
- package/dst/cjs/constant/notation/JSON.js +14 -0
- package/dst/cjs/index.js +19 -0
- package/dst/cjs/node/ArrayNode.js +34 -0
- package/dst/cjs/node/BlockNode.js +33 -0
- package/dst/cjs/node/CallNode.js +54 -0
- package/dst/cjs/node/ConstantNode.js +33 -0
- package/dst/cjs/node/LoopNode.js +34 -0
- package/dst/cjs/node/ObjectNode.js +42 -0
- package/dst/cjs/node/SwitchNode.js +45 -0
- package/dst/cjs/node/VariableNode.js +30 -0
- package/dst/cjs/package.json +3 -0
- package/dst/constant/Array.d.ts +22 -0
- package/dst/constant/Array.js +90 -0
- package/dst/constant/Boolean.d.ts +11 -0
- package/dst/constant/Boolean.js +22 -0
- package/dst/constant/Buffer.d.ts +10 -0
- package/dst/constant/Buffer.js +61 -0
- package/dst/constant/Enumerable.d.ts +5 -0
- package/dst/constant/Enumerable.js +31 -0
- package/dst/constant/Float.d.ts +22 -0
- package/dst/constant/Float.js +80 -0
- package/dst/constant/Integer.d.ts +10 -0
- package/dst/constant/Integer.js +100 -0
- package/dst/constant/Iterable.d.ts +3 -0
- package/dst/constant/Iterable.js +21 -0
- package/dst/constant/Number.d.ts +14 -0
- package/dst/constant/Number.js +56 -0
- package/dst/constant/Object.d.ts +7 -0
- package/dst/constant/Object.js +10 -0
- package/dst/constant/String.d.ts +34 -0
- package/dst/constant/String.js +179 -0
- package/dst/constant/Timestamp.d.ts +20 -0
- package/dst/constant/Timestamp.js +50 -0
- package/dst/constant/Unknown.d.ts +10 -0
- package/dst/constant/Unknown.js +95 -0
- package/dst/constant/notation/AN.d.ts +6 -0
- package/dst/constant/notation/AN.js +42 -0
- package/dst/constant/notation/JSON.d.ts +7 -0
- package/dst/constant/notation/JSON.js +10 -0
- package/dst/index.d.ts +3 -0
- package/dst/index.js +3 -0
- package/dst/node/ArrayNode.d.ts +12 -0
- package/dst/node/ArrayNode.js +30 -0
- package/dst/node/BlockNode.d.ts +12 -0
- package/dst/node/BlockNode.js +29 -0
- package/dst/node/CallNode.d.ts +14 -0
- package/dst/node/CallNode.js +50 -0
- package/dst/node/ConstantNode.d.ts +15 -0
- package/dst/node/ConstantNode.js +29 -0
- package/dst/node/LoopNode.d.ts +13 -0
- package/dst/node/LoopNode.js +30 -0
- package/dst/node/ObjectNode.d.ts +13 -0
- package/dst/node/ObjectNode.js +38 -0
- package/dst/node/SwitchNode.d.ts +14 -0
- package/dst/node/SwitchNode.js +41 -0
- package/dst/node/VariableNode.d.ts +14 -0
- package/dst/node/VariableNode.js +26 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Keywords: string[];
|
package/dst/Keywords.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const Keywords = [
|
|
2
|
+
'true', 'false',
|
|
3
|
+
'null', 'void',
|
|
4
|
+
'boolean', 'bool',
|
|
5
|
+
'timestamp', 'time',
|
|
6
|
+
'float', 'flo',
|
|
7
|
+
'integer', 'int',
|
|
8
|
+
'buffer', 'buf',
|
|
9
|
+
'string', 'str',
|
|
10
|
+
'array', 'arr',
|
|
11
|
+
'object', 'obj',
|
|
12
|
+
'function', 'func',
|
|
13
|
+
'variable', 'var',
|
|
14
|
+
'constant', 'const',
|
|
15
|
+
'while',
|
|
16
|
+
'if', 'else',
|
|
17
|
+
];
|
package/dst/Node.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParserFrame } from './ParserFrame.js';
|
|
2
|
+
import { Value } from './Value.js';
|
|
3
|
+
import { Type } from './Type.js';
|
|
4
|
+
export declare abstract class Node extends ParserFrame {
|
|
5
|
+
constructor(frame: ParserFrame);
|
|
6
|
+
abstract type: Type;
|
|
7
|
+
abstract compile(type: Type): Node;
|
|
8
|
+
abstract evaluate(): Value;
|
|
9
|
+
get constant(): boolean;
|
|
10
|
+
protected reduceType(type: Type): Type;
|
|
11
|
+
protected throwTypeError(type: Type): never;
|
|
12
|
+
toString(ident?: number): string;
|
|
13
|
+
}
|
package/dst/Node.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ParserFrame } from './ParserFrame.js';
|
|
2
|
+
export class Node extends ParserFrame {
|
|
3
|
+
constructor(frame) {
|
|
4
|
+
super(frame.expr, frame.start, frame.end);
|
|
5
|
+
}
|
|
6
|
+
get constant() {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
reduceType(type) {
|
|
10
|
+
const compiledType = this.type.reduce(type);
|
|
11
|
+
if (compiledType) {
|
|
12
|
+
return compiledType;
|
|
13
|
+
}
|
|
14
|
+
this.throwTypeError(type);
|
|
15
|
+
}
|
|
16
|
+
throwTypeError(type) {
|
|
17
|
+
return this.throwError(`type ${this.type} mismatch with expected type ${type}`);
|
|
18
|
+
}
|
|
19
|
+
toString(ident = 0) {
|
|
20
|
+
return ' '.repeat(ident) + `[${this._start}:${this.end}] <${this.type}>`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class ParserFrame {
|
|
2
|
+
protected readonly _expr: string;
|
|
3
|
+
protected _start: number;
|
|
4
|
+
protected _end: number;
|
|
5
|
+
constructor(_expr: string, _start?: number, _end?: number);
|
|
6
|
+
get expr(): string;
|
|
7
|
+
get start(): number;
|
|
8
|
+
get end(): number;
|
|
9
|
+
starts(frame?: ParserFrame): ParserFrame;
|
|
10
|
+
ends(frame?: ParserFrame): ParserFrame;
|
|
11
|
+
throwError(message: string): never;
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export class ParserFrame {
|
|
2
|
+
_expr;
|
|
3
|
+
_start;
|
|
4
|
+
_end;
|
|
5
|
+
constructor(_expr, _start = 0, _end = 0) {
|
|
6
|
+
this._expr = _expr;
|
|
7
|
+
this._start = _start;
|
|
8
|
+
this._end = _end;
|
|
9
|
+
}
|
|
10
|
+
get expr() {
|
|
11
|
+
return this._expr;
|
|
12
|
+
}
|
|
13
|
+
get start() {
|
|
14
|
+
return this._start;
|
|
15
|
+
}
|
|
16
|
+
get end() {
|
|
17
|
+
return this._end;
|
|
18
|
+
}
|
|
19
|
+
starts(frame) {
|
|
20
|
+
if (frame) {
|
|
21
|
+
this._start = frame.start;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
return new ParserFrame(this._expr, this._start, this._end);
|
|
25
|
+
}
|
|
26
|
+
ends(frame) {
|
|
27
|
+
if (frame) {
|
|
28
|
+
this._end = frame.end;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
return new ParserFrame(this._expr, this._start, this._end);
|
|
32
|
+
}
|
|
33
|
+
throwError(message) {
|
|
34
|
+
const offset = this._start < 32 ? 0 : this._start - 32;
|
|
35
|
+
const length = this._end < this._start ? 0 : this._end - this._start - 1;
|
|
36
|
+
let expr = '';
|
|
37
|
+
for (let i = 0; i < this._expr.length; ++i) {
|
|
38
|
+
const c = this._expr[i];
|
|
39
|
+
expr += SPACE_SYMBOLS.includes(c) ? ' ' : c;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`error: ${message} at position ${this._start}:\n${expr.substring(offset, offset + 60)}\n` +
|
|
42
|
+
`${' '.repeat(expr.substring(offset, this._start).length)}^${'\''.repeat(length)}`);
|
|
43
|
+
}
|
|
44
|
+
toString() {
|
|
45
|
+
return `[${this._start}:${this._end}]`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const SPACE_SYMBOLS = [
|
|
49
|
+
// Whitespace and line-breaking characters
|
|
50
|
+
'\t', // tab
|
|
51
|
+
'\n', // newline
|
|
52
|
+
'\r', // carriage return
|
|
53
|
+
'\f', // form feed
|
|
54
|
+
'\v', // vertical tab
|
|
55
|
+
// Unicode spaces and separators
|
|
56
|
+
'\u00A0', // no-break space
|
|
57
|
+
'\u1680', // ogham space mark
|
|
58
|
+
'\u180E', // mongolian vowel separator
|
|
59
|
+
'\u2000', // en quad
|
|
60
|
+
'\u2001', // em quad
|
|
61
|
+
'\u2002', // en space
|
|
62
|
+
'\u2003', // em space
|
|
63
|
+
'\u2004', // three-per-em space
|
|
64
|
+
'\u2005', // four-per-em space
|
|
65
|
+
'\u2006', // six-per-em space
|
|
66
|
+
'\u2007', // figure space
|
|
67
|
+
'\u2008', // punctuation space
|
|
68
|
+
'\u2009', // thin space
|
|
69
|
+
'\u200A', // hair space
|
|
70
|
+
'\u2028', // line separator
|
|
71
|
+
'\u2029', // paragraph separator
|
|
72
|
+
'\u205F', // medium mathematical space
|
|
73
|
+
'\u3000', // ideographic space
|
|
74
|
+
// Zero-width & directional formatting characters
|
|
75
|
+
'\u200B', // zero-width space
|
|
76
|
+
'\u200C', // zero-width non-joiner
|
|
77
|
+
'\u200D', // zero-width joiner
|
|
78
|
+
'\u2060', // word joiner
|
|
79
|
+
'\uFEFF', // byte order mark
|
|
80
|
+
];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Constant } from './Constant.js';
|
|
2
|
+
import { Value } from './Value.js';
|
|
3
|
+
import { Type } from './Type.js';
|
|
4
|
+
import { ParserFrame } from './ParserFrame.js';
|
|
5
|
+
declare class Literal {
|
|
6
|
+
readonly value: Value;
|
|
7
|
+
constructor(value: Value);
|
|
8
|
+
}
|
|
9
|
+
declare class Assignment {
|
|
10
|
+
readonly operator?: Constant | undefined;
|
|
11
|
+
constructor(operator?: Constant | undefined);
|
|
12
|
+
}
|
|
13
|
+
export declare class ParserState extends ParserFrame {
|
|
14
|
+
protected _fragment: Literal | Assignment | Constant | Type | symbol | string | undefined;
|
|
15
|
+
constructor(expr: string);
|
|
16
|
+
get literalValue(): Value;
|
|
17
|
+
get assignmentOperator(): Constant | undefined;
|
|
18
|
+
get operator(): Constant;
|
|
19
|
+
get type(): Type;
|
|
20
|
+
get token(): string;
|
|
21
|
+
get isOperator(): boolean;
|
|
22
|
+
get isLiteral(): boolean;
|
|
23
|
+
get isAssignment(): boolean;
|
|
24
|
+
get isType(): boolean;
|
|
25
|
+
get isToken(): boolean;
|
|
26
|
+
get isParenthesesOpen(): boolean;
|
|
27
|
+
get isParenthesesClose(): boolean;
|
|
28
|
+
get isBracketsOpen(): boolean;
|
|
29
|
+
get isBracketsClose(): boolean;
|
|
30
|
+
get isBracesOpen(): boolean;
|
|
31
|
+
get isBracesClose(): boolean;
|
|
32
|
+
get isSemicolonSeparator(): boolean;
|
|
33
|
+
get isColonSeparator(): boolean;
|
|
34
|
+
get isCommaSeparator(): boolean;
|
|
35
|
+
get isTildaMark(): boolean;
|
|
36
|
+
get isOptionalType(): boolean;
|
|
37
|
+
get isVariadicFunction(): boolean;
|
|
38
|
+
get isVariableDefinition(): boolean;
|
|
39
|
+
get isConstantDefinition(): boolean;
|
|
40
|
+
get isWhile(): boolean;
|
|
41
|
+
get isIf(): boolean;
|
|
42
|
+
get isElse(): boolean;
|
|
43
|
+
get isVoid(): boolean;
|
|
44
|
+
openParentheses(): this;
|
|
45
|
+
closeParentheses(): this;
|
|
46
|
+
openBrackets(): this;
|
|
47
|
+
closeBrackets(): this;
|
|
48
|
+
openBraces(): this;
|
|
49
|
+
closeBraces(): this;
|
|
50
|
+
separateByColon(): this;
|
|
51
|
+
clone(): ParserState;
|
|
52
|
+
next(): ParserState;
|
|
53
|
+
}
|
|
54
|
+
export {};
|