@hoox-sh/pynets 0.1.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 (48) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +661 -0
  3. package/NOTICE +46 -0
  4. package/README.md +327 -0
  5. package/dist/browser.js +44 -0
  6. package/dist/index.d.ts +348 -0
  7. package/dist/index.js +41741 -0
  8. package/package.json +77 -0
  9. package/src/ast/builder.ts +1002 -0
  10. package/src/ast/dump.ts +43 -0
  11. package/src/ast/helper.ts +77 -0
  12. package/src/ast/nodes.ts +570 -0
  13. package/src/ast/unparse.ts +360 -0
  14. package/src/cli/rich.ts +378 -0
  15. package/src/cli.ts +627 -0
  16. package/src/generated/PinescriptLexer.interp +267 -0
  17. package/src/generated/PinescriptLexer.tokens +131 -0
  18. package/src/generated/PinescriptLexer.ts +673 -0
  19. package/src/generated/PinescriptLexerBase.ts +395 -0
  20. package/src/generated/PinescriptParser.interp +267 -0
  21. package/src/generated/PinescriptParser.tokens +131 -0
  22. package/src/generated/PinescriptParser.ts +8863 -0
  23. package/src/generated/PinescriptParserBase.ts +21 -0
  24. package/src/generated/PinescriptParserVisitor.ts +840 -0
  25. package/src/index.ts +55 -0
  26. package/src/parser/LexerBase.ts +395 -0
  27. package/src/parser/ParserBase.ts +21 -0
  28. package/src/parser/error.ts +33 -0
  29. package/src/runtime/array.ts +486 -0
  30. package/src/runtime/color.ts +164 -0
  31. package/src/runtime/drawings.ts +510 -0
  32. package/src/runtime/input.ts +102 -0
  33. package/src/runtime/interpret.ts +3897 -0
  34. package/src/runtime/library.ts +282 -0
  35. package/src/runtime/log.ts +69 -0
  36. package/src/runtime/map.ts +85 -0
  37. package/src/runtime/math.ts +231 -0
  38. package/src/runtime/matrix.ts +1154 -0
  39. package/src/runtime/provider.ts +232 -0
  40. package/src/runtime/request.ts +372 -0
  41. package/src/runtime/series.ts +44 -0
  42. package/src/runtime/str.ts +433 -0
  43. package/src/runtime/strategy.ts +1105 -0
  44. package/src/runtime/ta.ts +2093 -0
  45. package/src/runtime/ticker.ts +81 -0
  46. package/src/runtime/time.ts +439 -0
  47. package/src/runtime/timeframe.ts +85 -0
  48. package/src/runtime/udt.ts +119 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright (C) 2024-2026 jango_blockchained
3
+ * SPDX-License-Identifier: AGPL-3.0-or-later
4
+ *
5
+ * Tiny Pine UDT / enum values. `null` is `na`. Unknown field get → na; unknown
6
+ * set is a no-op. Python `UserDefinedType` / `ObjectInstance` / `visit_EnumDef`
7
+ * remain the source of truth — interpret registers TypeDef / EnumDef later.
8
+ */
9
+
10
+ export type UdtField = { name: string; default: unknown };
11
+
12
+ /** Stored method; `body` is opaque (interpret owns FunctionDef). */
13
+ export type UdtMethod = {
14
+ name: string;
15
+ params: Array<{ name: string; default?: unknown }>;
16
+ body?: unknown;
17
+ exported?: boolean;
18
+ };
19
+
20
+ export class UdtType {
21
+ readonly fields: UdtField[];
22
+ readonly methods = new Map<string, UdtMethod>();
23
+ isExported = false;
24
+
25
+ constructor(
26
+ readonly name: string,
27
+ fields: UdtField[],
28
+ ) {
29
+ this.fields = fields.map((f) => ({ name: f.name, default: f.default ?? null }));
30
+ }
31
+
32
+ addMethod(name: string, method: UdtMethod): void {
33
+ this.methods.set(name, method);
34
+ }
35
+
36
+ getMethod(name: string): UdtMethod | undefined {
37
+ return this.methods.get(name);
38
+ }
39
+
40
+ /** Shallow copy of fields + methods for library `export type`. */
41
+ cloneType(): UdtType {
42
+ const copy = new UdtType(
43
+ this.name,
44
+ this.fields.map((f) => ({ name: f.name, default: f.default })),
45
+ );
46
+ copy.isExported = this.isExported;
47
+ for (const [name, method] of this.methods) copy.addMethod(name, method);
48
+ return copy;
49
+ }
50
+
51
+ /** Pine `Type.new(...)` — defaults fill first; missing default is `na`. */
52
+ newInstance(overrides?: Record<string, unknown>): UdtInstance {
53
+ const inst = new UdtInstance(this);
54
+ if (overrides) {
55
+ for (const field of this.fields) {
56
+ if (Object.hasOwn(overrides, field.name)) inst.set(field.name, overrides[field.name]);
57
+ }
58
+ }
59
+ return inst;
60
+ }
61
+ }
62
+
63
+ export class UdtInstance {
64
+ readonly type: UdtType;
65
+ readonly typeName: string;
66
+ private readonly values = new Map<string, unknown>();
67
+
68
+ constructor(type: UdtType) {
69
+ this.type = type;
70
+ this.typeName = type.name;
71
+ for (const field of type.fields) this.values.set(field.name, field.default ?? null);
72
+ }
73
+
74
+ get(field: string): unknown {
75
+ return this.values.has(field) ? this.values.get(field) : null;
76
+ }
77
+
78
+ set(field: string, value: unknown): void {
79
+ if (!this.values.has(field)) return;
80
+ this.values.set(field, value);
81
+ }
82
+
83
+ getMethod(name: string): UdtMethod | undefined {
84
+ return this.type.getMethod(name);
85
+ }
86
+ }
87
+
88
+ export class EnumMember {
89
+ constructor(
90
+ readonly enumName: string,
91
+ readonly name: string,
92
+ readonly value?: unknown,
93
+ ) {}
94
+
95
+ equals(other: unknown): boolean {
96
+ return other instanceof EnumMember && other.enumName === this.enumName && other.name === this.name;
97
+ }
98
+
99
+ toString(): string {
100
+ return this.name;
101
+ }
102
+ }
103
+
104
+ export class EnumType {
105
+ constructor(
106
+ readonly name: string,
107
+ readonly members: Map<string, EnumMember>,
108
+ ) {}
109
+ }
110
+
111
+ export function udtTypeFromAssigns(name: string, fields: UdtField[]): UdtType {
112
+ return new UdtType(name, fields);
113
+ }
114
+
115
+ export function enumTypeFromNames(name: string, members: string[]): EnumType {
116
+ const map = new Map<string, EnumMember>();
117
+ for (const member of members) map.set(member, new EnumMember(name, member));
118
+ return new EnumType(name, map);
119
+ }