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.
Files changed (121) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +301 -0
  3. package/dst/Affinirum.d.ts +73 -0
  4. package/dst/Affinirum.js +536 -0
  5. package/dst/Constant.d.ts +15 -0
  6. package/dst/Constant.js +26 -0
  7. package/dst/Constants.d.ts +2 -0
  8. package/dst/Constants.js +22 -0
  9. package/dst/Functions.d.ts +2 -0
  10. package/dst/Functions.js +85 -0
  11. package/dst/Keywords.d.ts +1 -0
  12. package/dst/Keywords.js +17 -0
  13. package/dst/Node.d.ts +13 -0
  14. package/dst/Node.js +22 -0
  15. package/dst/ParserFrame.d.ts +13 -0
  16. package/dst/ParserFrame.js +80 -0
  17. package/dst/ParserState.d.ts +54 -0
  18. package/dst/ParserState.js +562 -0
  19. package/dst/StaticScope.d.ts +13 -0
  20. package/dst/StaticScope.js +44 -0
  21. package/dst/Type.d.ts +72 -0
  22. package/dst/Type.js +196 -0
  23. package/dst/Value.d.ts +3 -0
  24. package/dst/Value.js +1 -0
  25. package/dst/Variable.d.ts +13 -0
  26. package/dst/Variable.js +25 -0
  27. package/dst/atom/ArrayAtom.d.ts +11 -0
  28. package/dst/atom/ArrayAtom.js +38 -0
  29. package/dst/atom/FunctionAtom.d.ts +17 -0
  30. package/dst/atom/FunctionAtom.js +54 -0
  31. package/dst/atom/ObjectAtom.d.ts +11 -0
  32. package/dst/atom/ObjectAtom.js +44 -0
  33. package/dst/atom/PrimitiveAtom.d.ts +8 -0
  34. package/dst/atom/PrimitiveAtom.js +26 -0
  35. package/dst/cjs/Affinirum.js +540 -0
  36. package/dst/cjs/Constant.js +30 -0
  37. package/dst/cjs/Constants.js +25 -0
  38. package/dst/cjs/Functions.js +88 -0
  39. package/dst/cjs/Keywords.js +20 -0
  40. package/dst/cjs/Node.js +26 -0
  41. package/dst/cjs/ParserFrame.js +84 -0
  42. package/dst/cjs/ParserState.js +566 -0
  43. package/dst/cjs/StaticScope.js +48 -0
  44. package/dst/cjs/Type.js +200 -0
  45. package/dst/cjs/Value.js +2 -0
  46. package/dst/cjs/Variable.js +29 -0
  47. package/dst/cjs/atom/ArrayAtom.js +42 -0
  48. package/dst/cjs/atom/FunctionAtom.js +58 -0
  49. package/dst/cjs/atom/ObjectAtom.js +48 -0
  50. package/dst/cjs/atom/PrimitiveAtom.js +30 -0
  51. package/dst/cjs/constant/Array.js +93 -0
  52. package/dst/cjs/constant/Boolean.js +25 -0
  53. package/dst/cjs/constant/Buffer.js +68 -0
  54. package/dst/cjs/constant/Enumerable.js +34 -0
  55. package/dst/cjs/constant/Float.js +85 -0
  56. package/dst/cjs/constant/Integer.js +104 -0
  57. package/dst/cjs/constant/Iterable.js +24 -0
  58. package/dst/cjs/constant/Number.js +59 -0
  59. package/dst/cjs/constant/Object.js +13 -0
  60. package/dst/cjs/constant/String.js +197 -0
  61. package/dst/cjs/constant/Timestamp.js +56 -0
  62. package/dst/cjs/constant/Unknown.js +101 -0
  63. package/dst/cjs/constant/notation/AN.js +46 -0
  64. package/dst/cjs/constant/notation/JSON.js +14 -0
  65. package/dst/cjs/index.js +19 -0
  66. package/dst/cjs/node/ArrayNode.js +34 -0
  67. package/dst/cjs/node/BlockNode.js +33 -0
  68. package/dst/cjs/node/CallNode.js +54 -0
  69. package/dst/cjs/node/ConstantNode.js +33 -0
  70. package/dst/cjs/node/LoopNode.js +34 -0
  71. package/dst/cjs/node/ObjectNode.js +42 -0
  72. package/dst/cjs/node/SwitchNode.js +45 -0
  73. package/dst/cjs/node/VariableNode.js +30 -0
  74. package/dst/cjs/package.json +3 -0
  75. package/dst/constant/Array.d.ts +22 -0
  76. package/dst/constant/Array.js +90 -0
  77. package/dst/constant/Boolean.d.ts +11 -0
  78. package/dst/constant/Boolean.js +22 -0
  79. package/dst/constant/Buffer.d.ts +10 -0
  80. package/dst/constant/Buffer.js +61 -0
  81. package/dst/constant/Enumerable.d.ts +5 -0
  82. package/dst/constant/Enumerable.js +31 -0
  83. package/dst/constant/Float.d.ts +22 -0
  84. package/dst/constant/Float.js +80 -0
  85. package/dst/constant/Integer.d.ts +10 -0
  86. package/dst/constant/Integer.js +100 -0
  87. package/dst/constant/Iterable.d.ts +3 -0
  88. package/dst/constant/Iterable.js +21 -0
  89. package/dst/constant/Number.d.ts +14 -0
  90. package/dst/constant/Number.js +56 -0
  91. package/dst/constant/Object.d.ts +7 -0
  92. package/dst/constant/Object.js +10 -0
  93. package/dst/constant/String.d.ts +34 -0
  94. package/dst/constant/String.js +179 -0
  95. package/dst/constant/Timestamp.d.ts +20 -0
  96. package/dst/constant/Timestamp.js +50 -0
  97. package/dst/constant/Unknown.d.ts +10 -0
  98. package/dst/constant/Unknown.js +95 -0
  99. package/dst/constant/notation/AN.d.ts +6 -0
  100. package/dst/constant/notation/AN.js +42 -0
  101. package/dst/constant/notation/JSON.d.ts +7 -0
  102. package/dst/constant/notation/JSON.js +10 -0
  103. package/dst/index.d.ts +3 -0
  104. package/dst/index.js +3 -0
  105. package/dst/node/ArrayNode.d.ts +12 -0
  106. package/dst/node/ArrayNode.js +30 -0
  107. package/dst/node/BlockNode.d.ts +12 -0
  108. package/dst/node/BlockNode.js +29 -0
  109. package/dst/node/CallNode.d.ts +14 -0
  110. package/dst/node/CallNode.js +50 -0
  111. package/dst/node/ConstantNode.d.ts +15 -0
  112. package/dst/node/ConstantNode.js +29 -0
  113. package/dst/node/LoopNode.d.ts +13 -0
  114. package/dst/node/LoopNode.js +30 -0
  115. package/dst/node/ObjectNode.d.ts +13 -0
  116. package/dst/node/ObjectNode.js +38 -0
  117. package/dst/node/SwitchNode.d.ts +14 -0
  118. package/dst/node/SwitchNode.js +41 -0
  119. package/dst/node/VariableNode.d.ts +14 -0
  120. package/dst/node/VariableNode.js +26 -0
  121. package/package.json +67 -0
@@ -0,0 +1 @@
1
+ export declare const Keywords: string[];
@@ -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 {};