@rsconcept/domain 1.4.5 → 1.4.6
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/dist/{analyzer-BIVXNtT6.d.ts → analyzer-54lGGg13.d.ts} +2 -2
- package/dist/{ast-annotations-Dfz-KtUp.d.ts → ast-annotations-C0eMySxt.d.ts} +2 -2
- package/dist/{calculator-KRU6RIzZ.d.ts → calculator-BQnE2gws.d.ts} +2 -2
- package/dist/{error-CpOz9MFT.d.ts → error-CxIs0A7Y.d.ts} +4 -1
- package/dist/index.d.ts +4 -4
- package/dist/library/rsengine.d.ts +1 -1
- package/dist/library/rsform-api.d.ts +1 -1
- package/dist/library/rsform.d.ts +1 -1
- package/dist/rslang/ast-annotations.d.ts +1 -1
- package/dist/rslang/error.d.ts +1 -1
- package/dist/rslang/error.js +3 -0
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +1 -1
- package/dist/rslang/eval/evaluator.d.ts +1 -1
- package/dist/rslang/index.d.ts +4 -4
- package/dist/rslang/parser/syntax-errors.d.ts +1 -1
- package/dist/rslang/parser/syntax-errors.js +123 -9
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +3 -1
- package/dist/rslang/semantic/type-auditor.js +44 -13
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +1 -1
- package/package.json +5 -5
- package/src/rslang/error.ts +3 -0
- package/src/rslang/parser/parser.test.ts +5 -1
- package/src/rslang/parser/syntax-errors.ts +194 -9
- package/src/rslang/semantic/type-auditor.test.ts +7 -4
- package/src/rslang/semantic/type-auditor.ts +55 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
2
|
import { f as ExpressionType, g as TypeClass } from "./typification-Dk-fisgO.js";
|
|
3
|
-
import { i as RSErrorDescription } from "./error-
|
|
3
|
+
import { i as RSErrorDescription } from "./error-CxIs0A7Y.js";
|
|
4
4
|
import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
|
|
5
5
|
|
|
6
6
|
//#region src/rslang/semantic/analyzer.d.ts
|
|
@@ -36,4 +36,4 @@ declare class RSLangAnalyzer {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
export { RSLangAnalyzer as a, AnalysisOptions as i, AnalysisFast as n, AnalysisFull as r, AnalysisBase as t };
|
|
39
|
-
//# sourceMappingURL=analyzer-
|
|
39
|
+
//# sourceMappingURL=analyzer-54lGGg13.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
2
|
import { f as ExpressionType } from "./typification-Dk-fisgO.js";
|
|
3
|
-
import { a as RSErrorInfo, r as RSErrorCode } from "./error-
|
|
3
|
+
import { a as RSErrorInfo, r as RSErrorCode } from "./error-CxIs0A7Y.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/ast-annotations.d.ts
|
|
6
6
|
/** Appends {@link ExpressionType} onto the node's `annotation.rsType`. */
|
|
@@ -13,4 +13,4 @@ declare function annotateError(node: AstNode, code: RSErrorCode, params?: readon
|
|
|
13
13
|
declare function readErrorAnnotation(node: AstNode): RSErrorInfo | null;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { readTypeAnnotation as i, annotateType as n, readErrorAnnotation as r, annotateError as t };
|
|
16
|
-
//# sourceMappingURL=ast-annotations-
|
|
16
|
+
//# sourceMappingURL=ast-annotations-C0eMySxt.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
2
|
import { f as ExpressionType } from "./typification-Dk-fisgO.js";
|
|
3
|
-
import { i as RSErrorDescription } from "./error-
|
|
3
|
+
import { i as RSErrorDescription } from "./error-CxIs0A7Y.js";
|
|
4
4
|
import { l as Value } from "./value-BduA_ZGp.js";
|
|
5
5
|
|
|
6
6
|
//#region src/rslang/eval/calculator.d.ts
|
|
@@ -36,4 +36,4 @@ declare class RSCalculator {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
export { CalculatorResult as n, RSCalculator as r, CalculatorEvaluateOptions as t };
|
|
39
|
-
//# sourceMappingURL=calculator-
|
|
39
|
+
//# sourceMappingURL=calculator-BQnE2gws.d.ts.map
|
|
@@ -28,6 +28,7 @@ declare const RSErrorCode: {
|
|
|
28
28
|
readonly doubleParenthesis: 33802;
|
|
29
29
|
readonly missingOpenBracket: 33803;
|
|
30
30
|
readonly missingCloseBracket: 33804;
|
|
31
|
+
readonly invalidFilterSyntax: 33815;
|
|
31
32
|
readonly expectedLocal: 33813;
|
|
32
33
|
readonly expectedType: 33814;
|
|
33
34
|
readonly localDoubleDeclare: 10241;
|
|
@@ -64,6 +65,8 @@ declare const RSErrorCode: {
|
|
|
64
65
|
readonly invalidArgumentCortegeDeclare: 34857;
|
|
65
66
|
readonly invalidQuantifierDomain: 34858;
|
|
66
67
|
readonly invalidFilterParameterType: 34859;
|
|
68
|
+
readonly invalidFilterIndex: 34860;
|
|
69
|
+
readonly invalidFilterBooleanEchelon: 34861;
|
|
67
70
|
readonly globalNoValue: 34880;
|
|
68
71
|
readonly invalidPropertyUsage: 34881;
|
|
69
72
|
readonly calcUnknownError: 33024;
|
|
@@ -85,4 +88,4 @@ declare function getRSErrorPrefix(code: RSErrorCode): string;
|
|
|
85
88
|
declare function isCritical(code: RSErrorCode): boolean;
|
|
86
89
|
//#endregion
|
|
87
90
|
export { RSErrorInfo as a, RSErrorDescription as i, RSErrorClass as n, getRSErrorPrefix as o, RSErrorCode as r, isCritical as s, ErrorReporter as t };
|
|
88
|
-
//# sourceMappingURL=error-
|
|
91
|
+
//# sourceMappingURL=error-CxIs0A7Y.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -9,15 +9,15 @@ import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i a
|
|
|
9
9
|
import { t as Branded } from "./branded-ZlzIcxzu.js";
|
|
10
10
|
import { n as generateStub, t as applyHash_fnv1a } from "./hash-Y8I4c6Al.js";
|
|
11
11
|
import { O as makeTypePath, b as Typification, d as EmptySetT, f as ExpressionType, g as TypeClass, m as LogicT, t as AnyTypificationT, v as TypeID, y as TypePath } from "./typification-Dk-fisgO.js";
|
|
12
|
-
import { i as RSErrorDescription, r as RSErrorCode } from "./error-
|
|
13
|
-
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-
|
|
12
|
+
import { i as RSErrorDescription, r as RSErrorCode } from "./error-CxIs0A7Y.js";
|
|
13
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-C0eMySxt.js";
|
|
14
14
|
import { d as ValuePath, l as Value, o as TUPLE_ID, p as makeValuePath } from "./value-BduA_ZGp.js";
|
|
15
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-
|
|
15
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-BQnE2gws.js";
|
|
16
16
|
import { d as printValue } from "./value-api-B6T6f4Ia.js";
|
|
17
17
|
import { t as parser } from "./parser-Bwd8LxJ1.js";
|
|
18
18
|
import { t as TokenID } from "./token-DeXAmzwr.js";
|
|
19
19
|
import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
|
|
20
|
-
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-
|
|
20
|
+
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-54lGGg13.js";
|
|
21
21
|
import { n as ArgumentsType } from "./arguments-extractor-1acwjQNc.js";
|
|
22
22
|
import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "./typification-parser-BBVx1RxP.js";
|
|
23
23
|
import { n as TypificationNodeData, t as TypificationGraph } from "./typification-graph-6HcZ-rKH.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "../ast-C8sIpKdL.js";
|
|
2
2
|
import { l as Value } from "../value-BduA_ZGp.js";
|
|
3
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-
|
|
3
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-BQnE2gws.js";
|
|
4
4
|
import { CstType, RSForm } from "./rsform.js";
|
|
5
5
|
import { BasicBinding, BasicsContext, EvalStatus, RSModel } from "./rsmodel.js";
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as LibraryItem } from "../library-CYun28Xz.js";
|
|
2
2
|
import { g as TypeClass, y as TypePath } from "../typification-Dk-fisgO.js";
|
|
3
3
|
import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
|
|
4
|
-
import { r as AnalysisFull } from "../analyzer-
|
|
4
|
+
import { r as AnalysisFull } from "../analyzer-54lGGg13.js";
|
|
5
5
|
import { ArgumentValue, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats } from "./rsform.js";
|
|
6
6
|
|
|
7
7
|
//#region src/library/rsform-api.d.ts
|
package/dist/library/rsform.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Graph } from "../graph-DR8rL2o3.js";
|
|
2
2
|
import { i as LibraryItemReference, n as CurrentVersion, r as LibraryItem, s as VersionInfo } from "../library-CYun28Xz.js";
|
|
3
3
|
import { f as ExpressionType, y as TypePath } from "../typification-Dk-fisgO.js";
|
|
4
|
-
import { a as RSLangAnalyzer, t as AnalysisBase } from "../analyzer-
|
|
4
|
+
import { a as RSLangAnalyzer, t as AnalysisBase } from "../analyzer-54lGGg13.js";
|
|
5
5
|
//#region src/library/rsform.d.ts
|
|
6
6
|
/** Represents {@link Constituenta} type. */
|
|
7
7
|
declare const CstType: {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-
|
|
1
|
+
import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-C0eMySxt.js";
|
|
2
2
|
export { annotateError, annotateType, readErrorAnnotation, readTypeAnnotation };
|
package/dist/rslang/error.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RSErrorInfo, i as RSErrorDescription, n as RSErrorClass, o as getRSErrorPrefix, r as RSErrorCode, s as isCritical, t as ErrorReporter } from "../error-
|
|
1
|
+
import { a as RSErrorInfo, i as RSErrorDescription, n as RSErrorClass, o as getRSErrorPrefix, r as RSErrorCode, s as isCritical, t as ErrorReporter } from "../error-CxIs0A7Y.js";
|
|
2
2
|
export { ErrorReporter, RSErrorClass, RSErrorCode, RSErrorDescription, RSErrorInfo, getRSErrorPrefix, isCritical };
|
package/dist/rslang/error.js
CHANGED
|
@@ -15,6 +15,7 @@ const RSErrorCode = {
|
|
|
15
15
|
doubleParenthesis: 33802,
|
|
16
16
|
missingOpenBracket: 33803,
|
|
17
17
|
missingCloseBracket: 33804,
|
|
18
|
+
invalidFilterSyntax: 33815,
|
|
18
19
|
expectedLocal: 33813,
|
|
19
20
|
expectedType: 33814,
|
|
20
21
|
localDoubleDeclare: 10241,
|
|
@@ -51,6 +52,8 @@ const RSErrorCode = {
|
|
|
51
52
|
invalidArgumentCortegeDeclare: 34857,
|
|
52
53
|
invalidQuantifierDomain: 34858,
|
|
53
54
|
invalidFilterParameterType: 34859,
|
|
55
|
+
invalidFilterIndex: 34860,
|
|
56
|
+
invalidFilterBooleanEchelon: 34861,
|
|
54
57
|
globalNoValue: 34880,
|
|
55
58
|
invalidPropertyUsage: 34881,
|
|
56
59
|
calcUnknownError: 33024,
|
package/dist/rslang/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":[],"sources":["../../src/rslang/error.ts"],"sourcesContent":["/** Module: Error types and functions. */\n\n/** Represents error class. */\nexport const RSErrorClass = {\n LEXER: 0,\n PARSER: 1,\n SEMANTIC: 2,\n EVALUATION: 3,\n UNKNOWN: 4\n} as const;\nexport type RSErrorClass = (typeof RSErrorClass)[keyof typeof RSErrorClass];\n\n/** Represents RSLang expression error information. */\nexport interface RSErrorInfo {\n code: RSErrorCode;\n params?: readonly string[];\n}\n\n/** Represents RSLang expression error description. */\nexport interface RSErrorDescription extends RSErrorInfo {\n from: number;\n to: number;\n}\n\n/** Error reporter function type. */\nexport type ErrorReporter = (error: RSErrorDescription) => void;\n\n/** Represents RSLang expression error types. */\nexport const RSErrorCode = {\n unknownSyntax: 0x8400, // 33792\n bracketMismatch: 0x8409, // 33801\n doubleParenthesis: 0x840a, // 33802\n missingOpenBracket: 0x840b, // 33803\n missingCloseBracket: 0x840c, // 33804\n expectedLocal: 0x8415, // 33813\n expectedType: 0x8416, // 33814\n\n localDoubleDeclare: 0x2801, // 10241\n localNotUsed: 0x2802, // 10242\n\n localUndeclared: 0x8801, // 34817\n localShadowing: 0x8802, // 34818\n\n typesNotEqual: 0x8803, // 34819\n globalNotTyped: 0x8804, // 34820\n invalidDecart: 0x8805, // 34821\n invalidBoolean: 0x8806, // 34822\n invalidTypeOperation: 0x8807, // 34823\n invalidCard: 0x8808, // 34824\n invalidDebool: 0x8809, // 34825\n globalFuncWithoutArgs: 0x880b, // 34827\n invalidReduce: 0x8810, // 34832\n invalidProjectionTuple: 0x8811, // 34833\n invalidProjectionSet: 0x8812, // 34834\n invalidEnumeration: 0x8813, // 34835\n invalidCortegeDeclare: 0x8814, // 34836\n localOutOfScope: 0x8815, // 34837\n invalidElementPredicate: 0x8816, // 34838\n invalidEmptySetUsage: 0x8817, // 34839\n invalidArgsArity: 0x8818, // 34840\n invalidArgumentType: 0x8819, // 34841\n globalStructure: 0x881c, // 34844\n radicalUsage: 0x8821, // 34849\n invalidFilterArgumentType: 0x8822, // 34850\n invalidFilterArity: 0x8823, // 34851\n arithmeticNotSupported: 0x8824, // 34852\n typesNotCompatible: 0x8825, // 34853\n orderingNotSupported: 0x8826, // 34854\n expectedLogic: 0x8827, // 34855\n expectedSetexpr: 0x8828, // 34856\n invalidArgumentCortegeDeclare: 0x8829, // 34857\n invalidQuantifierDomain: 0x882a, // 34858\n invalidFilterParameterType: 0x882b, // 34859\n\n globalNoValue: 0x8840, // 34880\n invalidPropertyUsage: 0x8841, // 34881\n\n // Value evaluation (runtime)\n calcUnknownError: 0x8100, // 35328\n setOverflow: 0x8101, // 35329\n booleanBaseLimit: 0x8102, // 35330\n calcGlobalMissing: 0x8103, // 35331\n iterationsLimit: 0x8104, // 35332\n calcInvalidDebool: 0x8105, // 35333\n iterateInfinity: 0x8106, // 35334\n calculationNotSupported: 0x8107, // 35335\n calcInvalidData: 0x8108, // 35336\n\n cstEmptyDerived: 0x8861, // 34913\n definitionNotAllowed: 0x8862 // 34914\n} as const;\nexport type RSErrorCode = (typeof RSErrorCode)[keyof typeof RSErrorCode];\n\nconst ERROR_EVALUATION_MASK = 0x0100;\nconst ERROR_LEXER_MASK = 0x0200;\nconst ERROR_PARSER_MASK = 0x0400;\nconst ERROR_SEMANTIC_MASK = 0x0800;\n\n/** Infers error class from error type (code). */\nfunction inferErrorClass(error: RSErrorCode): RSErrorClass {\n if ((error & ERROR_EVALUATION_MASK) !== 0) {\n return RSErrorClass.EVALUATION;\n } else if ((error & ERROR_LEXER_MASK) !== 0) {\n return RSErrorClass.LEXER;\n } else if ((error & ERROR_PARSER_MASK) !== 0) {\n return RSErrorClass.PARSER;\n } else if ((error & ERROR_SEMANTIC_MASK) !== 0) {\n return RSErrorClass.SEMANTIC;\n } else {\n return RSErrorClass.UNKNOWN;\n }\n}\n\n/** Generate ErrorID label. */\nexport function getRSErrorPrefix(code: RSErrorCode): string {\n const id = code.toString(16).toUpperCase();\n // prettier-ignore\n switch (inferErrorClass(code)) {\n case RSErrorClass.LEXER: return 'L' + id;\n case RSErrorClass.PARSER: return 'P' + id;\n case RSErrorClass.SEMANTIC: return 'S' + id;\n case RSErrorClass.EVALUATION: return 'E' + id;\n case RSErrorClass.UNKNOWN: return 'U' + id;\n }\n}\n\n/** Checks if error is critical. */\nexport function isCritical(code: RSErrorCode): boolean {\n return code !== RSErrorCode.localDoubleDeclare && code !== RSErrorCode.localNotUsed;\n}\n"],"mappings":";;;AAGA,MAAa,eAAe;CAC1B,OAAO;CACP,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;AACX;;AAmBA,MAAa,cAAc;CACzB,eAAe;CACf,iBAAiB;CACjB,mBAAmB;CACnB,oBAAoB;CACpB,qBAAqB;CACrB,eAAe;CACf,cAAc;CAEd,oBAAoB;CACpB,cAAc;CAEd,iBAAiB;CACjB,gBAAgB;CAEhB,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,aAAa;CACb,eAAe;CACf,uBAAuB;CACvB,eAAe;CACf,wBAAwB;CACxB,sBAAsB;CACtB,oBAAoB;CACpB,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,cAAc;CACd,2BAA2B;CAC3B,oBAAoB;CACpB,wBAAwB;CACxB,oBAAoB;CACpB,sBAAsB;CACtB,eAAe;CACf,iBAAiB;CACjB,+BAA+B;CAC/B,yBAAyB;CACzB,4BAA4B;
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../src/rslang/error.ts"],"sourcesContent":["/** Module: Error types and functions. */\n\n/** Represents error class. */\nexport const RSErrorClass = {\n LEXER: 0,\n PARSER: 1,\n SEMANTIC: 2,\n EVALUATION: 3,\n UNKNOWN: 4\n} as const;\nexport type RSErrorClass = (typeof RSErrorClass)[keyof typeof RSErrorClass];\n\n/** Represents RSLang expression error information. */\nexport interface RSErrorInfo {\n code: RSErrorCode;\n params?: readonly string[];\n}\n\n/** Represents RSLang expression error description. */\nexport interface RSErrorDescription extends RSErrorInfo {\n from: number;\n to: number;\n}\n\n/** Error reporter function type. */\nexport type ErrorReporter = (error: RSErrorDescription) => void;\n\n/** Represents RSLang expression error types. */\nexport const RSErrorCode = {\n unknownSyntax: 0x8400, // 33792\n bracketMismatch: 0x8409, // 33801\n doubleParenthesis: 0x840a, // 33802\n missingOpenBracket: 0x840b, // 33803\n missingCloseBracket: 0x840c, // 33804\n invalidFilterSyntax: 0x8417, // 33815\n expectedLocal: 0x8415, // 33813\n expectedType: 0x8416, // 33814\n\n localDoubleDeclare: 0x2801, // 10241\n localNotUsed: 0x2802, // 10242\n\n localUndeclared: 0x8801, // 34817\n localShadowing: 0x8802, // 34818\n\n typesNotEqual: 0x8803, // 34819\n globalNotTyped: 0x8804, // 34820\n invalidDecart: 0x8805, // 34821\n invalidBoolean: 0x8806, // 34822\n invalidTypeOperation: 0x8807, // 34823\n invalidCard: 0x8808, // 34824\n invalidDebool: 0x8809, // 34825\n globalFuncWithoutArgs: 0x880b, // 34827\n invalidReduce: 0x8810, // 34832\n invalidProjectionTuple: 0x8811, // 34833\n invalidProjectionSet: 0x8812, // 34834\n invalidEnumeration: 0x8813, // 34835\n invalidCortegeDeclare: 0x8814, // 34836\n localOutOfScope: 0x8815, // 34837\n invalidElementPredicate: 0x8816, // 34838\n invalidEmptySetUsage: 0x8817, // 34839\n invalidArgsArity: 0x8818, // 34840\n invalidArgumentType: 0x8819, // 34841\n globalStructure: 0x881c, // 34844\n radicalUsage: 0x8821, // 34849\n invalidFilterArgumentType: 0x8822, // 34850\n invalidFilterArity: 0x8823, // 34851\n arithmeticNotSupported: 0x8824, // 34852\n typesNotCompatible: 0x8825, // 34853\n orderingNotSupported: 0x8826, // 34854\n expectedLogic: 0x8827, // 34855\n expectedSetexpr: 0x8828, // 34856\n invalidArgumentCortegeDeclare: 0x8829, // 34857\n invalidQuantifierDomain: 0x882a, // 34858\n invalidFilterParameterType: 0x882b, // 34859\n invalidFilterIndex: 0x882c, // 34860\n invalidFilterBooleanEchelon: 0x882d, // 34861\n\n globalNoValue: 0x8840, // 34880\n invalidPropertyUsage: 0x8841, // 34881\n\n // Value evaluation (runtime)\n calcUnknownError: 0x8100, // 35328\n setOverflow: 0x8101, // 35329\n booleanBaseLimit: 0x8102, // 35330\n calcGlobalMissing: 0x8103, // 35331\n iterationsLimit: 0x8104, // 35332\n calcInvalidDebool: 0x8105, // 35333\n iterateInfinity: 0x8106, // 35334\n calculationNotSupported: 0x8107, // 35335\n calcInvalidData: 0x8108, // 35336\n\n cstEmptyDerived: 0x8861, // 34913\n definitionNotAllowed: 0x8862 // 34914\n} as const;\nexport type RSErrorCode = (typeof RSErrorCode)[keyof typeof RSErrorCode];\n\nconst ERROR_EVALUATION_MASK = 0x0100;\nconst ERROR_LEXER_MASK = 0x0200;\nconst ERROR_PARSER_MASK = 0x0400;\nconst ERROR_SEMANTIC_MASK = 0x0800;\n\n/** Infers error class from error type (code). */\nfunction inferErrorClass(error: RSErrorCode): RSErrorClass {\n if ((error & ERROR_EVALUATION_MASK) !== 0) {\n return RSErrorClass.EVALUATION;\n } else if ((error & ERROR_LEXER_MASK) !== 0) {\n return RSErrorClass.LEXER;\n } else if ((error & ERROR_PARSER_MASK) !== 0) {\n return RSErrorClass.PARSER;\n } else if ((error & ERROR_SEMANTIC_MASK) !== 0) {\n return RSErrorClass.SEMANTIC;\n } else {\n return RSErrorClass.UNKNOWN;\n }\n}\n\n/** Generate ErrorID label. */\nexport function getRSErrorPrefix(code: RSErrorCode): string {\n const id = code.toString(16).toUpperCase();\n // prettier-ignore\n switch (inferErrorClass(code)) {\n case RSErrorClass.LEXER: return 'L' + id;\n case RSErrorClass.PARSER: return 'P' + id;\n case RSErrorClass.SEMANTIC: return 'S' + id;\n case RSErrorClass.EVALUATION: return 'E' + id;\n case RSErrorClass.UNKNOWN: return 'U' + id;\n }\n}\n\n/** Checks if error is critical. */\nexport function isCritical(code: RSErrorCode): boolean {\n return code !== RSErr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C,OAAO,aAAa;MAEpB,OAAO,aAAa;AAExB;;AAGA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;CAEzC,QAAQ,gBAAgB,IAAI,GAA5B;EACE,KAAK,aAAa,OAAO,OAAO,MAAM;EACtC,KAAK,aAAa,QAAQ,OAAO,MAAM;EACvC,KAAK,aAAa,UAAU,OAAO,MAAM;EACzC,KAAK,aAAa,YAAY,OAAO,MAAM;EAC3C,KAAK,aAAa,SAAS,OAAO,MAAM;CAC1C;AACF;;AAGA,SAAgB,WAAW,MAA4B;CACrD,OAAO,SAAS,YAAY,sBAAsB,SAAS,YAAY;AACzE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-
|
|
1
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-BQnE2gws.js";
|
|
2
2
|
export { CalculatorEvaluateOptions, CalculatorResult, RSCalculator };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
|
-
import { t as ErrorReporter } from "../../error-
|
|
2
|
+
import { t as ErrorReporter } from "../../error-CxIs0A7Y.js";
|
|
3
3
|
import { l as Value, u as ValueContext } from "../../value-BduA_ZGp.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/eval/evaluator.d.ts
|
package/dist/rslang/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { O as makeTypePath, b as Typification, d as EmptySetT, f as ExpressionType, g as TypeClass, m as LogicT, t as AnyTypificationT, v as TypeID, y as TypePath } from "../typification-Dk-fisgO.js";
|
|
2
|
-
import { i as RSErrorDescription, r as RSErrorCode } from "../error-
|
|
3
|
-
import { i as readTypeAnnotation, r as readErrorAnnotation } from "../ast-annotations-
|
|
2
|
+
import { i as RSErrorDescription, r as RSErrorCode } from "../error-CxIs0A7Y.js";
|
|
3
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "../ast-annotations-C0eMySxt.js";
|
|
4
4
|
import { d as ValuePath, l as Value, p as makeValuePath } from "../value-BduA_ZGp.js";
|
|
5
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-
|
|
5
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-BQnE2gws.js";
|
|
6
6
|
import { d as printValue } from "../value-api-B6T6f4Ia.js";
|
|
7
7
|
import { t as parser } from "../parser-Bwd8LxJ1.js";
|
|
8
8
|
import { t as TokenID } from "../token-DeXAmzwr.js";
|
|
9
9
|
import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
|
|
10
|
-
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../analyzer-
|
|
10
|
+
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../analyzer-54lGGg13.js";
|
|
11
11
|
import { n as ArgumentsType } from "../arguments-extractor-1acwjQNc.js";
|
|
12
12
|
import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "../typification-parser-BBVx1RxP.js";
|
|
13
13
|
import { n as TypificationNodeData, t as TypificationGraph } from "../typification-graph-6HcZ-rKH.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
|
-
import { t as ErrorReporter } from "../../error-
|
|
2
|
+
import { t as ErrorReporter } from "../../error-CxIs0A7Y.js";
|
|
3
3
|
|
|
4
4
|
//#region src/rslang/parser/syntax-errors.d.ts
|
|
5
5
|
declare function extractSyntaxErrors(ast: AstNode, expression: string, reporter: ErrorReporter, annotateErrors?: boolean): void;
|
|
@@ -9,23 +9,35 @@ import "./parser.terms.js";
|
|
|
9
9
|
* Module: Syntactic errors reporting.
|
|
10
10
|
*/
|
|
11
11
|
function extractSyntaxErrors(ast, expression, reporter, annotateErrors = false) {
|
|
12
|
+
const collected = [];
|
|
13
|
+
const collect = (error) => {
|
|
14
|
+
collected.push(error);
|
|
15
|
+
};
|
|
12
16
|
const bracketError = extractBracketErrors(expression);
|
|
13
17
|
if (bracketError !== null) {
|
|
14
|
-
|
|
18
|
+
collect(bracketError);
|
|
15
19
|
if (annotateErrors) annotateError(ast, bracketError.code, bracketError.params);
|
|
16
20
|
}
|
|
17
21
|
const hasBracketErrors = bracketError !== null;
|
|
18
|
-
visitAstDFS(ast, (node) => extractInternal(node,
|
|
22
|
+
visitAstDFS(ast, (node) => extractInternal(node, expression, collect, annotateErrors, hasBracketErrors));
|
|
23
|
+
for (const error of deduplicateErrors(collected)) reporter(error);
|
|
19
24
|
}
|
|
20
|
-
function extractInternal(node, reporter, annotateErrors, ignoreUnknownErrors) {
|
|
25
|
+
function extractInternal(node, expression, reporter, annotateErrors, ignoreUnknownErrors) {
|
|
21
26
|
if (node.typeID !== TokenID.ERROR) return;
|
|
22
|
-
function emit(target, code) {
|
|
27
|
+
function emit(target, code, params) {
|
|
23
28
|
reporter({
|
|
24
29
|
code,
|
|
25
30
|
from: target.from,
|
|
26
|
-
to: target.to
|
|
31
|
+
to: target.to,
|
|
32
|
+
params
|
|
27
33
|
});
|
|
28
|
-
if (annotateErrors) annotateError(target, code);
|
|
34
|
+
if (annotateErrors) annotateError(target, code, params);
|
|
35
|
+
}
|
|
36
|
+
const classified = classifyParseError(node, expression);
|
|
37
|
+
if (classified !== null) {
|
|
38
|
+
reporter(classified);
|
|
39
|
+
if (annotateErrors) annotateError(node, classified.code, classified.params);
|
|
40
|
+
return;
|
|
29
41
|
}
|
|
30
42
|
const parent = node.parent;
|
|
31
43
|
if (parent === null) {
|
|
@@ -35,6 +47,108 @@ function extractInternal(node, reporter, annotateErrors, ignoreUnknownErrors) {
|
|
|
35
47
|
if (parent.typeID === 4) return emit(parent, RSErrorCode.expectedLocal);
|
|
36
48
|
if (!ignoreUnknownErrors) emit(node.from === node.to ? parent : node, RSErrorCode.unknownSyntax);
|
|
37
49
|
}
|
|
50
|
+
function classifyParseError(node, expression) {
|
|
51
|
+
const filterParen = detectFilterParenMismatch(node, expression);
|
|
52
|
+
if (filterParen !== null) return filterParen;
|
|
53
|
+
return detectGlobalFuncWithoutArgs(node, expression);
|
|
54
|
+
}
|
|
55
|
+
function detectFilterParenMismatch(node, expression) {
|
|
56
|
+
const filterNode = findAncestor(node, isFilterNode) ?? findRelatedNode(node, isFilterNode);
|
|
57
|
+
if (filterNode === null) return null;
|
|
58
|
+
if (expression[filterNode.to] === "(") return {
|
|
59
|
+
code: RSErrorCode.invalidFilterSyntax,
|
|
60
|
+
from: filterNode.from,
|
|
61
|
+
to: filterNode.to + 1
|
|
62
|
+
};
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
function detectGlobalFuncWithoutArgs(node, expression) {
|
|
66
|
+
const funcNode = findAncestor(node, (n) => isFunctionNode(n) || isPredicateNode(n)) ?? findRelatedNode(node, (n) => isFunctionNode(n) || isPredicateNode(n));
|
|
67
|
+
if (funcNode === null) return null;
|
|
68
|
+
return classifyFuncWithoutArgs(funcNode, expression);
|
|
69
|
+
}
|
|
70
|
+
function findRelatedNode(node, predicate) {
|
|
71
|
+
let current = node.parent;
|
|
72
|
+
while (current !== null) {
|
|
73
|
+
for (const child of current.children) if (predicate(child)) return child;
|
|
74
|
+
current = current.parent;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
function classifyFuncWithoutArgs(funcNode, expression) {
|
|
79
|
+
const name = expression.slice(funcNode.from, funcNode.to);
|
|
80
|
+
const rest = expression.slice(funcNode.to);
|
|
81
|
+
if (!/^\s*\[/.test(rest)) return {
|
|
82
|
+
code: RSErrorCode.globalFuncWithoutArgs,
|
|
83
|
+
from: funcNode.from,
|
|
84
|
+
to: funcNode.to,
|
|
85
|
+
params: [name]
|
|
86
|
+
};
|
|
87
|
+
if (/^\s*\[\s*\]/.test(rest)) return {
|
|
88
|
+
code: RSErrorCode.globalFuncWithoutArgs,
|
|
89
|
+
from: funcNode.from,
|
|
90
|
+
to: funcNode.to,
|
|
91
|
+
params: [name]
|
|
92
|
+
};
|
|
93
|
+
const openBracket = /^\s*\[/.exec(rest);
|
|
94
|
+
if (openBracket !== null) {
|
|
95
|
+
const closeIdx = findMatchingCloseBracket(rest, openBracket[0].length - 1);
|
|
96
|
+
if (closeIdx >= 0) {
|
|
97
|
+
if (rest.slice(openBracket[0].length, closeIdx).trim().length === 0) return {
|
|
98
|
+
code: RSErrorCode.globalFuncWithoutArgs,
|
|
99
|
+
from: funcNode.from,
|
|
100
|
+
to: funcNode.to,
|
|
101
|
+
params: [name]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
function findAncestor(node, predicate) {
|
|
108
|
+
let current = node;
|
|
109
|
+
while (current !== null) {
|
|
110
|
+
if (predicate(current)) return current;
|
|
111
|
+
current = current.parent;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
function isFunctionNode(node) {
|
|
116
|
+
return node.typeID === 69 || node.typeID === TokenID.ID_FUNCTION;
|
|
117
|
+
}
|
|
118
|
+
function isPredicateNode(node) {
|
|
119
|
+
return node.typeID === 26 || node.typeID === TokenID.ID_PREDICATE;
|
|
120
|
+
}
|
|
121
|
+
function isFilterNode(node) {
|
|
122
|
+
return node.typeID === 59 || node.typeID === TokenID.FILTER;
|
|
123
|
+
}
|
|
124
|
+
function findMatchingCloseBracket(expression, openPos) {
|
|
125
|
+
if (expression[openPos] !== "[") return -1;
|
|
126
|
+
let depth = 0;
|
|
127
|
+
for (let index = openPos; index < expression.length; index++) {
|
|
128
|
+
const symbol = expression[index];
|
|
129
|
+
if (symbol === "[") depth++;
|
|
130
|
+
else if (symbol === "]") {
|
|
131
|
+
depth--;
|
|
132
|
+
if (depth === 0) return index;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return -1;
|
|
136
|
+
}
|
|
137
|
+
function deduplicateErrors(errors) {
|
|
138
|
+
const result = [];
|
|
139
|
+
for (const error of errors) {
|
|
140
|
+
if (result.some((existing) => existing.code === error.code && existing.from === error.from && existing.to === error.to)) continue;
|
|
141
|
+
if (error.code !== RSErrorCode.unknownSyntax) {
|
|
142
|
+
for (let index = result.length - 1; index >= 0; index--) if (result[index].code === RSErrorCode.unknownSyntax && rangesOverlap(error, result[index])) result.splice(index, 1);
|
|
143
|
+
}
|
|
144
|
+
result.push(error);
|
|
145
|
+
}
|
|
146
|
+
const specific = result.filter((error) => error.code !== RSErrorCode.unknownSyntax);
|
|
147
|
+
return result.filter((error) => error.code !== RSErrorCode.unknownSyntax || !specific.some((item) => rangesOverlap(error, item)));
|
|
148
|
+
}
|
|
149
|
+
function rangesOverlap(a, b) {
|
|
150
|
+
return a.from < b.to && b.from < a.to;
|
|
151
|
+
}
|
|
38
152
|
function extractBracketErrors(expression) {
|
|
39
153
|
const stack = [];
|
|
40
154
|
for (let pos = 0; pos < expression.length; pos++) {
|
|
@@ -101,12 +215,12 @@ function closeToOpen(symbol) {
|
|
|
101
215
|
}
|
|
102
216
|
function isDoubleParenthesis(expression, pos) {
|
|
103
217
|
if (!(expression[pos] === "(" && expression[pos + 1] === "(")) return false;
|
|
104
|
-
const outerClose =
|
|
105
|
-
const innerClose =
|
|
218
|
+
const outerClose = findMatchingCloseParen(expression, pos);
|
|
219
|
+
const innerClose = findMatchingCloseParen(expression, pos + 1);
|
|
106
220
|
if (outerClose < 0 || innerClose < 0) return false;
|
|
107
221
|
return outerClose === innerClose + 1;
|
|
108
222
|
}
|
|
109
|
-
function
|
|
223
|
+
function findMatchingCloseParen(expression, openPos) {
|
|
110
224
|
if (expression[openPos] !== "(") return -1;
|
|
111
225
|
const stack = [];
|
|
112
226
|
for (let index = openPos; index < expression.length; index++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-errors.js","names":[],"sources":["../../../src/rslang/parser/syntax-errors.ts"],"sourcesContent":["/**\n * Module: Syntactic errors reporting.\n */\n\nimport { type AstNode, visitAstDFS } from '../../parsing';\nimport { annotateError } from '../ast-annotations';\nimport { type ErrorReporter, RSErrorCode, type RSErrorDescription } from '../error';\n\nimport { Variable } from './parser.terms';\nimport { TokenID } from './token';\n\nexport function extractSyntaxErrors(\n ast: AstNode,\n expression: string,\n reporter: ErrorReporter,\n annotateErrors: boolean = false\n) {\n const bracketError = extractBracketErrors(expression);\n if (bracketError !== null) {\n reporter(bracketError);\n if (annotateErrors) {\n annotateError(ast, bracketError.code, bracketError.params);\n }\n }\n const hasBracketErrors = bracketError !== null;\n visitAstDFS(ast, node => extractInternal(node, reporter, annotateErrors, hasBracketErrors));\n}\n\n// ====== Internals =========\nfunction extractInternal(\n node: AstNode,\n reporter: ErrorReporter,\n annotateErrors: boolean,\n ignoreUnknownErrors: boolean\n) {\n if (node.typeID !== TokenID.ERROR) {\n return;\n }\n\n function emit(target: AstNode, code: RSErrorCode) {\n reporter({ code: code, from: target.from, to: target.to });\n if (annotateErrors) {\n annotateError(target, code);\n }\n }\n\n const parent = node.parent;\n if (parent === null) {\n if (!ignoreUnknownErrors) {\n return emit(node, RSErrorCode.unknownSyntax);\n }\n return;\n }\n\n if (parent.typeID === Variable) {\n return emit(parent, RSErrorCode.expectedLocal);\n }\n\n if (!ignoreUnknownErrors) {\n emit(node.from === node.to ? parent : node, RSErrorCode.unknownSyntax);\n }\n}\n\ntype OpenBracket = '(' | '[' | '{';\ntype CloseBracket = ')' | ']' | '}';\n\ninterface BracketFrame {\n bracket: OpenBracket;\n index: number;\n}\n\nfunction extractBracketErrors(expression: string): RSErrorDescription | null {\n const stack: BracketFrame[] = [];\n\n for (let pos = 0; pos < expression.length; pos++) {\n const symbol = expression[pos];\n if (isOpenBracket(symbol)) {\n if (isDoubleParenthesis(expression, pos)) {\n return {\n code: RSErrorCode.doubleParenthesis,\n from: pos,\n to: pos + 2\n };\n }\n stack.push({ bracket: symbol, index: pos });\n continue;\n }\n if (!isCloseBracket(symbol)) {\n continue;\n }\n\n const expectedOpen = closeToOpen(symbol);\n const top = stack[stack.length - 1];\n if (top === undefined) {\n return {\n code: RSErrorCode.missingOpenBracket,\n from: pos,\n to: pos + 1,\n params: [symbol]\n };\n }\n\n if (top.bracket !== expectedOpen) {\n return {\n code: RSErrorCode.bracketMismatch,\n from: pos,\n to: pos + 1,\n params: [openToClose(top.bracket), symbol]\n };\n }\n\n stack.pop();\n }\n\n if (stack.length > 0) {\n const unclosed = stack[0];\n return {\n code: RSErrorCode.missingCloseBracket,\n from: unclosed.index,\n to: unclosed.index + 1,\n params: [unclosed.bracket]\n };\n }\n\n return null;\n}\n\nfunction isOpenBracket(symbol: string): symbol is OpenBracket {\n return symbol === '(' || symbol === '[' || symbol === '{';\n}\n\nfunction isCloseBracket(symbol: string): symbol is CloseBracket {\n return symbol === ')' || symbol === ']' || symbol === '}';\n}\n\nfunction openToClose(symbol: OpenBracket): CloseBracket {\n switch (symbol) {\n case '(':\n return ')';\n case '[':\n return ']';\n case '{':\n return '}';\n }\n}\n\nfunction closeToOpen(symbol: CloseBracket): OpenBracket {\n switch (symbol) {\n case ')':\n return '(';\n case ']':\n return '[';\n case '}':\n return '{';\n }\n}\n\nfunction isDoubleParenthesis(expression: string, pos: number): boolean {\n const isOpenDoubleParenthesis = expression[pos] === '(' && expression[pos + 1] === '(';\n if (!isOpenDoubleParenthesis) {\n return false;\n }\n\n const outerClose = findMatchingCloseBracket(expression, pos);\n const innerClose = findMatchingCloseBracket(expression, pos + 1);\n if (outerClose < 0 || innerClose < 0) {\n return false;\n }\n\n return outerClose === innerClose + 1;\n}\n\nfunction findMatchingCloseBracket(expression: string, openPos: number): number {\n if (expression[openPos] !== '(') {\n return -1;\n }\n\n const stack: OpenBracket[] = [];\n for (let index = openPos; index < expression.length; index++) {\n const symbol = expression[index];\n if (isOpenBracket(symbol)) {\n stack.push(symbol);\n continue;\n }\n if (!isCloseBracket(symbol)) {\n continue;\n }\n const top = stack.pop();\n if (top === undefined || top !== closeToOpen(symbol)) {\n return -1;\n }\n if (stack.length === 0) {\n return index;\n }\n }\n\n return -1;\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,oBACd,KACA,YACA,UACA,iBAA0B,OAC1B;CACA,MAAM,eAAe,qBAAqB,UAAU;CACpD,IAAI,iBAAiB,MAAM;EACzB,SAAS,YAAY;EACrB,IAAI,gBACF,cAAc,KAAK,aAAa,MAAM,aAAa,MAAM;CAE7D;CACA,MAAM,mBAAmB,iBAAiB;CAC1C,YAAY,MAAK,SAAQ,gBAAgB,MAAM,UAAU,gBAAgB,gBAAgB,CAAC;AAC5F;AAGA,SAAS,gBACP,MACA,UACA,gBACA,qBACA;CACA,IAAI,KAAK,WAAW,QAAQ,OAC1B;CAGF,SAAS,KAAK,QAAiB,MAAmB;EAChD,SAAS;GAAQ;GAAM,MAAM,OAAO;GAAM,IAAI,OAAO;EAAG,CAAC;EACzD,IAAI,gBACF,cAAc,QAAQ,IAAI;CAE9B;CAEA,MAAM,SAAS,KAAK;CACpB,IAAI,WAAW,MAAM;EACnB,IAAI,CAAC,qBACH,OAAO,KAAK,MAAM,YAAY,aAAa;EAE7C;CACF;CAEA,IAAI,OAAO,WAAA,GACT,OAAO,KAAK,QAAQ,YAAY,aAAa;CAG/C,IAAI,CAAC,qBACH,KAAK,KAAK,SAAS,KAAK,KAAK,SAAS,MAAM,YAAY,aAAa;AAEzE;AAUA,SAAS,qBAAqB,YAA+C;CAC3E,MAAM,QAAwB,CAAC;CAE/B,KAAK,IAAI,MAAM,GAAG,MAAM,WAAW,QAAQ,OAAO;EAChD,MAAM,SAAS,WAAW;EAC1B,IAAI,cAAc,MAAM,GAAG;GACzB,IAAI,oBAAoB,YAAY,GAAG,GACrC,OAAO;IACL,MAAM,YAAY;IAClB,MAAM;IACN,IAAI,MAAM;GACZ;GAEF,MAAM,KAAK;IAAE,SAAS;IAAQ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C;AAEA,SAAS,yBAAyB,YAAoB,SAAyB;CAC7E,IAAI,WAAW,aAAa,KAC1B,OAAO;CAGT,MAAM,QAAuB,CAAC;CAC9B,KAAK,IAAI,QAAQ,SAAS,QAAQ,WAAW,QAAQ,SAAS;EAC5D,MAAM,SAAS,WAAW;EAC1B,IAAI,cAAc,MAAM,GAAG;GACzB,MAAM,KAAK,MAAM;GACjB;EACF;EACA,IAAI,CAAC,eAAe,MAAM,GACxB;EAEF,MAAM,MAAM,MAAM,IAAI;EACtB,IAAI,QAAQ,UAAa,QAAQ,YAAY,MAAM,GACjD,OAAO;EAET,IAAI,MAAM,WAAW,GACnB,OAAO;CAEX;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"syntax-errors.js","names":[],"sources":["../../../src/rslang/parser/syntax-errors.ts"],"sourcesContent":["/**\n * Module: Syntactic errors reporting.\n */\n\nimport { type AstNode, visitAstDFS } from '../../parsing';\nimport { annotateError } from '../ast-annotations';\nimport { type ErrorReporter, RSErrorCode, type RSErrorDescription } from '../error';\n\nimport { Filter, Function, Predicate, Variable } from './parser.terms';\nimport { TokenID } from './token';\n\nexport function extractSyntaxErrors(\n ast: AstNode,\n expression: string,\n reporter: ErrorReporter,\n annotateErrors: boolean = false\n) {\n const collected: RSErrorDescription[] = [];\n const collect = (error: RSErrorDescription) => {\n collected.push(error);\n };\n\n const bracketError = extractBracketErrors(expression);\n if (bracketError !== null) {\n collect(bracketError);\n if (annotateErrors) {\n annotateError(ast, bracketError.code, bracketError.params);\n }\n }\n const hasBracketErrors = bracketError !== null;\n visitAstDFS(ast, node => extractInternal(node, expression, collect, annotateErrors, hasBracketErrors));\n\n for (const error of deduplicateErrors(collected)) {\n reporter(error);\n }\n}\n\n// ====== Internals =========\nfunction extractInternal(\n node: AstNode,\n expression: string,\n reporter: ErrorReporter,\n annotateErrors: boolean,\n ignoreUnknownErrors: boolean\n) {\n if (node.typeID !== TokenID.ERROR) {\n return;\n }\n\n function emit(target: AstNode, code: RSErrorCode, params?: readonly string[]) {\n reporter({ code: code, from: target.from, to: target.to, params });\n if (annotateErrors) {\n annotateError(target, code, params);\n }\n }\n\n const classified = classifyParseError(node, expression);\n if (classified !== null) {\n reporter(classified);\n if (annotateErrors) {\n annotateError(node, classified.code, classified.params);\n }\n return;\n }\n\n const parent = node.parent;\n if (parent === null) {\n if (!ignoreUnknownErrors) {\n return emit(node, RSErrorCode.unknownSyntax);\n }\n return;\n }\n\n if (parent.typeID === Variable) {\n return emit(parent, RSErrorCode.expectedLocal);\n }\n\n if (!ignoreUnknownErrors) {\n emit(node.from === node.to ? parent : node, RSErrorCode.unknownSyntax);\n }\n}\n\nfunction classifyParseError(node: AstNode, expression: string): RSErrorDescription | null {\n const filterParen = detectFilterParenMismatch(node, expression);\n if (filterParen !== null) {\n return filterParen;\n }\n\n return detectGlobalFuncWithoutArgs(node, expression);\n}\n\nfunction detectFilterParenMismatch(node: AstNode, expression: string): RSErrorDescription | null {\n const filterNode = findAncestor(node, isFilterNode) ?? findRelatedNode(node, isFilterNode);\n if (filterNode === null) {\n return null;\n }\n\n const nextChar = expression[filterNode.to];\n if (nextChar === '(') {\n return {\n code: RSErrorCode.invalidFilterSyntax,\n from: filterNode.from,\n to: filterNode.to + 1\n };\n }\n return null;\n}\n\nfunction detectGlobalFuncWithoutArgs(node: AstNode, expression: string): RSErrorDescription | null {\n const funcNode =\n findAncestor(node, n => isFunctionNode(n) || isPredicateNode(n)) ??\n findRelatedNode(node, n => isFunctionNode(n) || isPredicateNode(n));\n if (funcNode === null) {\n return null;\n }\n return classifyFuncWithoutArgs(funcNode, expression);\n}\n\nfunction findRelatedNode(node: AstNode, predicate: (target: AstNode) => boolean): AstNode | null {\n let current: AstNode | null = node.parent;\n while (current !== null) {\n for (const child of current.children) {\n if (predicate(child)) {\n return child;\n }\n }\n current = current.parent;\n }\n return null;\n}\n\nfunction classifyFuncWithoutArgs(funcNode: AstNode, expression: string): RSErrorDescription | null {\n const name = expression.slice(funcNode.from, funcNode.to);\n const rest = expression.slice(funcNode.to);\n\n if (!/^\\s*\\[/.test(rest)) {\n return {\n code: RSErrorCode.globalFuncWithoutArgs,\n from: funcNode.from,\n to: funcNode.to,\n params: [name]\n };\n }\n\n if (/^\\s*\\[\\s*\\]/.test(rest)) {\n return {\n code: RSErrorCode.globalFuncWithoutArgs,\n from: funcNode.from,\n to: funcNode.to,\n params: [name]\n };\n }\n\n const openBracket = /^\\s*\\[/.exec(rest);\n if (openBracket !== null) {\n const closeIdx = findMatchingCloseBracket(rest, openBracket[0].length - 1);\n if (closeIdx >= 0) {\n const inner = rest.slice(openBracket[0].length, closeIdx).trim();\n if (inner.length === 0) {\n return {\n code: RSErrorCode.globalFuncWithoutArgs,\n from: funcNode.from,\n to: funcNode.to,\n params: [name]\n };\n }\n }\n }\n\n return null;\n}\n\nfunction findAncestor(node: AstNode, predicate: (node: AstNode) => boolean): AstNode | null {\n let current: AstNode | null = node;\n while (current !== null) {\n if (predicate(current)) {\n return current;\n }\n current = current.parent;\n }\n return null;\n}\n\nfunction isFunctionNode(node: AstNode): boolean {\n return node.typeID === Function || node.typeID === TokenID.ID_FUNCTION;\n}\n\nfunction isPredicateNode(node: AstNode): boolean {\n return node.typeID === Predicate || node.typeID === TokenID.ID_PREDICATE;\n}\n\nfunction isFilterNode(node: AstNode): boolean {\n return node.typeID === Filter || node.typeID === TokenID.FILTER;\n}\n\nfunction findMatchingCloseBracket(expression: string, openPos: number): number {\n const open = expression[openPos];\n if (open !== '[') {\n return -1;\n }\n\n let depth = 0;\n for (let index = openPos; index < expression.length; index++) {\n const symbol = expression[index];\n if (symbol === '[') {\n depth++;\n } else if (symbol === ']') {\n depth--;\n if (depth === 0) {\n return index;\n }\n }\n }\n return -1;\n}\n\nfunction deduplicateErrors(errors: RSErrorDescription[]): RSErrorDescription[] {\n const result: RSErrorDescription[] = [];\n\n for (const error of errors) {\n const duplicate = result.some(\n existing => existing.code === error.code && existing.from === error.from && existing.to === error.to\n );\n if (duplicate) {\n continue;\n }\n\n if (error.code !== RSErrorCode.unknownSyntax) {\n for (let index = result.length - 1; index >= 0; index--) {\n if (result[index].code === RSErrorCode.unknownSyntax && rangesOverlap(error, result[index])) {\n result.splice(index, 1);\n }\n }\n }\n\n result.push(error);\n }\n\n const specific = result.filter(error => error.code !== RSErrorCode.unknownSyntax);\n return result.filter(\n error => error.code !== RSErrorCode.unknownSyntax || !specific.some(item => rangesOverlap(error, item))\n );\n}\n\nfunction rangesOverlap(a: RSErrorDescription, b: RSErrorDescription): boolean {\n return a.from < b.to && b.from < a.to;\n}\n\ntype OpenBracket = '(' | '[' | '{';\ntype CloseBracket = ')' | ']' | '}';\n\ninterface BracketFrame {\n bracket: OpenBracket;\n index: number;\n}\n\nfunction extractBracketErrors(expression: string): RSErrorDescription | null {\n const stack: BracketFrame[] = [];\n\n for (let pos = 0; pos < expression.length; pos++) {\n const symbol = expression[pos];\n if (isOpenBracket(symbol)) {\n if (isDoubleParenthesis(expression, pos)) {\n return {\n code: RSErrorCode.doubleParenthesis,\n from: pos,\n to: pos + 2\n };\n }\n stack.push({ bracket: symbol, index: pos });\n continue;\n }\n if (!isCloseBracket(symbol)) {\n continue;\n }\n\n const expectedOpen = closeToOpen(symbol);\n const top = stack[stack.length - 1];\n if (top === undefined) {\n return {\n code: RSErrorCode.missingOpenBracket,\n from: pos,\n to: pos + 1,\n params: [symbol]\n };\n }\n\n if (top.bracket !== expectedOpen) {\n return {\n code: RSErrorCode.bracketMismatch,\n from: pos,\n to: pos + 1,\n params: [openToClose(top.bracket), symbol]\n };\n }\n\n stack.pop();\n }\n\n if (stack.length > 0) {\n const unclosed = stack[0];\n return {\n code: RSErrorCode.missingCloseBracket,\n from: unclosed.index,\n to: unclosed.index + 1,\n params: [unclosed.bracket]\n };\n }\n\n return null;\n}\n\nfunction isOpenBracket(symbol: string): symbol is OpenBracket {\n return symbol === '(' || symbol === '[' || symbol === '{';\n}\n\nfunction isCloseBracket(symbol: string): symbol is CloseBracket {\n return symbol === ')' || symbol === ']' || symbol === '}';\n}\n\nfunction openToClose(symbol: OpenBracket): CloseBracket {\n switch (symbol) {\n case '(':\n return ')';\n case '[':\n return ']';\n case '{':\n return '}';\n }\n}\n\nfunction closeToOpen(symbol: CloseBracket): OpenBracket {\n switch (symbol) {\n case ')':\n return '(';\n case ']':\n return '[';\n case '}':\n return '{';\n }\n}\n\nfunction isDoubleParenthesis(expression: string, pos: number): boolean {\n const isOpenDoubleParenthesis = expression[pos] === '(' && expression[pos + 1] === '(';\n if (!isOpenDoubleParenthesis) {\n return false;\n }\n\n const outerClose = findMatchingCloseParen(expression, pos);\n const innerClose = findMatchingCloseParen(expression, pos + 1);\n if (outerClose < 0 || innerClose < 0) {\n return false;\n }\n\n return outerClose === innerClose + 1;\n}\n\nfunction findMatchingCloseParen(expression: string, openPos: number): number {\n if (expression[openPos] !== '(') {\n return -1;\n }\n\n const stack: OpenBracket[] = [];\n for (let index = openPos; index < expression.length; index++) {\n const symbol = expression[index];\n if (isOpenBracket(symbol)) {\n stack.push(symbol);\n continue;\n }\n if (!isCloseBracket(symbol)) {\n continue;\n }\n const top = stack.pop();\n if (top === undefined || top !== closeToOpen(symbol)) {\n return -1;\n }\n if (stack.length === 0) {\n return index;\n }\n }\n\n return -1;\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,oBACd,KACA,YACA,UACA,iBAA0B,OAC1B;CACA,MAAM,YAAkC,CAAC;CACzC,MAAM,WAAW,UAA8B;EAC7C,UAAU,KAAK,KAAK;CACtB;CAEA,MAAM,eAAe,qBAAqB,UAAU;CACpD,IAAI,iBAAiB,MAAM;EACzB,QAAQ,YAAY;EACpB,IAAI,gBACF,cAAc,KAAK,aAAa,MAAM,aAAa,MAAM;CAE7D;CACA,MAAM,mBAAmB,iBAAiB;CAC1C,YAAY,MAAK,SAAQ,gBAAgB,MAAM,YAAY,SAAS,gBAAgB,gBAAgB,CAAC;CAErG,KAAK,MAAM,SAAS,kBAAkB,SAAS,GAC7C,SAAS,KAA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,IAAI,EAD4B,WAAW,SAAS,OAAO,WAAW,MAAM,OAAO,MAEjF,OAAO;CAGT,MAAM,aAAa,uBAAuB,YAAY,GAAG;CACzD,MAAM,aAAa,uBAAuB,YAAY,MAAM,CAAC;CAC7D,IAAI,aAAa,KAAK,aAAa,GACjC,OAAO;CAGT,OAAO,eAAe,aAAa;AACrC;AAEA,SAAS,uBAAuB,YAAoB,SAAyB;CAC3E,IAAI,WAAW,aAAa,KAC1B,OAAO;CAGT,MAAM,QAAuB,CAAC;CAC9B,KAAK,IAAI,QAAQ,SAAS,QAAQ,WAAW,QAAQ,SAAS;EAC5D,MAAM,SAAS,WAAW;EAC1B,IAAI,cAAc,MAAM,GAAG;GACzB,MAAM,KAAK,MAAM;GACjB;EACF;EACA,IAAI,CAAC,eAAe,MAAM,GACxB;EAEF,MAAM,MAAM,MAAM,IAAI;EACtB,IAAI,QAAQ,UAAa,QAAQ,YAAY,MAAM,GACjD,OAAO;EAET,IAAI,MAAM,WAAW,GACnB,OAAO;CAEX;CAEA,OAAO;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RSLangAnalyzer, i as AnalysisOptions, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../../analyzer-
|
|
1
|
+
import { a as RSLangAnalyzer, i as AnalysisOptions, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../../analyzer-54lGGg13.js";
|
|
2
2
|
export { AnalysisBase, AnalysisFast, AnalysisFull, AnalysisOptions, RSLangAnalyzer };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
2
|
import { _ as TypeContext, f as ExpressionType } from "../../typification-Dk-fisgO.js";
|
|
3
|
-
import { t as ErrorReporter } from "../../error-
|
|
3
|
+
import { t as ErrorReporter } from "../../error-CxIs0A7Y.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/semantic/type-auditor.d.ts
|
|
6
6
|
/** Type auditor for AST type checking. */
|
|
@@ -54,6 +54,8 @@ declare class TypeAuditor {
|
|
|
54
54
|
private visitProjectSet;
|
|
55
55
|
private visitProjectTuple;
|
|
56
56
|
private visitFilter;
|
|
57
|
+
private expectedFilterArgumentLabel;
|
|
58
|
+
private reportFilterParameterError;
|
|
57
59
|
private visitReduce;
|
|
58
60
|
private visitArgumentsEnum;
|
|
59
61
|
private visitDeclarative;
|
|
@@ -200,6 +200,7 @@ var TypeAuditor = class TypeAuditor {
|
|
|
200
200
|
const alias = getNodeText(node);
|
|
201
201
|
const type = this.context.get(alias);
|
|
202
202
|
if (!type) return this.onError(RSErrorCode.globalNotTyped, node, [alias]);
|
|
203
|
+
if (type.typeID === TypeID.function || type.typeID === TypeID.predicate) return this.onError(RSErrorCode.globalFuncWithoutArgs, node, [alias]);
|
|
203
204
|
return type;
|
|
204
205
|
}
|
|
205
206
|
visitFunctionDefinition(node) {
|
|
@@ -443,40 +444,70 @@ var TypeAuditor = class TypeAuditor {
|
|
|
443
444
|
const operator = labelRSLangNode(node);
|
|
444
445
|
const indices = getNodeIndices(node);
|
|
445
446
|
const tupleParam = indices.length === node.children.length - 1;
|
|
446
|
-
if (!tupleParam && node.children.length > 2)
|
|
447
|
+
if (!tupleParam && node.children.length > 2) {
|
|
448
|
+
const extraParam = node.children[indices.length];
|
|
449
|
+
return this.onError(RSErrorCode.invalidFilterArity, extraParam ?? node, [
|
|
450
|
+
String(indices.length),
|
|
451
|
+
String(node.children.length - 1),
|
|
452
|
+
operator
|
|
453
|
+
]);
|
|
454
|
+
}
|
|
447
455
|
const argument = this.childTypification(node, node.children.length - 1);
|
|
448
456
|
if (argument === null) return null;
|
|
449
457
|
if (argument.typeID === TypeID.anyTypification || argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification) return EmptySetT;
|
|
450
|
-
|
|
458
|
+
const expectedArgument = this.expectedFilterArgumentLabel(indices);
|
|
459
|
+
if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.tuple) return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [
|
|
460
|
+
operator,
|
|
461
|
+
labelType(argument),
|
|
462
|
+
expectedArgument
|
|
463
|
+
]);
|
|
451
464
|
const argBase = debool(argument);
|
|
452
465
|
const bases = [];
|
|
453
466
|
for (const index of indices) {
|
|
454
467
|
const newBase = component(argBase, index);
|
|
455
|
-
if (newBase === null) return this.onError(RSErrorCode.
|
|
468
|
+
if (newBase === null) return this.onError(RSErrorCode.invalidFilterIndex, node.children[node.children.length - 1], [
|
|
469
|
+
operator,
|
|
470
|
+
labelType(argument),
|
|
471
|
+
String(index),
|
|
472
|
+
String(argBase.factors.length)
|
|
473
|
+
]);
|
|
456
474
|
bases.push(newBase);
|
|
457
475
|
}
|
|
458
476
|
if (tupleParam) for (let child = 0; child + 1 < node.children.length; child++) {
|
|
459
477
|
const param = this.childTypification(node, child);
|
|
460
478
|
if (param === null) return null;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
labelType(bool(bases[child])),
|
|
464
|
-
operator
|
|
465
|
-
]);
|
|
479
|
+
const expectedParam = bool(bases[child]);
|
|
480
|
+
if (param.typeID !== TypeID.collection || !checkCompatibility(bases[child], debool(param))) return this.reportFilterParameterError(node, child, param, expectedParam, operator);
|
|
466
481
|
}
|
|
467
482
|
else {
|
|
468
483
|
const param = this.childTypification(node, 0);
|
|
469
484
|
if (param === null) return null;
|
|
470
485
|
const paramType = param;
|
|
471
486
|
const expected = bool(tuple(bases));
|
|
472
|
-
if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) return this.
|
|
473
|
-
labelType(paramType),
|
|
474
|
-
labelType(expected),
|
|
475
|
-
operator
|
|
476
|
-
]);
|
|
487
|
+
if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) return this.reportFilterParameterError(node, 0, paramType, expected, operator);
|
|
477
488
|
}
|
|
478
489
|
return argument;
|
|
479
490
|
}
|
|
491
|
+
expectedFilterArgumentLabel(indices) {
|
|
492
|
+
const maxIndex = Math.max(...indices, 0);
|
|
493
|
+
if (maxIndex <= 1) return labelType(bool({ typeID: TypeID.anyTypification }));
|
|
494
|
+
const factors = [];
|
|
495
|
+
for (let index = 1; index <= maxIndex; index++) factors.push({ typeID: TypeID.anyTypification });
|
|
496
|
+
return labelType(bool(tuple(factors)));
|
|
497
|
+
}
|
|
498
|
+
reportFilterParameterError(node, childIndex, param, expected, operator) {
|
|
499
|
+
const wrapped = bool(param);
|
|
500
|
+
if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [
|
|
501
|
+
operator,
|
|
502
|
+
labelType(param),
|
|
503
|
+
labelType(expected)
|
|
504
|
+
]);
|
|
505
|
+
return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [
|
|
506
|
+
labelType(param),
|
|
507
|
+
labelType(expected),
|
|
508
|
+
operator
|
|
509
|
+
]);
|
|
510
|
+
}
|
|
480
511
|
visitReduce(node) {
|
|
481
512
|
const argument = this.childTypification(node, 0);
|
|
482
513
|
if (argument === null) return null;
|