@simahfud/pine-to-kline 0.1.3 → 0.1.4
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/README.md +7 -0
- package/dist/index.d.ts +43 -1
- package/dist/pine-to-kline.js +196 -116
- package/dist/pine-to-kline.js.map +1 -1
- package/dist/pine-to-kline.umd.js +29 -29
- package/dist/pine-to-kline.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/pine-to-kline.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var p = (i, t, e) =>
|
|
1
|
+
var F = Object.defineProperty;
|
|
2
|
+
var B = (i, t, e) => t in i ? F(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var p = (i, t, e) => B(i, typeof t != "symbol" ? t + "" : t, e);
|
|
4
4
|
/**
|
|
5
5
|
* pine-to-kline — Token
|
|
6
6
|
* @license Apache-2.0
|
|
@@ -66,12 +66,12 @@ class w extends Error {
|
|
|
66
66
|
return `${this.name}: ${this.message}${t}${e}`;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class R extends w {
|
|
70
70
|
constructor(t, e, s) {
|
|
71
71
|
super(t, e, s), this.name = "LexerError";
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
class
|
|
74
|
+
class g extends w {
|
|
75
75
|
constructor(t, e, s) {
|
|
76
76
|
super(t, e, s), this.name = "ParseError";
|
|
77
77
|
}
|
|
@@ -92,7 +92,7 @@ class jt extends w {
|
|
|
92
92
|
* Handles indentation-significant syntax (INDENT/DEDENT).
|
|
93
93
|
* @license Apache-2.0
|
|
94
94
|
*/
|
|
95
|
-
class
|
|
95
|
+
class P {
|
|
96
96
|
constructor(t) {
|
|
97
97
|
p(this, "source");
|
|
98
98
|
p(this, "tokens", []);
|
|
@@ -140,7 +140,7 @@ class O {
|
|
|
140
140
|
continue;
|
|
141
141
|
}
|
|
142
142
|
if (!this.readOperator())
|
|
143
|
-
throw new
|
|
143
|
+
throw new R(`Unexpected character: '${t}'`, this.line, this.column);
|
|
144
144
|
}
|
|
145
145
|
for (; this.indentStack.length > 1; )
|
|
146
146
|
this.indentStack.pop(), this.tokens.push(new N(a.DEDENT, "", this.line, this.column));
|
|
@@ -219,10 +219,10 @@ class O {
|
|
|
219
219
|
}
|
|
220
220
|
if (n === `
|
|
221
221
|
`)
|
|
222
|
-
throw new
|
|
222
|
+
throw new R("Unterminated string literal", s, e);
|
|
223
223
|
r += n, this.advance();
|
|
224
224
|
}
|
|
225
|
-
throw new
|
|
225
|
+
throw new R("Unterminated string literal", s, e);
|
|
226
226
|
}
|
|
227
227
|
// ─── Color Literals ─────────────────────────────────────────
|
|
228
228
|
readColor() {
|
|
@@ -231,7 +231,7 @@ class O {
|
|
|
231
231
|
for (this.advance(); this.pos < this.source.length && this.isHexDigit(this.current()); )
|
|
232
232
|
e += this.current(), this.advance();
|
|
233
233
|
if (e.length !== 7 && e.length !== 9)
|
|
234
|
-
throw new
|
|
234
|
+
throw new R(`Invalid color literal: ${e}`, this.line, t);
|
|
235
235
|
this.tokens.push(new N(a.COLOR_LITERAL, e, this.line, t));
|
|
236
236
|
}
|
|
237
237
|
// ─── Identifiers & Keywords ─────────────────────────────────
|
|
@@ -362,8 +362,8 @@ class O {
|
|
|
362
362
|
* Recursive descent parser: Token[] → AST (ProgramNode)
|
|
363
363
|
* @license Apache-2.0
|
|
364
364
|
*/
|
|
365
|
-
const
|
|
366
|
-
class
|
|
365
|
+
const U = /* @__PURE__ */ new Set(["plot", "plotshape", "plotarrow", "plotbar", "plotcandle", "plotchar", "bgcolor", "fill"]), V = /* @__PURE__ */ new Set(["int", "float", "bool", "string", "color", "label", "line", "box", "table", "series", "simple"]);
|
|
366
|
+
class O {
|
|
367
367
|
constructor(t) {
|
|
368
368
|
p(this, "tokens");
|
|
369
369
|
p(this, "pos", 0);
|
|
@@ -394,6 +394,10 @@ class _ {
|
|
|
394
394
|
if (this.check(a.CONTINUE))
|
|
395
395
|
return this.advance(), { type: "Continue", line: this.previous().line };
|
|
396
396
|
if (this.check(a.RETURN)) return this.parseReturn();
|
|
397
|
+
if (this.check(a.IMPORT)) return this.parseImport();
|
|
398
|
+
if (this.check(a.EXPORT)) return this.parseExport();
|
|
399
|
+
if (this.check(a.TYPE)) return this.parseTypeDef();
|
|
400
|
+
if (this.check(a.METHOD)) return this.parseMethodDef();
|
|
397
401
|
if (this.check(a.IDENTIFIER))
|
|
398
402
|
return this.parseIdentifierStatement();
|
|
399
403
|
if (this.check(a.LBRACKET))
|
|
@@ -402,19 +406,19 @@ class _ {
|
|
|
402
406
|
return { type: "ExpressionStatement", expression: t, line: t.line };
|
|
403
407
|
}
|
|
404
408
|
parseIdentifierStatement() {
|
|
405
|
-
var s, r, n, l, h
|
|
409
|
+
var s, r, n, l, h;
|
|
406
410
|
const t = this.peek();
|
|
407
411
|
if ((t.value === "indicator" || t.value === "strategy" || t.value === "library") && ((s = this.peekAt(1)) == null ? void 0 : s.type) === a.LPAREN)
|
|
408
412
|
return this.parseIndicator();
|
|
409
|
-
if (
|
|
413
|
+
if (U.has(t.value) && ((r = this.peekAt(1)) == null ? void 0 : r.type) === a.LPAREN)
|
|
410
414
|
return this.parsePlotCall();
|
|
411
415
|
if (t.value === "hline" && ((n = this.peekAt(1)) == null ? void 0 : n.type) === a.LPAREN)
|
|
412
416
|
return this.parseHlineCall();
|
|
413
417
|
if (((l = this.peekAt(1)) == null ? void 0 : l.type) === a.LPAREN && this.isFunctionDef())
|
|
414
418
|
return this.parseFunctionDef();
|
|
415
|
-
if (
|
|
419
|
+
if (this.isTypeAnnotation())
|
|
416
420
|
return this.parseTypedDecl();
|
|
417
|
-
if ((
|
|
421
|
+
if ((h = this.peekAt(1)) != null && h.isAny(a.ASSIGN, a.REASSIGN, a.PLUS_ASSIGN, a.MINUS_ASSIGN, a.STAR_ASSIGN, a.SLASH_ASSIGN, a.PERCENT_ASSIGN))
|
|
418
422
|
return this.parseAssignment();
|
|
419
423
|
const e = this.parseExpression();
|
|
420
424
|
return { type: "ExpressionStatement", expression: e, line: e.line };
|
|
@@ -436,14 +440,14 @@ class _ {
|
|
|
436
440
|
const t = this.check(a.VAR), e = this.check(a.VARIP);
|
|
437
441
|
this.advance();
|
|
438
442
|
let s = null;
|
|
439
|
-
this.
|
|
443
|
+
this.isTypeAnnotation() && (s = this.parseTypeAnnotationString());
|
|
440
444
|
const r = this.expect(a.IDENTIFIER).value;
|
|
441
445
|
this.expect(a.ASSIGN);
|
|
442
446
|
const n = this.parseExpression();
|
|
443
447
|
return { type: "VarDecl", persistent: t, persistentTick: e, name: r, typeAnnotation: s, value: n, line: n.line };
|
|
444
448
|
}
|
|
445
449
|
parseTypedDecl() {
|
|
446
|
-
const t = this.
|
|
450
|
+
const t = this.parseTypeAnnotationString(), e = this.expect(a.IDENTIFIER).value;
|
|
447
451
|
this.expect(a.ASSIGN);
|
|
448
452
|
const s = this.parseExpression();
|
|
449
453
|
return { type: "VarDecl", persistent: !1, persistentTick: !1, name: e, typeAnnotation: t, value: s, line: s.line };
|
|
@@ -531,7 +535,53 @@ class _ {
|
|
|
531
535
|
let e = null;
|
|
532
536
|
return !this.check(a.NEWLINE) && !this.check(a.DEDENT) && !this.isAtEnd() && (e = this.parseExpression()), { type: "Return", value: e, line: t };
|
|
533
537
|
}
|
|
534
|
-
// ───
|
|
538
|
+
// ─── Import / Export ───────────────────────────────────────
|
|
539
|
+
parseImport() {
|
|
540
|
+
const t = this.advance().line, e = [];
|
|
541
|
+
for (e.push(this.expect(a.IDENTIFIER).value); this.match(a.SLASH); )
|
|
542
|
+
(this.check(a.IDENTIFIER) || this.check(a.NUMBER)) && e.push(this.advance().value);
|
|
543
|
+
const s = e.join("/");
|
|
544
|
+
let r = null;
|
|
545
|
+
return this.check(a.IDENTIFIER) && this.peek().value === "as" && (this.advance(), r = this.expect(a.IDENTIFIER).value), { type: "Import", path: s, alias: r, line: t };
|
|
546
|
+
}
|
|
547
|
+
parseExport() {
|
|
548
|
+
const t = this.advance().line, e = this.parseStatement();
|
|
549
|
+
if (!e) throw new g("Expected declaration after export", t, 0);
|
|
550
|
+
return { type: "Export", declaration: e, line: t };
|
|
551
|
+
}
|
|
552
|
+
// ─── Type / Method / Function Definition ───────────────────
|
|
553
|
+
parseTypeDef() {
|
|
554
|
+
const t = this.advance().line, e = this.expect(a.IDENTIFIER).value;
|
|
555
|
+
this.skipNewlines();
|
|
556
|
+
const s = [];
|
|
557
|
+
if (this.match(a.INDENT)) {
|
|
558
|
+
for (; !this.check(a.DEDENT) && !this.isAtEnd() && (this.skipNewlines(), !this.check(a.DEDENT)); ) {
|
|
559
|
+
let r = null;
|
|
560
|
+
this.isTypeAnnotation() ? r = this.parseTypeAnnotationString() : r = this.advance().value;
|
|
561
|
+
const n = this.expect(a.IDENTIFIER).value;
|
|
562
|
+
let l = null;
|
|
563
|
+
this.match(a.ASSIGN) && (l = this.parseExpression()), s.push({ name: n, typeAnnotation: r, defaultValue: l }), this.skipNewlines();
|
|
564
|
+
}
|
|
565
|
+
this.check(a.DEDENT) && this.advance();
|
|
566
|
+
}
|
|
567
|
+
return { type: "TypeDef", name: e, fields: s, line: t };
|
|
568
|
+
}
|
|
569
|
+
parseMethodDef() {
|
|
570
|
+
const t = this.advance().line, e = this.expect(a.IDENTIFIER).value;
|
|
571
|
+
this.expect(a.LPAREN);
|
|
572
|
+
const s = [];
|
|
573
|
+
if (!this.check(a.RPAREN))
|
|
574
|
+
do {
|
|
575
|
+
let n = null;
|
|
576
|
+
this.isTypeAnnotation() ? n = this.parseTypeAnnotationString() : V.has(this.peek().value) && (n = this.advance().value);
|
|
577
|
+
const l = this.expect(a.IDENTIFIER).value;
|
|
578
|
+
let h = null;
|
|
579
|
+
this.match(a.ASSIGN) && (h = this.parseExpression()), s.push({ name: l, typeAnnotation: n, defaultValue: h });
|
|
580
|
+
} while (this.match(a.COMMA));
|
|
581
|
+
this.expect(a.RPAREN), this.expect(a.ARROW), this.skipNewlines();
|
|
582
|
+
const r = this.parseBlock();
|
|
583
|
+
return { type: "MethodDef", name: e, params: s, body: r, line: t };
|
|
584
|
+
}
|
|
535
585
|
isFunctionDef() {
|
|
536
586
|
var s;
|
|
537
587
|
let t = 0, e = this.pos + 1;
|
|
@@ -643,25 +693,35 @@ class _ {
|
|
|
643
693
|
return this.parsePostfix();
|
|
644
694
|
}
|
|
645
695
|
parsePostfix() {
|
|
696
|
+
var e, s, r, n, l, h;
|
|
646
697
|
let t = this.parsePrimary();
|
|
647
698
|
for (; ; )
|
|
648
699
|
if (this.match(a.LBRACKET)) {
|
|
649
|
-
const
|
|
650
|
-
this.expect(a.RBRACKET), t = { type: "SeriesAccess", series: t, offset:
|
|
700
|
+
const c = this.parseExpression();
|
|
701
|
+
this.expect(a.RBRACKET), t = { type: "SeriesAccess", series: t, offset: c, line: t.line };
|
|
651
702
|
} else if (this.match(a.DOT)) {
|
|
652
|
-
const
|
|
703
|
+
const c = this.expect(a.IDENTIFIER).value;
|
|
704
|
+
let o = !1;
|
|
705
|
+
if ((this.check(a.LPAREN) || this.check(a.LT) && ((e = this.peekAt(1)) == null ? void 0 : e.type) === a.IDENTIFIER && ((s = this.peekAt(2)) == null ? void 0 : s.type) === a.GT && ((r = this.peekAt(3)) == null ? void 0 : r.type) === a.LPAREN) && (o = !0), o) {
|
|
706
|
+
const u = this.buildCalleeName(t) + "." + c;
|
|
707
|
+
this.check(a.LT) && (this.advance(), this.advance(), this.advance()), this.advance();
|
|
708
|
+
const { positional: f, named: E } = this.parseCallArgs();
|
|
709
|
+
this.expect(a.RPAREN), t = { type: "FunctionCall", callee: u, args: f, kwargs: E, line: t.line };
|
|
710
|
+
} else
|
|
711
|
+
t = { type: "MemberExpr", object: t, property: c, line: t.line };
|
|
712
|
+
} else if ((this.check(a.LPAREN) || this.check(a.LT)) && t.type === "Identifier") {
|
|
713
|
+
const c = t.name;
|
|
714
|
+
if (this.check(a.LT))
|
|
715
|
+
if (((n = this.peekAt(1)) == null ? void 0 : n.type) === a.IDENTIFIER && ((l = this.peekAt(2)) == null ? void 0 : l.type) === a.GT && ((h = this.peekAt(3)) == null ? void 0 : h.type) === a.LPAREN)
|
|
716
|
+
this.advance(), this.advance(), this.advance();
|
|
717
|
+
else
|
|
718
|
+
break;
|
|
653
719
|
if (this.check(a.LPAREN)) {
|
|
654
|
-
const s = this.buildCalleeName(t) + "." + e;
|
|
655
720
|
this.advance();
|
|
656
|
-
const { positional:
|
|
657
|
-
this.expect(a.RPAREN), t = { type: "FunctionCall", callee:
|
|
721
|
+
const { positional: o, named: u } = this.parseCallArgs();
|
|
722
|
+
this.expect(a.RPAREN), t = { type: "FunctionCall", callee: c, args: o, kwargs: u, line: t.line };
|
|
658
723
|
} else
|
|
659
|
-
|
|
660
|
-
} else if (this.check(a.LPAREN) && t.type === "Identifier") {
|
|
661
|
-
const e = t.name;
|
|
662
|
-
this.advance();
|
|
663
|
-
const { positional: s, named: r } = this.parseCallArgs();
|
|
664
|
-
this.expect(a.RPAREN), t = { type: "FunctionCall", callee: e, args: s, kwargs: r, line: t.line };
|
|
724
|
+
break;
|
|
665
725
|
} else break;
|
|
666
726
|
return t;
|
|
667
727
|
}
|
|
@@ -679,6 +739,14 @@ class _ {
|
|
|
679
739
|
return this.advance(), { type: "NaLiteral", line: t.line };
|
|
680
740
|
if (this.check(a.COLOR_LITERAL))
|
|
681
741
|
return this.advance(), { type: "ColorLiteral", value: t.value, line: t.line };
|
|
742
|
+
if (this.match(a.LBRACKET)) {
|
|
743
|
+
const e = [];
|
|
744
|
+
if (!this.check(a.RBRACKET))
|
|
745
|
+
do
|
|
746
|
+
e.push(this.parseExpression());
|
|
747
|
+
while (this.match(a.COMMA));
|
|
748
|
+
return this.expect(a.RBRACKET), { type: "ArrayLiteral", elements: e, line: t.line };
|
|
749
|
+
}
|
|
682
750
|
if (this.match(a.LPAREN)) {
|
|
683
751
|
const e = this.parseExpression();
|
|
684
752
|
return this.expect(a.RPAREN), e;
|
|
@@ -689,7 +757,11 @@ class _ {
|
|
|
689
757
|
const e = this.parseIf();
|
|
690
758
|
return { type: "Identifier", name: "__if_expr__", line: e.line, _ifNode: e };
|
|
691
759
|
}
|
|
692
|
-
|
|
760
|
+
if (this.check(a.SWITCH)) {
|
|
761
|
+
const e = this.parseSwitch();
|
|
762
|
+
return { type: "Identifier", name: "__switch_expr__", line: e.line, _switchNode: e };
|
|
763
|
+
}
|
|
764
|
+
throw new g(`Unexpected token: ${t.type} (${t.value})`, t.line, t.column);
|
|
693
765
|
}
|
|
694
766
|
// ─── Call Arguments ────────────────────────────────────────
|
|
695
767
|
parseCallArgs() {
|
|
@@ -730,6 +802,14 @@ class _ {
|
|
|
730
802
|
return [{ type: "ExpressionStatement", expression: t, line: t.line }];
|
|
731
803
|
}
|
|
732
804
|
// ─── Helpers ───────────────────────────────────────────────
|
|
805
|
+
isTypeAnnotation() {
|
|
806
|
+
var t, e, s, r;
|
|
807
|
+
return this.check(a.IDENTIFIER) ? ((t = this.peekAt(1)) == null ? void 0 : t.type) === a.IDENTIFIER || ((e = this.peekAt(1)) == null ? void 0 : e.type) === a.LBRACKET && ((s = this.peekAt(2)) == null ? void 0 : s.type) === a.RBRACKET && ((r = this.peekAt(3)) == null ? void 0 : r.type) === a.IDENTIFIER : !1;
|
|
808
|
+
}
|
|
809
|
+
parseTypeAnnotationString() {
|
|
810
|
+
let t = this.advance().value;
|
|
811
|
+
return this.match(a.LBRACKET) && (this.expect(a.RBRACKET), t += "[]"), t;
|
|
812
|
+
}
|
|
733
813
|
buildCalleeName(t) {
|
|
734
814
|
return t.type === "Identifier" ? t.name : t.type === "MemberExpr" ? this.buildCalleeName(t.object) + "." + t.property : "__unknown__";
|
|
735
815
|
}
|
|
@@ -760,7 +840,7 @@ class _ {
|
|
|
760
840
|
expect(t) {
|
|
761
841
|
if (this.check(t)) return this.advance();
|
|
762
842
|
const e = this.peek();
|
|
763
|
-
throw new
|
|
843
|
+
throw new g(`Expected ${t} but got ${e == null ? void 0 : e.type} (${e == null ? void 0 : e.value})`, e == null ? void 0 : e.line, e == null ? void 0 : e.column);
|
|
764
844
|
}
|
|
765
845
|
skipNewlines() {
|
|
766
846
|
for (; this.check(a.NEWLINE); ) this.advance();
|
|
@@ -843,7 +923,7 @@ class W {
|
|
|
843
923
|
* Implements: sma, ema, rma, wma, hma, vwma, swma, dema, tema
|
|
844
924
|
* @license Apache-2.0
|
|
845
925
|
*/
|
|
846
|
-
function
|
|
926
|
+
function C(i, t) {
|
|
847
927
|
return i.map((e, s) => {
|
|
848
928
|
if (s < t - 1) return NaN;
|
|
849
929
|
let r = 0;
|
|
@@ -940,7 +1020,7 @@ function z(i, t, e, s) {
|
|
|
940
1020
|
});
|
|
941
1021
|
}
|
|
942
1022
|
function X(i, t) {
|
|
943
|
-
const e =
|
|
1023
|
+
const e = C(i, t);
|
|
944
1024
|
return i.map((s, r) => {
|
|
945
1025
|
if (r < t - 1) return NaN;
|
|
946
1026
|
let n = 0;
|
|
@@ -964,7 +1044,7 @@ function J(i, t) {
|
|
|
964
1044
|
* Implements: atr, bb, kc, donchian
|
|
965
1045
|
* @license Apache-2.0
|
|
966
1046
|
*/
|
|
967
|
-
function
|
|
1047
|
+
function D(i, t, e, s) {
|
|
968
1048
|
const r = i.map((n, l) => l === 0 ? n - t[l] : Math.max(
|
|
969
1049
|
n - t[l],
|
|
970
1050
|
Math.abs(n - e[l - 1]),
|
|
@@ -973,7 +1053,7 @@ function F(i, t, e, s) {
|
|
|
973
1053
|
return x(r, s);
|
|
974
1054
|
}
|
|
975
1055
|
function tt(i, t, e = 2) {
|
|
976
|
-
const s =
|
|
1056
|
+
const s = C(i, t);
|
|
977
1057
|
return i.map((r, n) => {
|
|
978
1058
|
if (n < t - 1) return { upper: NaN, basis: NaN, lower: NaN };
|
|
979
1059
|
let l = 0;
|
|
@@ -988,7 +1068,7 @@ function tt(i, t, e = 2) {
|
|
|
988
1068
|
});
|
|
989
1069
|
}
|
|
990
1070
|
function et(i, t, e, s, r, n = 1.5) {
|
|
991
|
-
const l = m(i, r), h =
|
|
1071
|
+
const l = m(i, r), h = D(t, e, s, r);
|
|
992
1072
|
return i.map((c, o) => ({
|
|
993
1073
|
upper: l[o] + n * h[o],
|
|
994
1074
|
basis: l[o],
|
|
@@ -1093,13 +1173,13 @@ function Nt(i) {
|
|
|
1093
1173
|
let t = NaN;
|
|
1094
1174
|
return i.map((e) => (e ? t = 0 : isNaN(t) || t++, t));
|
|
1095
1175
|
}
|
|
1096
|
-
function
|
|
1176
|
+
function Et(i, t, e = 0) {
|
|
1097
1177
|
const s = [], r = [];
|
|
1098
1178
|
for (let n = 0; n < t.length; n++)
|
|
1099
1179
|
i[n] && r.unshift(t[n]), s.push(r[e] ?? NaN);
|
|
1100
1180
|
return s;
|
|
1101
1181
|
}
|
|
1102
|
-
function
|
|
1182
|
+
function mt(i, t, e) {
|
|
1103
1183
|
return i.map((s, r) => {
|
|
1104
1184
|
if (r < t || r + e >= i.length) return NaN;
|
|
1105
1185
|
for (let n = r - t; n < r; n++)
|
|
@@ -1109,7 +1189,7 @@ function Et(i, t, e) {
|
|
|
1109
1189
|
return s;
|
|
1110
1190
|
});
|
|
1111
1191
|
}
|
|
1112
|
-
function
|
|
1192
|
+
function At(i, t, e) {
|
|
1113
1193
|
return i.map((s, r) => {
|
|
1114
1194
|
if (r < t || r + e >= i.length) return NaN;
|
|
1115
1195
|
for (let n = r - t; n < r; n++)
|
|
@@ -1119,11 +1199,11 @@ function vt(i, t, e) {
|
|
|
1119
1199
|
return s;
|
|
1120
1200
|
});
|
|
1121
1201
|
}
|
|
1122
|
-
function
|
|
1202
|
+
function vt(i) {
|
|
1123
1203
|
let t = 0;
|
|
1124
1204
|
return i.map((e) => (t += e, t));
|
|
1125
1205
|
}
|
|
1126
|
-
function
|
|
1206
|
+
function dt(i, t) {
|
|
1127
1207
|
return i.map((e, s) => {
|
|
1128
1208
|
if (s < t - 1) return NaN;
|
|
1129
1209
|
let r = 0;
|
|
@@ -1147,9 +1227,9 @@ function It(i, t) {
|
|
|
1147
1227
|
* pine-to-kline — TA Namespace Barrel Export
|
|
1148
1228
|
* @license Apache-2.0
|
|
1149
1229
|
*/
|
|
1150
|
-
const
|
|
1230
|
+
const Rt = {
|
|
1151
1231
|
// Moving averages
|
|
1152
|
-
"ta.sma":
|
|
1232
|
+
"ta.sma": C,
|
|
1153
1233
|
"ta.ema": m,
|
|
1154
1234
|
"ta.rma": x,
|
|
1155
1235
|
"ta.wma": y,
|
|
@@ -1166,7 +1246,7 @@ const St = {
|
|
|
1166
1246
|
"ta.mom": Z,
|
|
1167
1247
|
"ta.roc": J,
|
|
1168
1248
|
// Volatility
|
|
1169
|
-
"ta.atr":
|
|
1249
|
+
"ta.atr": D,
|
|
1170
1250
|
"ta.bb": tt,
|
|
1171
1251
|
"ta.kc": et,
|
|
1172
1252
|
"ta.donchian": st,
|
|
@@ -1184,11 +1264,11 @@ const St = {
|
|
|
1184
1264
|
"ta.highestbars": pt,
|
|
1185
1265
|
"ta.lowestbars": ft,
|
|
1186
1266
|
"ta.barssince": Nt,
|
|
1187
|
-
"ta.valuewhen":
|
|
1188
|
-
"ta.pivothigh":
|
|
1189
|
-
"ta.pivotlow":
|
|
1190
|
-
"ta.cum":
|
|
1191
|
-
"ta.stdev":
|
|
1267
|
+
"ta.valuewhen": Et,
|
|
1268
|
+
"ta.pivothigh": mt,
|
|
1269
|
+
"ta.pivotlow": At,
|
|
1270
|
+
"ta.cum": vt,
|
|
1271
|
+
"ta.stdev": dt,
|
|
1192
1272
|
"ta.percentrank": It
|
|
1193
1273
|
};
|
|
1194
1274
|
/**
|
|
@@ -1196,7 +1276,7 @@ const St = {
|
|
|
1196
1276
|
* Wraps JavaScript Math.* to match Pine's math.* namespace
|
|
1197
1277
|
* @license Apache-2.0
|
|
1198
1278
|
*/
|
|
1199
|
-
const
|
|
1279
|
+
const St = {
|
|
1200
1280
|
"math.abs": (i) => Math.abs(i),
|
|
1201
1281
|
"math.ceil": (i) => Math.ceil(i),
|
|
1202
1282
|
"math.floor": (i) => Math.floor(i),
|
|
@@ -1247,7 +1327,7 @@ const Rt = {
|
|
|
1247
1327
|
* All Pine color.* constants → hex values
|
|
1248
1328
|
* @license Apache-2.0
|
|
1249
1329
|
*/
|
|
1250
|
-
const
|
|
1330
|
+
const v = {
|
|
1251
1331
|
"color.aqua": "#00BCD4",
|
|
1252
1332
|
"color.black": "#000000",
|
|
1253
1333
|
"color.blue": "#2196F3",
|
|
@@ -1301,14 +1381,14 @@ const gt = {
|
|
|
1301
1381
|
* These extract metadata for KlineChart calcParams.
|
|
1302
1382
|
* @license Apache-2.0
|
|
1303
1383
|
*/
|
|
1304
|
-
let
|
|
1384
|
+
let d = 0;
|
|
1305
1385
|
function kt() {
|
|
1306
|
-
|
|
1386
|
+
d = 0;
|
|
1307
1387
|
}
|
|
1308
1388
|
function Lt(i, t, e) {
|
|
1309
1389
|
return {
|
|
1310
1390
|
meta: {
|
|
1311
|
-
id: `input_${
|
|
1391
|
+
id: `input_${d++}`,
|
|
1312
1392
|
type: "int",
|
|
1313
1393
|
title: t ?? null,
|
|
1314
1394
|
defaultValue: i,
|
|
@@ -1319,10 +1399,10 @@ function Lt(i, t, e) {
|
|
|
1319
1399
|
value: i
|
|
1320
1400
|
};
|
|
1321
1401
|
}
|
|
1322
|
-
function
|
|
1402
|
+
function Ct(i, t, e) {
|
|
1323
1403
|
return {
|
|
1324
1404
|
meta: {
|
|
1325
|
-
id: `input_${
|
|
1405
|
+
id: `input_${d++}`,
|
|
1326
1406
|
type: "float",
|
|
1327
1407
|
title: t ?? null,
|
|
1328
1408
|
defaultValue: i,
|
|
@@ -1333,10 +1413,10 @@ function bt(i, t, e) {
|
|
|
1333
1413
|
value: i
|
|
1334
1414
|
};
|
|
1335
1415
|
}
|
|
1336
|
-
function
|
|
1416
|
+
function bt(i, t) {
|
|
1337
1417
|
return {
|
|
1338
1418
|
meta: {
|
|
1339
|
-
id: `input_${
|
|
1419
|
+
id: `input_${d++}`,
|
|
1340
1420
|
type: "bool",
|
|
1341
1421
|
title: t ?? null,
|
|
1342
1422
|
defaultValue: i
|
|
@@ -1344,10 +1424,10 @@ function Ct(i, t) {
|
|
|
1344
1424
|
value: i
|
|
1345
1425
|
};
|
|
1346
1426
|
}
|
|
1347
|
-
function
|
|
1427
|
+
function Pt(i, t, e) {
|
|
1348
1428
|
return {
|
|
1349
1429
|
meta: {
|
|
1350
|
-
id: `input_${
|
|
1430
|
+
id: `input_${d++}`,
|
|
1351
1431
|
type: "string",
|
|
1352
1432
|
title: t ?? null,
|
|
1353
1433
|
defaultValue: i,
|
|
@@ -1356,10 +1436,10 @@ function Ot(i, t, e) {
|
|
|
1356
1436
|
value: i
|
|
1357
1437
|
};
|
|
1358
1438
|
}
|
|
1359
|
-
function
|
|
1439
|
+
function Ot(i, t) {
|
|
1360
1440
|
return {
|
|
1361
1441
|
meta: {
|
|
1362
|
-
id: `input_${
|
|
1442
|
+
id: `input_${d++}`,
|
|
1363
1443
|
type: "color",
|
|
1364
1444
|
title: t ?? null,
|
|
1365
1445
|
defaultValue: i
|
|
@@ -1367,10 +1447,10 @@ function Pt(i, t) {
|
|
|
1367
1447
|
value: i
|
|
1368
1448
|
};
|
|
1369
1449
|
}
|
|
1370
|
-
function
|
|
1450
|
+
function Mt(i, t) {
|
|
1371
1451
|
return {
|
|
1372
1452
|
meta: {
|
|
1373
|
-
id: `input_${
|
|
1453
|
+
id: `input_${d++}`,
|
|
1374
1454
|
type: "source",
|
|
1375
1455
|
title: t ?? null,
|
|
1376
1456
|
defaultValue: i
|
|
@@ -1378,11 +1458,11 @@ function _t(i, t) {
|
|
|
1378
1458
|
value: i
|
|
1379
1459
|
};
|
|
1380
1460
|
}
|
|
1381
|
-
function
|
|
1461
|
+
function _t(i, t) {
|
|
1382
1462
|
const e = typeof i == "number" ? Number.isInteger(i) ? "int" : "float" : typeof i == "boolean" ? "bool" : "string";
|
|
1383
1463
|
return {
|
|
1384
1464
|
meta: {
|
|
1385
|
-
id: `input_${
|
|
1465
|
+
id: `input_${d++}`,
|
|
1386
1466
|
type: e,
|
|
1387
1467
|
title: t ?? null,
|
|
1388
1468
|
defaultValue: i
|
|
@@ -1391,27 +1471,27 @@ function Mt(i, t) {
|
|
|
1391
1471
|
};
|
|
1392
1472
|
}
|
|
1393
1473
|
const Dt = {
|
|
1394
|
-
input:
|
|
1474
|
+
input: _t,
|
|
1395
1475
|
"input.int": Lt,
|
|
1396
|
-
"input.float":
|
|
1397
|
-
"input.bool":
|
|
1398
|
-
"input.string":
|
|
1399
|
-
"input.color":
|
|
1400
|
-
"input.source":
|
|
1476
|
+
"input.float": Ct,
|
|
1477
|
+
"input.bool": bt,
|
|
1478
|
+
"input.string": Pt,
|
|
1479
|
+
"input.color": Ot,
|
|
1480
|
+
"input.source": Mt
|
|
1401
1481
|
};
|
|
1402
1482
|
/**
|
|
1403
1483
|
* pine-to-kline — Builtins Master Index
|
|
1404
1484
|
* Central registry of all built-in functions and constants
|
|
1405
1485
|
* @license Apache-2.0
|
|
1406
1486
|
*/
|
|
1407
|
-
const
|
|
1408
|
-
...St,
|
|
1487
|
+
const k = {
|
|
1409
1488
|
...Rt,
|
|
1489
|
+
...St,
|
|
1410
1490
|
...gt,
|
|
1411
1491
|
...Dt
|
|
1412
|
-
},
|
|
1492
|
+
}, S = {
|
|
1413
1493
|
...yt,
|
|
1414
|
-
...
|
|
1494
|
+
...v,
|
|
1415
1495
|
// Pine special constants
|
|
1416
1496
|
na: NaN,
|
|
1417
1497
|
true: !0,
|
|
@@ -1423,7 +1503,7 @@ const g = {
|
|
|
1423
1503
|
* Produces arrays of computed values for each plot.
|
|
1424
1504
|
* @license Apache-2.0
|
|
1425
1505
|
*/
|
|
1426
|
-
class
|
|
1506
|
+
class _ {
|
|
1427
1507
|
constructor() {
|
|
1428
1508
|
p(this, "ctx");
|
|
1429
1509
|
p(this, "vars", new W());
|
|
@@ -1485,8 +1565,8 @@ class D {
|
|
|
1485
1565
|
const c = e.length, o = [];
|
|
1486
1566
|
for (let u = 0; u < c; u++) {
|
|
1487
1567
|
const f = {};
|
|
1488
|
-
for (const [E,
|
|
1489
|
-
f[E] =
|
|
1568
|
+
for (const [E, A] of this.plotResults)
|
|
1569
|
+
f[E] = A[u] ?? NaN;
|
|
1490
1570
|
o.push(f);
|
|
1491
1571
|
}
|
|
1492
1572
|
return o;
|
|
@@ -1621,7 +1701,7 @@ class D {
|
|
|
1621
1701
|
return NaN;
|
|
1622
1702
|
case "Identifier": {
|
|
1623
1703
|
const n = t.name;
|
|
1624
|
-
return this.scope.has(n) ? this.scope.get(n) : e && n in e ? e[n] :
|
|
1704
|
+
return this.scope.has(n) ? this.scope.get(n) : e && n in e ? e[n] : S[n] !== void 0 ? S[n] : v[n] ? v[n] : n === "bar_index" ? Array.from({ length: this.ctx.barCount }, (l, h) => h) : void 0;
|
|
1625
1705
|
}
|
|
1626
1706
|
case "BinaryExpr": {
|
|
1627
1707
|
const n = this.evalExpr(t.left, e, s, r), l = this.evalExpr(t.right, e, s, r);
|
|
@@ -1647,7 +1727,7 @@ class D {
|
|
|
1647
1727
|
}
|
|
1648
1728
|
case "MemberExpr": {
|
|
1649
1729
|
const n = this.buildMemberName(t);
|
|
1650
|
-
return
|
|
1730
|
+
return S[n] !== void 0 ? S[n] : v[n] ? v[n] : e && n in e ? e[n] : n;
|
|
1651
1731
|
}
|
|
1652
1732
|
default:
|
|
1653
1733
|
return;
|
|
@@ -1656,7 +1736,7 @@ class D {
|
|
|
1656
1736
|
evalFunctionCall(t, e, s, r) {
|
|
1657
1737
|
const n = t.args.map((c) => this.evalExpr(c, e, s, r)), l = Object.fromEntries(t.kwargs.map((c) => [c.key, this.evalExpr(c.value, e, s, r)])), h = t.callee;
|
|
1658
1738
|
if (h.startsWith("input")) {
|
|
1659
|
-
const c =
|
|
1739
|
+
const c = k[h];
|
|
1660
1740
|
if (c) {
|
|
1661
1741
|
const o = c(n[0], l.title ?? n[1], l);
|
|
1662
1742
|
r && r.push(o.meta);
|
|
@@ -1664,8 +1744,8 @@ class D {
|
|
|
1664
1744
|
return o.meta.type === "source" && e ? e[f] ?? e.close : f;
|
|
1665
1745
|
}
|
|
1666
1746
|
}
|
|
1667
|
-
if (
|
|
1668
|
-
return
|
|
1747
|
+
if (k[h])
|
|
1748
|
+
return k[h](...n);
|
|
1669
1749
|
if (this.functions.has(h))
|
|
1670
1750
|
return this.callUserFunction(h, n, e, s, r);
|
|
1671
1751
|
if (h === "nz") {
|
|
@@ -1749,7 +1829,7 @@ class D {
|
|
|
1749
1829
|
}
|
|
1750
1830
|
// ─── Helpers ──────────────────────────────────────────────
|
|
1751
1831
|
resolveColor(t) {
|
|
1752
|
-
return t && typeof t == "string" ? t.startsWith("#") ? t :
|
|
1832
|
+
return t && typeof t == "string" ? t.startsWith("#") ? t : v[t] ? v[t] : t : null;
|
|
1753
1833
|
}
|
|
1754
1834
|
buildMemberName(t) {
|
|
1755
1835
|
return t.type === "Identifier" ? t.name : t.type === "MemberExpr" ? this.buildMemberName(t.object) + "." + t.property : "";
|
|
@@ -1760,7 +1840,7 @@ class D {
|
|
|
1760
1840
|
* Maps Pine plot styles to KlineChart figure types
|
|
1761
1841
|
* @license Apache-2.0
|
|
1762
1842
|
*/
|
|
1763
|
-
const
|
|
1843
|
+
const Tt = {
|
|
1764
1844
|
"plot.style_line": "line",
|
|
1765
1845
|
"plot.style_linebr": "line",
|
|
1766
1846
|
"plot.style_stepline": "line",
|
|
@@ -1771,19 +1851,19 @@ const Ft = {
|
|
|
1771
1851
|
"plot.style_circles": "circle",
|
|
1772
1852
|
"plot.style_cross": "circle"
|
|
1773
1853
|
};
|
|
1774
|
-
function
|
|
1775
|
-
return i ?
|
|
1854
|
+
function Ft(i) {
|
|
1855
|
+
return i ? Tt[i] ?? "line" : "line";
|
|
1776
1856
|
}
|
|
1777
1857
|
/**
|
|
1778
1858
|
* pine-to-kline — Style Mapper
|
|
1779
1859
|
* Converts Pine style values to KlineChart-compatible CSS
|
|
1780
1860
|
* @license Apache-2.0
|
|
1781
1861
|
*/
|
|
1782
|
-
function
|
|
1862
|
+
function L(i) {
|
|
1783
1863
|
if (!i) return "#2196F3";
|
|
1784
1864
|
if (typeof i == "string") {
|
|
1785
1865
|
if (i.startsWith("#")) return i;
|
|
1786
|
-
if (
|
|
1866
|
+
if (v[i]) return v[i];
|
|
1787
1867
|
}
|
|
1788
1868
|
return "#2196F3";
|
|
1789
1869
|
}
|
|
@@ -1803,7 +1883,7 @@ function Bt(i) {
|
|
|
1803
1883
|
* Converts PineRuntime IR → KlineChart IndicatorTemplate
|
|
1804
1884
|
* @license Apache-2.0
|
|
1805
1885
|
*/
|
|
1806
|
-
class
|
|
1886
|
+
class Gt {
|
|
1807
1887
|
toIndicatorTemplate(t) {
|
|
1808
1888
|
const { meta: e, inputs: s, plots: r, hlines: n, calcFn: l } = t;
|
|
1809
1889
|
return {
|
|
@@ -1825,12 +1905,12 @@ class Ut {
|
|
|
1825
1905
|
draw: (c) => {
|
|
1826
1906
|
const { ctx: o, bounding: u, indicator: f, yAxis: E } = c;
|
|
1827
1907
|
if (!o || !E) return !1;
|
|
1828
|
-
for (const
|
|
1829
|
-
const I = E.convertToPixel(
|
|
1908
|
+
for (const A of n) {
|
|
1909
|
+
const I = E.convertToPixel(A.price);
|
|
1830
1910
|
if (I < u.top || I > u.top + u.height) continue;
|
|
1831
|
-
o.save(), o.strokeStyle =
|
|
1832
|
-
const b = Bt(
|
|
1833
|
-
b.length && o.setLineDash(b), o.beginPath(), o.moveTo(u.left, I), o.lineTo(u.left + u.width, I), o.stroke(),
|
|
1911
|
+
o.save(), o.strokeStyle = L(A.color), o.lineWidth = A.linewidth ?? 1;
|
|
1912
|
+
const b = Bt(A.linestyle);
|
|
1913
|
+
b.length && o.setLineDash(b), o.beginPath(), o.moveTo(u.left, I), o.lineTo(u.left + u.width, I), o.stroke(), A.title && (o.fillStyle = L(A.color), o.font = "10px sans-serif", o.textAlign = "right", o.fillText(A.title, u.left + u.width - 4, I - 4)), o.restore();
|
|
1834
1914
|
}
|
|
1835
1915
|
return !1;
|
|
1836
1916
|
}
|
|
@@ -1852,9 +1932,9 @@ class Ut {
|
|
|
1852
1932
|
return t.map((e) => ({
|
|
1853
1933
|
key: e.id,
|
|
1854
1934
|
title: `${e.title ?? e.id}: `,
|
|
1855
|
-
type:
|
|
1935
|
+
type: Ft(e.style),
|
|
1856
1936
|
styles: (s, r, n) => ({
|
|
1857
|
-
color:
|
|
1937
|
+
color: L(e.color)
|
|
1858
1938
|
})
|
|
1859
1939
|
}));
|
|
1860
1940
|
}
|
|
@@ -1864,7 +1944,7 @@ class Ut {
|
|
|
1864
1944
|
* Main entry point class for the library
|
|
1865
1945
|
* @license Apache-2.0
|
|
1866
1946
|
*/
|
|
1867
|
-
const
|
|
1947
|
+
const Ut = {
|
|
1868
1948
|
version: "v5",
|
|
1869
1949
|
strict: !1,
|
|
1870
1950
|
sandbox: !0,
|
|
@@ -1874,15 +1954,15 @@ const Gt = {
|
|
|
1874
1954
|
class Vt {
|
|
1875
1955
|
constructor(t = {}) {
|
|
1876
1956
|
p(this, "options");
|
|
1877
|
-
this.options = { ...
|
|
1957
|
+
this.options = { ...Ut, ...t };
|
|
1878
1958
|
}
|
|
1879
1959
|
/** Full compile: PineScript source → IndicatorConfig (IndicatorTemplate) */
|
|
1880
1960
|
compile(t) {
|
|
1881
1961
|
try {
|
|
1882
|
-
const e = new
|
|
1962
|
+
const e = new P(t).tokenize(), s = new O(e).parse(), r = new _(), n = [{ timestamp: 0, open: 0, high: 0, low: 0, close: 0 }], l = r.execute(s, n), h = {
|
|
1883
1963
|
...l,
|
|
1884
|
-
calcFn: (u, f) => new
|
|
1885
|
-
}, o = new
|
|
1964
|
+
calcFn: (u, f) => new _().execute(s, u, f).calcFn(u, f)
|
|
1965
|
+
}, o = new Gt().toIndicatorTemplate(h);
|
|
1886
1966
|
return {
|
|
1887
1967
|
success: !0,
|
|
1888
1968
|
indicatorConfig: o,
|
|
@@ -1903,8 +1983,8 @@ class Vt {
|
|
|
1903
1983
|
/** Validate syntax only (no execution) */
|
|
1904
1984
|
validate(t) {
|
|
1905
1985
|
try {
|
|
1906
|
-
const e = new
|
|
1907
|
-
return new
|
|
1986
|
+
const e = new P(t).tokenize();
|
|
1987
|
+
return new O(e).parse(), { valid: !0, errors: [] };
|
|
1908
1988
|
} catch (e) {
|
|
1909
1989
|
return { valid: !1, errors: [e] };
|
|
1910
1990
|
}
|
|
@@ -1977,21 +2057,21 @@ class Kt {
|
|
|
1977
2057
|
}
|
|
1978
2058
|
}
|
|
1979
2059
|
export {
|
|
1980
|
-
|
|
1981
|
-
|
|
2060
|
+
k as ALL_BUILTINS,
|
|
2061
|
+
S as ALL_CONSTANTS,
|
|
1982
2062
|
jt as AdapterError,
|
|
1983
2063
|
M as BarContext,
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
2064
|
+
Gt as KlineAdapter,
|
|
2065
|
+
P as Lexer,
|
|
2066
|
+
R as LexerError,
|
|
2067
|
+
g as ParseError,
|
|
2068
|
+
O as Parser,
|
|
1989
2069
|
w as PineError,
|
|
1990
2070
|
Vt as PineInterpreter,
|
|
1991
|
-
|
|
2071
|
+
_ as PineRuntime,
|
|
1992
2072
|
Ht as RuntimeError,
|
|
1993
2073
|
Kt as SeriesEmulator,
|
|
1994
|
-
|
|
2074
|
+
Rt as TA_REGISTRY,
|
|
1995
2075
|
N as Token,
|
|
1996
2076
|
a as TokenType,
|
|
1997
2077
|
$t as createPinePlugin
|