@rsconcept/domain 1.4.6 → 1.5.1
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-54lGGg13.d.ts → analyzer-Bx7SOXWN.d.ts} +2 -2
- package/dist/{ast-annotations-C0eMySxt.d.ts → ast-annotations-DBZCQOsx.d.ts} +2 -2
- package/dist/{calculator-BQnE2gws.d.ts → calculator-Dwv_yn2r.d.ts} +2 -2
- package/dist/{error-CxIs0A7Y.d.ts → error-CB3HYTri.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 +9 -3
- package/dist/rslang/parser/syntax-errors.js +58 -33
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +1 -1
- package/dist/rslang/semantic/analyzer.js +1 -1
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.js +2 -6
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +1 -1
- package/package.json +1 -1
- package/src/rslang/error.ts +3 -0
- package/src/rslang/parser/parser.test.ts +20 -1
- package/src/rslang/parser/syntax-errors.ts +113 -48
- package/src/rslang/semantic/analyzer.ts +3 -1
- package/src/rslang/semantic/type-auditor.test.ts +32 -8
- package/src/rslang/semantic/type-auditor.ts +2 -3
|
@@ -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-CB3HYTri.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-Bx7SOXWN.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-CB3HYTri.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-DBZCQOsx.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-CB3HYTri.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-Dwv_yn2r.d.ts.map
|
|
@@ -29,6 +29,9 @@ declare const RSErrorCode: {
|
|
|
29
29
|
readonly missingOpenBracket: 33803;
|
|
30
30
|
readonly missingCloseBracket: 33804;
|
|
31
31
|
readonly invalidFilterSyntax: 33815;
|
|
32
|
+
readonly expectedFunctionBody: 33816;
|
|
33
|
+
readonly expectedExpressionBody: 33817;
|
|
34
|
+
readonly expectedLogicBody: 33818;
|
|
32
35
|
readonly expectedLocal: 33813;
|
|
33
36
|
readonly expectedType: 33814;
|
|
34
37
|
readonly localDoubleDeclare: 10241;
|
|
@@ -88,4 +91,4 @@ declare function getRSErrorPrefix(code: RSErrorCode): string;
|
|
|
88
91
|
declare function isCritical(code: RSErrorCode): boolean;
|
|
89
92
|
//#endregion
|
|
90
93
|
export { RSErrorInfo as a, RSErrorDescription as i, RSErrorClass as n, getRSErrorPrefix as o, RSErrorCode as r, isCritical as s, ErrorReporter as t };
|
|
91
|
-
//# sourceMappingURL=error-
|
|
94
|
+
//# sourceMappingURL=error-CB3HYTri.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-CB3HYTri.js";
|
|
13
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-DBZCQOsx.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-Dwv_yn2r.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-Bx7SOXWN.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-Dwv_yn2r.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-Bx7SOXWN.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-Bx7SOXWN.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-DBZCQOsx.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-CB3HYTri.js";
|
|
2
2
|
export { ErrorReporter, RSErrorClass, RSErrorCode, RSErrorDescription, RSErrorInfo, getRSErrorPrefix, isCritical };
|
package/dist/rslang/error.js
CHANGED
|
@@ -16,6 +16,9 @@ const RSErrorCode = {
|
|
|
16
16
|
missingOpenBracket: 33803,
|
|
17
17
|
missingCloseBracket: 33804,
|
|
18
18
|
invalidFilterSyntax: 33815,
|
|
19
|
+
expectedFunctionBody: 33816,
|
|
20
|
+
expectedExpressionBody: 33817,
|
|
21
|
+
expectedLogicBody: 33818,
|
|
19
22
|
expectedLocal: 33813,
|
|
20
23
|
expectedType: 33814,
|
|
21
24
|
localDoubleDeclare: 10241,
|
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 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 !== RSErrorCode.localDoubleDeclare && code !== RSErrorCode.localNotUsed;\n}\n"],"mappings":";;;AAGA,MAAa,eAAe;CAC1B,OAAO;CACP,QAAQ;C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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
|
+
{"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 expectedFunctionBody: 0x8418, // 33816\n expectedExpressionBody: 0x8419, // 33817\n expectedLogicBody: 0x841a, // 33818\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 !== 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,qBAAqB;CACrB,sBAAsB;CACtB,wBAAwB;CACxB,mBAAmB;CACnB,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,sBA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@
|
|
|
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-Dwv_yn2r.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-CB3HYTri.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-CB3HYTri.js";
|
|
3
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "../ast-annotations-DBZCQOsx.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-Dwv_yn2r.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-Bx7SOXWN.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,8 +1,14 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
|
-
import {
|
|
2
|
+
import { g as TypeClass } from "../../typification-Dk-fisgO.js";
|
|
3
|
+
import { t as ErrorReporter } from "../../error-CB3HYTri.js";
|
|
3
4
|
|
|
4
5
|
//#region src/rslang/parser/syntax-errors.d.ts
|
|
5
|
-
|
|
6
|
+
/** Options for syntax error extraction. */
|
|
7
|
+
interface SyntaxErrorOptions {
|
|
8
|
+
expected?: TypeClass;
|
|
9
|
+
}
|
|
10
|
+
/** Extracts syntax errors from an AST. */
|
|
11
|
+
declare function extractSyntaxErrors(ast: AstNode, expression: string, reporter: ErrorReporter, annotateErrors?: boolean, options?: SyntaxErrorOptions): void;
|
|
6
12
|
//#endregion
|
|
7
|
-
export { extractSyntaxErrors };
|
|
13
|
+
export { SyntaxErrorOptions, extractSyntaxErrors };
|
|
8
14
|
//# sourceMappingURL=syntax-errors.d.ts.map
|
|
@@ -3,40 +3,45 @@ import { RSErrorCode } from "../error.js";
|
|
|
3
3
|
import { visitAstDFS } from "../../parsing/ast.js";
|
|
4
4
|
import "../../parsing/index.js";
|
|
5
5
|
import { TokenID } from "./token.js";
|
|
6
|
+
import { TypeClass } from "../semantic/typification.js";
|
|
6
7
|
import "./parser.terms.js";
|
|
7
8
|
//#region src/rslang/parser/syntax-errors.ts
|
|
8
9
|
/**
|
|
9
10
|
* Module: Syntactic errors reporting.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
/** Extracts syntax errors from an AST. */
|
|
13
|
+
function extractSyntaxErrors(ast, expression, reporter, annotateErrors = false, options) {
|
|
12
14
|
const collected = [];
|
|
13
|
-
const
|
|
15
|
+
const annotationTargets = /* @__PURE__ */ new Map();
|
|
16
|
+
const collect = (error, target) => {
|
|
14
17
|
collected.push(error);
|
|
18
|
+
if (target !== void 0) annotationTargets.set(error, target);
|
|
15
19
|
};
|
|
16
20
|
const bracketError = extractBracketErrors(expression);
|
|
17
|
-
if (bracketError !== null)
|
|
18
|
-
collect(bracketError);
|
|
19
|
-
if (annotateErrors) annotateError(ast, bracketError.code, bracketError.params);
|
|
20
|
-
}
|
|
21
|
+
if (bracketError !== null) collect(bracketError, ast);
|
|
21
22
|
const hasBracketErrors = bracketError !== null;
|
|
22
|
-
visitAstDFS(ast, (node) => extractInternal(node, expression, collect,
|
|
23
|
-
for (const error of deduplicateErrors(collected))
|
|
23
|
+
visitAstDFS(ast, (node) => extractInternal(node, expression, collect, hasBracketErrors, options));
|
|
24
|
+
for (const error of deduplicateErrors(collected)) {
|
|
25
|
+
reporter(error);
|
|
26
|
+
if (annotateErrors) {
|
|
27
|
+
const target = annotationTargets.get(error);
|
|
28
|
+
if (target !== void 0) annotateError(target, error.code, error.params);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
|
-
function extractInternal(node, expression,
|
|
32
|
+
function extractInternal(node, expression, collect, ignoreUnknownErrors, options) {
|
|
26
33
|
if (node.typeID !== TokenID.ERROR) return;
|
|
27
34
|
function emit(target, code, params) {
|
|
28
|
-
|
|
35
|
+
collect({
|
|
29
36
|
code,
|
|
30
37
|
from: target.from,
|
|
31
38
|
to: target.to,
|
|
32
39
|
params
|
|
33
|
-
});
|
|
34
|
-
if (annotateErrors) annotateError(target, code, params);
|
|
40
|
+
}, target);
|
|
35
41
|
}
|
|
36
|
-
const classified = classifyParseError(node, expression);
|
|
42
|
+
const classified = classifyParseError(node, expression, options);
|
|
37
43
|
if (classified !== null) {
|
|
38
|
-
|
|
39
|
-
if (annotateErrors) annotateError(node, classified.code, classified.params);
|
|
44
|
+
collect(classified, node);
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
47
|
const parent = node.parent;
|
|
@@ -47,11 +52,39 @@ function extractInternal(node, expression, reporter, annotateErrors, ignoreUnkno
|
|
|
47
52
|
if (parent.typeID === 4) return emit(parent, RSErrorCode.expectedLocal);
|
|
48
53
|
if (!ignoreUnknownErrors) emit(node.from === node.to ? parent : node, RSErrorCode.unknownSyntax);
|
|
49
54
|
}
|
|
50
|
-
function classifyParseError(node, expression) {
|
|
55
|
+
function classifyParseError(node, expression, options) {
|
|
56
|
+
const incompleteFunctionDecl = detectIncompleteFunctionDecl(node, expression, options?.expected);
|
|
57
|
+
if (incompleteFunctionDecl !== null) return incompleteFunctionDecl;
|
|
51
58
|
const filterParen = detectFilterParenMismatch(node, expression);
|
|
52
59
|
if (filterParen !== null) return filterParen;
|
|
53
60
|
return detectGlobalFuncWithoutArgs(node, expression);
|
|
54
61
|
}
|
|
62
|
+
function detectIncompleteFunctionDecl(node, expression, expected) {
|
|
63
|
+
const funcDecl = findAncestor(node, isFunctionDeclNode);
|
|
64
|
+
if (funcDecl === null) return null;
|
|
65
|
+
const bodyChild = funcDecl.children[funcDecl.children.length - 1];
|
|
66
|
+
if (bodyChild?.typeID !== TokenID.ERROR || node !== bodyChild) return null;
|
|
67
|
+
const argsNode = funcDecl.children.find((child) => child.typeID === 77 || child.typeID === TokenID.NT_ARGUMENTS);
|
|
68
|
+
if (argsNode === void 0 || subtreeHasError(argsNode)) return null;
|
|
69
|
+
if (expression.slice(funcDecl.to).trim().length > 0) return null;
|
|
70
|
+
return {
|
|
71
|
+
code: incompleteFormalExpressionCode(expected),
|
|
72
|
+
from: bodyChild.from,
|
|
73
|
+
to: bodyChild.to
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function incompleteFormalExpressionCode(expected) {
|
|
77
|
+
switch (expected) {
|
|
78
|
+
case TypeClass.function: return RSErrorCode.expectedExpressionBody;
|
|
79
|
+
case TypeClass.predicate:
|
|
80
|
+
case TypeClass.logic: return RSErrorCode.expectedLogicBody;
|
|
81
|
+
default: return RSErrorCode.expectedFunctionBody;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function subtreeHasError(node) {
|
|
85
|
+
if (node.typeID === TokenID.ERROR) return true;
|
|
86
|
+
return node.children.some(subtreeHasError);
|
|
87
|
+
}
|
|
55
88
|
function detectFilterParenMismatch(node, expression) {
|
|
56
89
|
const filterNode = findAncestor(node, isFilterNode) ?? findRelatedNode(node, isFilterNode);
|
|
57
90
|
if (filterNode === null) return null;
|
|
@@ -78,29 +111,18 @@ function findRelatedNode(node, predicate) {
|
|
|
78
111
|
function classifyFuncWithoutArgs(funcNode, expression) {
|
|
79
112
|
const name = expression.slice(funcNode.from, funcNode.to);
|
|
80
113
|
const rest = expression.slice(funcNode.to);
|
|
81
|
-
|
|
82
|
-
code: RSErrorCode.globalFuncWithoutArgs,
|
|
83
|
-
from: funcNode.from,
|
|
84
|
-
to: funcNode.to,
|
|
85
|
-
params: [name]
|
|
86
|
-
};
|
|
87
|
-
if (/^\s*\[\s*\]/.test(rest)) return {
|
|
114
|
+
const withoutArgs = {
|
|
88
115
|
code: RSErrorCode.globalFuncWithoutArgs,
|
|
89
116
|
from: funcNode.from,
|
|
90
117
|
to: funcNode.to,
|
|
91
118
|
params: [name]
|
|
92
119
|
};
|
|
120
|
+
if (/^\s*$/.test(rest)) return withoutArgs;
|
|
93
121
|
const openBracket = /^\s*\[/.exec(rest);
|
|
94
|
-
if (openBracket
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
code: RSErrorCode.globalFuncWithoutArgs,
|
|
99
|
-
from: funcNode.from,
|
|
100
|
-
to: funcNode.to,
|
|
101
|
-
params: [name]
|
|
102
|
-
};
|
|
103
|
-
}
|
|
122
|
+
if (openBracket === null) return null;
|
|
123
|
+
const closeIdx = findMatchingCloseBracket(rest, openBracket[0].length - 1);
|
|
124
|
+
if (closeIdx >= 0) {
|
|
125
|
+
if (rest.slice(openBracket[0].length, closeIdx).trim().length === 0) return withoutArgs;
|
|
104
126
|
}
|
|
105
127
|
return null;
|
|
106
128
|
}
|
|
@@ -112,6 +134,9 @@ function findAncestor(node, predicate) {
|
|
|
112
134
|
}
|
|
113
135
|
return null;
|
|
114
136
|
}
|
|
137
|
+
function isFunctionDeclNode(node) {
|
|
138
|
+
return node.typeID === 76 || node.typeID === TokenID.NT_FUNC_DEFINITION;
|
|
139
|
+
}
|
|
115
140
|
function isFunctionNode(node) {
|
|
116
141
|
return node.typeID === 69 || node.typeID === TokenID.ID_FUNCTION;
|
|
117
142
|
}
|
|
@@ -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 { 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,iBAAi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CACtD,QAAQ,QAAR;EACE,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;CACX;AACF;AAEA,SAAS,oBAAoB,YAAoB,KAAsB;CAErE,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
|
+
{"version":3,"file":"syntax-errors.js","names":["TypeClassEnum"],"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';\nimport { type TypeClass, TypeClass as TypeClassEnum } from '../semantic/typification';\n\nimport { Arguments, Filter, Function, Function_decl, Predicate, Variable } from './parser.terms';\nimport { TokenID } from './token';\n\n/** Options for syntax error extraction. */\nexport interface SyntaxErrorOptions {\n expected?: TypeClass;\n}\n\n/** Extracts syntax errors from an AST. */\nexport function extractSyntaxErrors(\n ast: AstNode,\n expression: string,\n reporter: ErrorReporter,\n annotateErrors: boolean = false,\n options?: SyntaxErrorOptions\n) {\n const collected: RSErrorDescription[] = [];\n const annotationTargets = new Map<RSErrorDescription, AstNode>();\n const collect = (error: RSErrorDescription, target?: AstNode) => {\n collected.push(error);\n if (target !== undefined) {\n annotationTargets.set(error, target);\n }\n };\n\n const bracketError = extractBracketErrors(expression);\n if (bracketError !== null) {\n collect(bracketError, ast);\n }\n const hasBracketErrors = bracketError !== null;\n visitAstDFS(ast, node => extractInternal(node, expression, collect, hasBracketErrors, options));\n\n for (const error of deduplicateErrors(collected)) {\n reporter(error);\n if (annotateErrors) {\n const target = annotationTargets.get(error);\n if (target !== undefined) {\n annotateError(target, error.code, error.params);\n }\n }\n }\n}\n\n// ====== Internals =========\nfunction extractInternal(\n node: AstNode,\n expression: string,\n collect: (error: RSErrorDescription, target: AstNode) => void,\n ignoreUnknownErrors: boolean,\n options?: SyntaxErrorOptions\n) {\n if (node.typeID !== TokenID.ERROR) {\n return;\n }\n\n function emit(target: AstNode, code: RSErrorCode, params?: readonly string[]) {\n collect({ code: code, from: target.from, to: target.to, params }, target);\n }\n\n const classified = classifyParseError(node, expression, options);\n if (classified !== null) {\n collect(classified, node);\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(\n node: AstNode,\n expression: string,\n options?: SyntaxErrorOptions\n): RSErrorDescription | null {\n const incompleteFunctionDecl = detectIncompleteFunctionDecl(node, expression, options?.expected);\n if (incompleteFunctionDecl !== null) {\n return incompleteFunctionDecl;\n }\n\n const filterParen = detectFilterParenMismatch(node, expression);\n if (filterParen !== null) {\n return filterParen;\n }\n\n return detectGlobalFuncWithoutArgs(node, expression);\n}\n\nfunction detectIncompleteFunctionDecl(\n node: AstNode,\n expression: string,\n expected?: TypeClass\n): RSErrorDescription | null {\n const funcDecl = findAncestor(node, isFunctionDeclNode);\n if (funcDecl === null) {\n return null;\n }\n\n const bodyChild = funcDecl.children[funcDecl.children.length - 1];\n if (bodyChild?.typeID !== TokenID.ERROR || node !== bodyChild) {\n return null;\n }\n\n const argsNode = funcDecl.children.find(child => child.typeID === Arguments || child.typeID === TokenID.NT_ARGUMENTS);\n if (argsNode === undefined || subtreeHasError(argsNode)) {\n return null;\n }\n\n if (expression.slice(funcDecl.to).trim().length > 0) {\n return null;\n }\n\n return {\n code: incompleteFormalExpressionCode(expected),\n from: bodyChild.from,\n to: bodyChild.to\n };\n}\n\nfunction incompleteFormalExpressionCode(expected?: TypeClass): RSErrorCode {\n switch (expected) {\n case TypeClassEnum.function:\n return RSErrorCode.expectedExpressionBody;\n case TypeClassEnum.predicate:\n case TypeClassEnum.logic:\n return RSErrorCode.expectedLogicBody;\n default:\n return RSErrorCode.expectedFunctionBody;\n }\n}\n\nfunction subtreeHasError(node: AstNode): boolean {\n if (node.typeID === TokenID.ERROR) {\n return true;\n }\n return node.children.some(subtreeHasError);\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 const withoutArgs: RSErrorDescription = {\n code: RSErrorCode.globalFuncWithoutArgs,\n from: funcNode.from,\n to: funcNode.to,\n params: [name]\n };\n\n // Function with nothing (or only whitespace) after it is genuinely called without arguments.\n if (/^\\s*$/.test(rest)) {\n return withoutArgs;\n }\n\n // Anything other than a bracketed argument form (e.g. parentheses or braces) is malformed call\n // syntax: defer to the bracket/syntax error handling instead of reporting a missing-arguments error.\n const openBracket = /^\\s*\\[/.exec(rest);\n if (openBracket === null) {\n return null;\n }\n\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 withoutArgs;\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 isFunctionDeclNode(node: AstNode): boolean {\n return node.typeID === Function_decl || node.typeID === TokenID.NT_FUNC_DEFINITION;\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":";;;;;;;;;;;;AAkBA,SAAgB,oBACd,KACA,YACA,UACA,iBAA0B,OAC1B,SACA;CACA,MAAM,YAAkC,CAAC;CACzC,MAAM,oCAAoB,IAAI,IAAiC;CAC/D,MAAM,WAAW,OAA2B,WA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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-Bx7SOXWN.js";
|
|
2
2
|
export { AnalysisBase, AnalysisFast, AnalysisFull, AnalysisOptions, RSLangAnalyzer };
|
|
@@ -102,7 +102,7 @@ var RSLangAnalyzer = class {
|
|
|
102
102
|
}
|
|
103
103
|
const ast = this.parse(expression);
|
|
104
104
|
if (ast.hasError) {
|
|
105
|
-
extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false);
|
|
105
|
+
extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false, { expected: options?.expected });
|
|
106
106
|
return {
|
|
107
107
|
success: false,
|
|
108
108
|
type: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","names":["rslangParser"],"sources":["../../../src/rslang/semantic/analyzer.ts"],"sourcesContent":["import { type AstNode, buildTree } from '../../parsing';\nimport { annotateError } from '../ast-annotations';\nimport { RSErrorCode, type RSErrorDescription } from '../error';\nimport { normalizeAST } from '../parser/normalize';\nimport { parser as rslangParser } from '../parser/parser';\nimport { extractSyntaxErrors } from '../parser/syntax-errors';\nimport { TokenID } from '../parser/token';\n\nimport { TypeAuditor } from './type-auditor';\nimport {\n basic,\n bool,\n constant,\n debool,\n type ExpressionType,\n type TypeClass,\n type TypeContext,\n TypeID\n} from './typification';\nimport { getTypeClass } from './typification-api';\nimport { ValueAuditor } from './value-auditor';\nimport { ValueClass, type ValueClassContext } from './value-class';\n\nexport interface AnalysisBase {\n success: boolean;\n type: ExpressionType | null;\n valueClass: ValueClass | null;\n}\n\nexport interface AnalysisFast extends AnalysisBase {\n ast: AstNode | null;\n}\n\nexport interface AnalysisFull extends AnalysisBase {\n ast: AstNode | null;\n errors: RSErrorDescription[];\n}\n\nexport interface AnalysisOptions {\n expected?: TypeClass;\n isDomain?: boolean;\n annotateTypes?: boolean;\n annotateErrors?: boolean;\n}\n\nexport class RSLangAnalyzer {\n private typeContext: TypeContext = new Map<string, ExpressionType>();\n private valueContext: ValueClassContext = new Map<string, ValueClass>();\n private typeAuditor: TypeAuditor = new TypeAuditor(this.typeContext);\n private valueAuditor: ValueAuditor = new ValueAuditor(this.valueContext);\n\n public addBase(alias: string, isNumeric: boolean = false, valueClass: ValueClass = ValueClass.VALUE): void {\n if (isNumeric) {\n this.typeContext.set(alias, bool(constant(alias)));\n this.valueContext.set(alias, valueClass);\n } else {\n this.typeContext.set(alias, bool(basic(alias)));\n this.valueContext.set(alias, valueClass);\n }\n }\n\n public setGlobal(alias: string, type: ExpressionType | null, value: ValueClass | null): void {\n if (type) {\n this.typeContext.set(alias, type);\n }\n if (value) {\n this.valueContext.set(alias, value);\n }\n }\n\n public getType(alias: string): ExpressionType | null {\n return this.typeContext.get(alias) ?? null;\n }\n\n public checkFast(expression: string, options?: AnalysisOptions): AnalysisFast {\n if (expression.length === 0) {\n return { success: false, type: null, valueClass: null, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, ast: ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n return {\n success: true,\n type: type,\n valueClass: options?.isDomain ? ValueClass.VALUE : this.valueAuditor.run(ast),\n ast: ast\n };\n }\n\n public checkFull(expression: string, options?: AnalysisOptions): AnalysisFull {\n const errors: RSErrorDescription[] = [];\n const reporter = (error: RSErrorDescription) => {\n errors.push(error);\n };\n if (expression.length === 0) {\n reporter({ code: RSErrorCode.cstEmptyDerived, from: 0, to: 0 });\n return { success: false, type: null, valueClass: null, errors: errors, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false);\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false, reporter, options?.annotateErrors ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n reporter({ code: RSErrorCode.globalStructure, from: ast.from, to: ast.to });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.globalStructure);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, errors, ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n reporter({\n code: RSErrorCode.expectedType,\n from: ast.from,\n to: ast.to\n });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.expectedType);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n const valueClass = options?.isDomain\n ? ValueClass.VALUE\n : this.valueAuditor.run(ast, reporter, options?.annotateErrors ?? false);\n return { success: true, type, valueClass, errors, ast };\n }\n\n private parse(expression: string): AstNode {\n const tree = rslangParser.parse(expression);\n const ast = buildTree(tree.cursor());\n normalizeAST(ast, expression);\n return ast;\n }\n}\n\n// ======= Internals ========\nfunction isStructureDomain(node: AstNode): boolean {\n switch (node.typeID) {\n case TokenID.LIT_WHOLE_NUMBERS:\n case TokenID.ID_GLOBAL:\n case TokenID.BOOLEAN:\n case TokenID.DECART:\n case TokenID.NT_ENUMERATION:\n break;\n default:\n return false;\n }\n for (const child of node.children) {\n if (!isStructureDomain(child)) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,MAA4B;CAC1B,8BAAmC,IAAI,IAA4B;CACnE,+BAA0C,IAAI,IAAwB;CACtE,cAAmC,IAAI,YAAY,KAAK,WAAW;CACnE,eAAqC,IAAI,aAAa,KAAK,YAAY;CAEvE,QAAe,OAAe,YAAqB,OAAO,aAAyB,WAAW,OAAa;EACzG,IAAI,WAAW;GACb,KAAK,YAAY,IAAI,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC;GACjD,KAAK,aAAa,IAAI,OAAO,UAAU;EACzC,OAAO;GACL,KAAK,YAAY,IAAI,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC;GAC9C,KAAK,aAAa,IAAI,OAAO,UAAU;EACzC;CACF;CAEA,UAAiB,OAAe,MAA6B,OAAgC;EAC3F,IAAI,MACF,KAAK,YAAY,IAAI,OAAO,IAAI;EAElC,IAAI,OACF,KAAK,aAAa,IAAI,OAAO,KAAK;CAEtC;CAEA,QAAe,OAAsC;EACnD,OAAO,KAAK,YAAY,IAAI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,
|
|
1
|
+
{"version":3,"file":"analyzer.js","names":["rslangParser"],"sources":["../../../src/rslang/semantic/analyzer.ts"],"sourcesContent":["import { type AstNode, buildTree } from '../../parsing';\nimport { annotateError } from '../ast-annotations';\nimport { RSErrorCode, type RSErrorDescription } from '../error';\nimport { normalizeAST } from '../parser/normalize';\nimport { parser as rslangParser } from '../parser/parser';\nimport { extractSyntaxErrors } from '../parser/syntax-errors';\nimport { TokenID } from '../parser/token';\n\nimport { TypeAuditor } from './type-auditor';\nimport {\n basic,\n bool,\n constant,\n debool,\n type ExpressionType,\n type TypeClass,\n type TypeContext,\n TypeID\n} from './typification';\nimport { getTypeClass } from './typification-api';\nimport { ValueAuditor } from './value-auditor';\nimport { ValueClass, type ValueClassContext } from './value-class';\n\nexport interface AnalysisBase {\n success: boolean;\n type: ExpressionType | null;\n valueClass: ValueClass | null;\n}\n\nexport interface AnalysisFast extends AnalysisBase {\n ast: AstNode | null;\n}\n\nexport interface AnalysisFull extends AnalysisBase {\n ast: AstNode | null;\n errors: RSErrorDescription[];\n}\n\nexport interface AnalysisOptions {\n expected?: TypeClass;\n isDomain?: boolean;\n annotateTypes?: boolean;\n annotateErrors?: boolean;\n}\n\nexport class RSLangAnalyzer {\n private typeContext: TypeContext = new Map<string, ExpressionType>();\n private valueContext: ValueClassContext = new Map<string, ValueClass>();\n private typeAuditor: TypeAuditor = new TypeAuditor(this.typeContext);\n private valueAuditor: ValueAuditor = new ValueAuditor(this.valueContext);\n\n public addBase(alias: string, isNumeric: boolean = false, valueClass: ValueClass = ValueClass.VALUE): void {\n if (isNumeric) {\n this.typeContext.set(alias, bool(constant(alias)));\n this.valueContext.set(alias, valueClass);\n } else {\n this.typeContext.set(alias, bool(basic(alias)));\n this.valueContext.set(alias, valueClass);\n }\n }\n\n public setGlobal(alias: string, type: ExpressionType | null, value: ValueClass | null): void {\n if (type) {\n this.typeContext.set(alias, type);\n }\n if (value) {\n this.valueContext.set(alias, value);\n }\n }\n\n public getType(alias: string): ExpressionType | null {\n return this.typeContext.get(alias) ?? null;\n }\n\n public checkFast(expression: string, options?: AnalysisOptions): AnalysisFast {\n if (expression.length === 0) {\n return { success: false, type: null, valueClass: null, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, ast: ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n return {\n success: true,\n type: type,\n valueClass: options?.isDomain ? ValueClass.VALUE : this.valueAuditor.run(ast),\n ast: ast\n };\n }\n\n public checkFull(expression: string, options?: AnalysisOptions): AnalysisFull {\n const errors: RSErrorDescription[] = [];\n const reporter = (error: RSErrorDescription) => {\n errors.push(error);\n };\n if (expression.length === 0) {\n reporter({ code: RSErrorCode.cstEmptyDerived, from: 0, to: 0 });\n return { success: false, type: null, valueClass: null, errors: errors, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false, {\n expected: options?.expected\n });\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false, reporter, options?.annotateErrors ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n reporter({ code: RSErrorCode.globalStructure, from: ast.from, to: ast.to });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.globalStructure);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, errors, ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n reporter({\n code: RSErrorCode.expectedType,\n from: ast.from,\n to: ast.to\n });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.expectedType);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n const valueClass = options?.isDomain\n ? ValueClass.VALUE\n : this.valueAuditor.run(ast, reporter, options?.annotateErrors ?? false);\n return { success: true, type, valueClass, errors, ast };\n }\n\n private parse(expression: string): AstNode {\n const tree = rslangParser.parse(expression);\n const ast = buildTree(tree.cursor());\n normalizeAST(ast, expression);\n return ast;\n }\n}\n\n// ======= Internals ========\nfunction isStructureDomain(node: AstNode): boolean {\n switch (node.typeID) {\n case TokenID.LIT_WHOLE_NUMBERS:\n case TokenID.ID_GLOBAL:\n case TokenID.BOOLEAN:\n case TokenID.DECART:\n case TokenID.NT_ENUMERATION:\n break;\n default:\n return false;\n }\n for (const child of node.children) {\n if (!isStructureDomain(child)) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,MAA4B;CAC1B,8BAAmC,IAAI,IAA4B;CACnE,+BAA0C,IAAI,IAAwB;CACtE,cAAmC,IAAI,YAAY,KAAK,WAAW;CACnE,eAAqC,IAAI,aAAa,KAAK,YAAY;CAEvE,QAAe,OAAe,YAAqB,OAAO,aAAyB,WAAW,OAAa;EACzG,IAAI,WAAW;GACb,KAAK,YAAY,IAAI,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC;GACjD,KAAK,aAAa,IAAI,OAAO,UAAU;EACzC,OAAO;GACL,KAAK,YAAY,IAAI,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC;GAC9C,KAAK,aAAa,IAAI,OAAO,UAAU;EACzC;CACF;CAEA,UAAiB,OAAe,MAA6B,OAAgC;EAC3F,IAAI,MACF,KAAK,YAAY,IAAI,OAAO,IAAI;EAElC,IAAI,OACF,KAAK,aAAa,IAAI,OAAO,KAA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AC5B,OAAO;CACT;AACF;AAGA,SAAS,kBAAkB,MAAwB;CACjD,QAAQ,KAAK,QAAb;EACE,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ,gBACX;EACF,SACE,OAAO;CACX;CACA,KAAK,MAAM,SAAS,KAAK,UACvB,IAAI,CAAC,kBAAkB,KAAK,GAC1B,OAAO;CAGX,OAAO;AACT"}
|
|
@@ -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-CB3HYTri.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/semantic/type-auditor.d.ts
|
|
6
6
|
/** Type auditor for AST type checking. */
|
|
@@ -497,11 +497,7 @@ var TypeAuditor = class TypeAuditor {
|
|
|
497
497
|
}
|
|
498
498
|
reportFilterParameterError(node, childIndex, param, expected, operator) {
|
|
499
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
|
-
]);
|
|
500
|
+
if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [operator, labelType(param)]);
|
|
505
501
|
return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [
|
|
506
502
|
labelType(param),
|
|
507
503
|
labelType(expected),
|
|
@@ -588,7 +584,7 @@ var TypeAuditor = class TypeAuditor {
|
|
|
588
584
|
return false;
|
|
589
585
|
}
|
|
590
586
|
checkFuncArguments(node, alias, type) {
|
|
591
|
-
if (node.children.length - 1 !== type.args.length) return this.onError(RSErrorCode.invalidArgsArity, node
|
|
587
|
+
if (node.children.length - 1 !== type.args.length) return this.onError(RSErrorCode.invalidArgsArity, node, [String(type.args.length), String(node.children.length - 1)]);
|
|
592
588
|
const substitutes = /* @__PURE__ */ new Map();
|
|
593
589
|
for (let child = 1; child < node.children.length; child++) {
|
|
594
590
|
const childType = this.childTypification(node, child);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-auditor.js","names":[],"sources":["../../../src/rslang/semantic/type-auditor.ts"],"sourcesContent":["/**\n * Module: Type auditor for AST type checking.\n */\n\nimport { type AstNode, getNodeIndices, getNodeText } from '../../parsing';\nimport { annotateError, annotateType } from '../ast-annotations';\nimport { type ErrorReporter, RSErrorCode } from '../error';\nimport { labelRSLangNode, labelToken, labelType } from '../labels';\nimport { TokenID } from '../parser/token';\n\nimport {\n type Argument,\n bool,\n component,\n debool,\n type EchelonTuple,\n EmptySetT,\n type ExpressionType,\n IntegerT,\n isRadical,\n isTypification,\n LogicT,\n type Parametrized,\n tuple,\n type TypeContext,\n TypeID,\n type Typification\n} from './typification';\nimport {\n checkCompatibility,\n checkEquality,\n compareTemplated,\n hasGenerics,\n mergeTypifications,\n substituteBase\n} from './typification-api';\n\n/** Type auditor for AST type checking. */\nexport class TypeAuditor {\n private static readonly TYPE_DEDUCTION_DEPTH = 5;\n\n private context: TypeContext;\n private reporter?: ErrorReporter;\n private locals: LocalContext;\n private annotateTypes: boolean;\n private annotateErrors: boolean;\n\n constructor(context: TypeContext) {\n this.annotateTypes = false;\n this.annotateErrors = false;\n this.context = context;\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n public run(\n ast: AstNode,\n annotateTypes: boolean,\n reporter?: ErrorReporter,\n annotateErrors: boolean = false\n ): ExpressionType | null {\n if (ast.hasError) {\n return null;\n }\n this.annotateTypes = annotateTypes;\n this.annotateErrors = annotateErrors;\n this.reporter = reporter;\n this.clear();\n return this.dispatchVisit(ast);\n }\n\n private clear(): void {\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n private dispatchDeclare(node: AstNode, domain: Typification): boolean {\n const result = this.processDeclare(node, domain);\n if (result === true && this.annotateTypes) {\n annotateType(node, domain);\n }\n return result;\n }\n\n private processDeclare(node: AstNode, domain: Typification): boolean {\n switch (node.typeID) {\n case TokenID.ID_LOCAL:\n return this.declareLocal(node, domain);\n case TokenID.NT_TUPLE_DECL:\n return this.declareTuple(node, domain);\n case TokenID.NT_ENUM_DECL:\n return this.declareEnumeration(node, domain);\n }\n return false;\n }\n\n private declareLocal(node: AstNode, domain: Typification): boolean {\n return this.locals.pushLocal(node, domain);\n }\n\n private declareTuple(node: AstNode, domain: Typification): boolean {\n if (domain.typeID !== TypeID.tuple || domain.factors.length !== node.children.length) {\n this.onError(RSErrorCode.invalidCortegeDeclare, node.children[0]);\n return false;\n }\n for (let child = 0; child < node.children.length; child++) {\n if (!this.visitChildDeclaration(node, child, component(domain, child + 1)!)) {\n return false;\n }\n }\n return true;\n }\n\n private declareEnumeration(node: AstNode, domain: Typification): boolean {\n for (const child of node.children) {\n if (!this.dispatchDeclare(child, domain)) {\n return false;\n }\n }\n return true;\n }\n\n private dispatchVisit(node: AstNode): ExpressionType | null {\n const result = this.processVisit(node);\n if (result !== null && this.annotateTypes) {\n annotateType(node, result);\n }\n return result;\n }\n\n private processVisit(node: AstNode): ExpressionType | null {\n switch (node.typeID) {\n case TokenID.ID_GLOBAL:\n case TokenID.ID_FUNCTION:\n case TokenID.ID_PREDICATE:\n return this.visitGlobal(node);\n\n case TokenID.ID_LOCAL:\n return this.visitLocal(node);\n case TokenID.ID_RADICAL:\n return this.visitRadical(node);\n\n case TokenID.LIT_INTEGER:\n return IntegerT;\n case TokenID.LIT_WHOLE_NUMBERS:\n return bool(IntegerT);\n case TokenID.LIT_EMPTYSET:\n return this.visitEmptySet(node);\n\n case TokenID.NT_ARGUMENTS:\n return this.visitArgumentsEnum(node);\n case TokenID.NT_ARG_DECL:\n return this.visitArgument(node);\n\n case TokenID.PLUS:\n case TokenID.MINUS:\n case TokenID.MULTIPLY:\n return this.visitArithmetic(node);\n\n case TokenID.QUANTOR_UNIVERSAL:\n case TokenID.QUANTOR_EXISTS:\n return this.visitQuantifier(node);\n\n case TokenID.LOGIC_NOT:\n return this.visitNegation(node);\n\n case TokenID.LOGIC_AND:\n case TokenID.LOGIC_OR:\n case TokenID.LOGIC_IMPLICATION:\n case TokenID.LOGIC_EQUIVALENT:\n return this.visitLogicBinary(node);\n\n case TokenID.EQUAL:\n case TokenID.NOTEQUAL:\n return this.visitEquals(node);\n\n case TokenID.GREATER:\n case TokenID.LESSER:\n case TokenID.GREATER_OR_EQ:\n case TokenID.LESSER_OR_EQ:\n return this.visitIntegerPredicate(node);\n\n case TokenID.SET_IN:\n case TokenID.SET_NOT_IN:\n case TokenID.SUBSET:\n case TokenID.SUBSET_OR_EQ:\n case TokenID.NOT_SUBSET:\n return this.visitSetexprPredicate(node);\n\n case TokenID.DECART:\n return this.visitDecart(node);\n case TokenID.BOOLEAN:\n return this.visitBoolean(node);\n\n case TokenID.NT_TUPLE:\n return this.visitTuple(node);\n case TokenID.NT_ENUMERATION:\n return this.visitEnumeration(node);\n\n case TokenID.BIGPR:\n return this.visitProjectSet(node);\n case TokenID.SMALLPR:\n return this.visitProjectTuple(node);\n case TokenID.FILTER:\n return this.visitFilter(node);\n\n case TokenID.CARD:\n return this.visitCard(node);\n case TokenID.REDUCE:\n return this.visitReduce(node);\n case TokenID.BOOL:\n return this.visitBool(node);\n case TokenID.DEBOOL:\n return this.visitDebool(node);\n\n case TokenID.SET_UNION:\n case TokenID.SET_INTERSECTION:\n case TokenID.SET_MINUS:\n case TokenID.SET_SYMMETRIC_MINUS:\n return this.visitSetexprBinary(node);\n\n case TokenID.NT_FUNC_DEFINITION:\n return this.visitFunctionDefinition(node);\n\n case TokenID.NT_FUNC_CALL:\n return this.visitFunctionCall(node);\n\n case TokenID.ITERATE:\n return this.visitIterate(node);\n case TokenID.ASSIGN:\n return this.visitAssign(node);\n\n case TokenID.NT_DECLARATIVE_EXPR:\n return this.visitDeclarative(node);\n case TokenID.NT_IMPERATIVE_EXPR:\n return this.visitImperative(node);\n\n case TokenID.NT_RECURSIVE_FULL:\n case TokenID.NT_RECURSIVE_SHORT:\n return this.visitRecursion(node);\n }\n return null;\n }\n\n private onError(code: RSErrorCode, node: AstNode, params?: string[]): null {\n this.reporter?.({ code, from: node.from, to: node.to, params });\n if (this.annotateErrors) {\n annotateError(node, code, params);\n }\n return null;\n }\n\n private visitChild(node: AstNode, index: number): ExpressionType | null {\n if (index >= node.children.length) {\n return null;\n }\n return this.dispatchVisit(node.children[index]);\n }\n\n private visitChildDeclaration(node: AstNode, index: number, domain: Typification): boolean {\n if (index >= node.children.length) {\n return false;\n }\n if (!this.dispatchDeclare(node.children[index], domain)) {\n return false;\n }\n return true;\n }\n\n private visitAllAndReturn(node: AstNode, type: ExpressionType | null): ExpressionType | null {\n for (const child of node.children) {\n if (!this.dispatchVisit(child)) {\n return null;\n }\n }\n return type;\n }\n\n private childTypification(node: AstNode, index: number): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.expectedSetexpr, node.children[index], [labelType(result)]);\n return null;\n }\n return result as Typification;\n }\n\n private childLogic(node: AstNode, index: number): boolean {\n const result = this.visitChild(node, index);\n if (result === null) {\n return false;\n }\n if (result.typeID !== TypeID.logic) {\n this.onError(RSErrorCode.expectedLogic, node.children[index], [labelType(result)]);\n return false;\n }\n return true;\n }\n\n private childTypeDebool(\n node: AstNode,\n index: number,\n errorCode: RSErrorCode,\n operation?: string\n ): Typification | null {\n const result = this.childTypification(node, index);\n if (result === null) {\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n const params =\n errorCode === RSErrorCode.invalidTypeOperation && operation !== undefined\n ? [operation, labelType(result)]\n : [labelType(result)];\n this.onError(errorCode, node.children[index], params);\n return null;\n }\n return debool(result);\n }\n\n private childQuantifierDomain(node: AstNode, index: number, operator: string): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n return debool(result);\n }\n\n private visitLocal(node: AstNode): ExpressionType | null {\n return this.locals.getLocalType(node);\n }\n\n private visitGlobal(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n const type = this.context.get(alias);\n if (!type) {\n return this.onError(RSErrorCode.globalNotTyped, node, [alias]);\n }\n if (type.typeID === TypeID.function || type.typeID === TypeID.predicate) {\n return this.onError(RSErrorCode.globalFuncWithoutArgs, node, [alias]);\n }\n return type;\n }\n\n private visitFunctionDefinition(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n if (!this.visitChild(node, 0)) {\n return null;\n }\n\n const args: Argument[] = [];\n for (const local of this.locals.data) {\n if (local.level === 1) {\n args.push({ alias: local.alias, type: local.type });\n }\n }\n\n const result = this.visitChild(node, 1);\n if (result === null || result.typeID === TypeID.function || result.typeID === TypeID.predicate) {\n return null;\n }\n this.locals.endScope(node.children[1]);\n if (result.typeID === TypeID.logic) {\n return {\n typeID: TypeID.predicate,\n result: result,\n args: args\n };\n } else {\n return {\n typeID: TypeID.function,\n result: result,\n args: args\n };\n }\n }\n\n private visitFunctionCall(node: AstNode): ExpressionType | null {\n const funcName = getNodeText(node.children[0]);\n const funcType = this.context.get(funcName);\n if (funcType?.typeID !== TypeID.function && funcType?.typeID !== TypeID.predicate) {\n return this.onError(RSErrorCode.globalNotTyped, node.children[0], [funcName]);\n }\n if (this.annotateTypes) {\n annotateType(node.children[0], funcType);\n }\n\n const substitutes = this.checkFuncArguments(node, funcName, funcType);\n if (substitutes === null) {\n return null;\n }\n if (funcType.result.typeID === TypeID.logic) {\n return funcType.result;\n } else {\n const result = mangleRadicals(funcName, funcType.result);\n if (substitutes.size > 0) {\n substituteBase(result, substitutes);\n }\n return result;\n }\n }\n\n private visitRadical(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n if (!this.isInsideFuncArgument(node)) {\n return this.onError(RSErrorCode.radicalUsage, node, [alias]);\n }\n return bool({ typeID: TypeID.basic, baseID: alias });\n }\n\n private visitEmptySet(node: AstNode): ExpressionType | null {\n const invalidParents: TokenID[] = [\n TokenID.CARD,\n TokenID.DEBOOL,\n TokenID.SET_UNION,\n TokenID.SET_INTERSECTION,\n TokenID.SET_MINUS,\n TokenID.SET_SYMMETRIC_MINUS,\n TokenID.REDUCE,\n TokenID.BIGPR,\n TokenID.SMALLPR\n ];\n if (invalidParents.includes(node.parent?.typeID as TokenID)) {\n return this.onError(RSErrorCode.invalidEmptySetUsage, node);\n }\n return EmptySetT;\n }\n\n private visitArgument(node: AstNode): ExpressionType | null {\n const variable = node.children[0];\n if (variable.typeID === TokenID.NT_TUPLE_DECL) {\n return this.onError(RSErrorCode.invalidArgumentCortegeDeclare, variable);\n }\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return domain;\n }\n\n private visitCard(node: AstNode): ExpressionType | null {\n if (!this.childTypeDebool(node, 0, RSErrorCode.invalidCard)) {\n return null;\n }\n return IntegerT;\n }\n\n private visitArithmetic(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isArithmetic' in type1 && type1.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isArithmetic' in type2 && type2.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return result;\n }\n\n private visitIntegerPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isOrdered' in type1 && type1.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isOrdered' in type2 && type2.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitQuantifier(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const operator = labelRSLangNode(node);\n const domain = this.childQuantifierDomain(node, 1, operator);\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return LogicT;\n }\n\n private visitNegation(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0)) {\n return null;\n }\n return LogicT;\n }\n\n private visitLogicBinary(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0) || !this.childLogic(node, 1)) {\n return null;\n }\n return LogicT;\n }\n\n private visitEquals(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitSetexprPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n let type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n const isSubset = this.isSubset(node.typeID as TokenID);\n if (isSubset) {\n type2 = bool(type2);\n }\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n if (!checkCompatibility(type1, type2)) {\n if (isSubset) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(type1), labelType(type2), operator]);\n } else {\n return this.onError(RSErrorCode.invalidElementPredicate, node, [\n labelType(type1),\n operator,\n labelType(bool(type2))\n ]);\n }\n }\n return LogicT;\n }\n\n private visitDecart(node: AstNode): ExpressionType | null {\n const factors: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypeDebool(node, child, RSErrorCode.invalidDecart);\n if (type === null) {\n return null;\n } else {\n factors.push(type);\n }\n }\n return bool(tuple(factors));\n }\n\n private visitBoolean(node: AstNode): ExpressionType | null {\n const type = this.childTypeDebool(node, 0, RSErrorCode.invalidBoolean);\n if (type === null) {\n return null;\n }\n return bool(bool(type));\n }\n\n private visitTuple(node: AstNode): ExpressionType | null {\n const components: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypification(node, child);\n if (type === null) {\n return null;\n }\n components.push(type);\n }\n return tuple(components);\n }\n\n private visitEnumeration(node: AstNode): ExpressionType | null {\n let type: ExpressionType | null = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n\n const merge = mergeTypifications(type, childType);\n if (merge === null) {\n return this.onError(RSErrorCode.invalidEnumeration, node.children[child], [\n labelType(type),\n labelType(childType)\n ]);\n }\n type = merge;\n }\n return bool(type);\n }\n\n private visitBool(node: AstNode): ExpressionType | null {\n return this.visitEnumeration(node);\n }\n\n private visitDebool(node: AstNode): ExpressionType | null {\n return this.childTypeDebool(node, 0, RSErrorCode.invalidDebool);\n }\n\n private visitSetexprBinary(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypeDebool(node, 0, RSErrorCode.invalidTypeOperation, operator);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(bool(type1)), labelType(bool(type2)), operator]);\n }\n return bool(result);\n }\n\n private visitProjectSet(node: AstNode): ExpressionType | null {\n const argument = this.childTypeDebool(node, 0, RSErrorCode.invalidProjectionSet);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidProjectionSet, node.children[0], [\n labelRSLangNode(node),\n labelType(bool(argument))\n ]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.invalidProjectionSet, node.children[0], [\n labelRSLangNode(node),\n labelType(bool(argument))\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return bool(components[0]);\n } else {\n return bool(tuple(components));\n }\n }\n\n private visitProjectTuple(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return argument;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidProjectionTuple, node.children[0], [\n labelRSLangNode(node),\n labelType(argument)\n ]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.invalidProjectionTuple, node.children[0], [\n labelRSLangNode(node),\n labelType(argument)\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return components[0];\n } else {\n return tuple(components);\n }\n }\n\n private visitFilter(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const indices = getNodeIndices(node);\n const tupleParam = indices.length === node.children.length - 1;\n if (!tupleParam && node.children.length > 2) {\n const extraParam = node.children[indices.length];\n return this.onError(RSErrorCode.invalidFilterArity, extraParam ?? node, [\n String(indices.length),\n String(node.children.length - 1),\n operator\n ]);\n }\n\n const argument = this.childTypification(node, node.children.length - 1);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n const expectedArgument = this.expectedFilterArgumentLabel(indices);\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n expectedArgument\n ]);\n }\n\n const argBase = debool(argument) as EchelonTuple;\n const bases: Typification[] = [];\n for (const index of indices) {\n const newBase = component(argBase, index);\n if (newBase === null) {\n return this.onError(RSErrorCode.invalidFilterIndex, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n String(index),\n String(argBase.factors.length)\n ]);\n }\n bases.push(newBase);\n }\n\n if (tupleParam) {\n for (let child = 0; child + 1 < node.children.length; child++) {\n const param = this.childTypification(node, child);\n if (param === null) {\n return null;\n }\n const expectedParam = bool(bases[child]);\n if (param.typeID !== TypeID.collection || !checkCompatibility(bases[child], debool(param))) {\n return this.reportFilterParameterError(node, child, param, expectedParam, operator);\n }\n }\n } else {\n const param = this.childTypification(node, 0);\n if (param === null) {\n return null;\n }\n const paramType = param;\n const expected = bool(tuple(bases));\n if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) {\n return this.reportFilterParameterError(node, 0, paramType, expected, operator);\n }\n }\n return argument;\n }\n\n private expectedFilterArgumentLabel(indices: number[]): string {\n const maxIndex = Math.max(...indices, 0);\n if (maxIndex <= 1) {\n return labelType(bool({ typeID: TypeID.anyTypification }));\n }\n const factors: Typification[] = [];\n for (let index = 1; index <= maxIndex; index++) {\n factors.push({ typeID: TypeID.anyTypification });\n }\n return labelType(bool(tuple(factors)));\n }\n\n private reportFilterParameterError(\n node: AstNode,\n childIndex: number,\n param: Typification,\n expected: Typification,\n operator: string\n ): null {\n const wrapped = bool(param);\n if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) {\n return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [\n operator,\n labelType(param),\n labelType(expected)\n ]);\n }\n return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [\n labelType(param),\n labelType(expected),\n operator\n ]);\n }\n\n private visitReduce(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.collection) {\n return this.onError(RSErrorCode.invalidReduce, node.children[0], [labelType(argument)]);\n }\n return debool(argument);\n }\n\n private visitArgumentsEnum(node: AstNode): ExpressionType | null {\n return this.visitAllAndReturn(node, LogicT);\n }\n\n private visitDeclarative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const domain = this.childTypeDebool(\n node,\n 1,\n RSErrorCode.invalidTypeOperation,\n labelToken(TokenID.NT_DECLARATIVE_EXPR)\n );\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return bool(domain);\n }\n\n private visitImperative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n for (let child = 1; child < node.children.length; child++) {\n if (!this.childLogic(node, child)) {\n return null;\n }\n }\n\n const type = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n\n this.locals.endScope(node);\n return bool(type);\n }\n\n private visitIterate(node: AstNode): ExpressionType | null {\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitAssign(node: AstNode): ExpressionType | null {\n const domain = this.childTypification(node, 1);\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitRecursion(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const initType = this.childTypification(node, 1);\n if (initType === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, initType)) {\n return null;\n }\n\n const isFull = node.typeID === TokenID.NT_RECURSIVE_FULL;\n const iterationIndex = isFull ? 3 : 2;\n\n let iterationValue = this.childTypification(node, iterationIndex);\n if (iterationValue === null) {\n return null;\n }\n if (!checkCompatibility(iterationValue, initType)) {\n return this.onError(RSErrorCode.typesNotEqual, node.children[iterationIndex], [\n labelType(iterationValue),\n labelType(initType),\n labelToken(node.typeID as TokenID)\n ]);\n }\n\n if (hasGenerics(initType)) {\n for (let retries = TypeAuditor.TYPE_DEDUCTION_DEPTH; retries > 0; retries--) {\n this.locals.endScope(node);\n this.locals.clearUnused();\n this.locals.startScope();\n if (!this.visitChildDeclaration(node, 0, iterationValue)) {\n return null;\n }\n const newIteration = this.childTypification(node, iterationIndex);\n if (newIteration === null) {\n return null;\n }\n if (checkEquality(newIteration, iterationValue)) {\n break;\n }\n iterationValue = newIteration;\n }\n }\n\n if (isFull) {\n if (!this.childLogic(node, 2)) {\n return null;\n }\n }\n\n this.locals.endScope(node);\n return iterationValue;\n }\n\n private isSubset(token: TokenID): boolean {\n return token === TokenID.SUBSET || token === TokenID.SUBSET_OR_EQ || token === TokenID.NOT_SUBSET;\n }\n\n private isInsideFuncArgument(node: AstNode): boolean {\n while (node.parent && node.parent !== node) {\n if (node.typeID === TokenID.NT_ARGUMENTS) return true;\n node = node.parent;\n }\n return false;\n }\n\n private checkFuncArguments(node: AstNode, alias: string, type: Parametrized): Map<string, Typification> | null {\n if (node.children.length - 1 !== type.args.length) {\n return this.onError(RSErrorCode.invalidArgsArity, node.children[1], [\n String(type.args.length),\n String(node.children.length - 1)\n ]);\n }\n\n const substitutes = new Map<string, Typification>();\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n const argType = mangleRadicals(alias, type.args[child - 1].type);\n if (!compareTemplated(substitutes, argType, childType)) {\n this.onError(RSErrorCode.invalidArgumentType, node.children[child], [\n `${type.args[child - 1].alias}∈${labelType(argType)}`,\n labelType(childType)\n ]);\n return null;\n }\n }\n return substitutes;\n }\n}\n\n// ========= Internals ========\nfunction mangleRadicals(funcName: string, type: Typification): Typification {\n switch (type.typeID) {\n default:\n throw new Error(`Unexpected type for ${funcName}: ${JSON.stringify(type)}`);\n case TypeID.anyTypification:\n case TypeID.integer:\n return type;\n case TypeID.basic: {\n if (isRadical(type.baseID)) {\n return {\n typeID: type.typeID,\n baseID: type.baseID + funcName\n };\n }\n return type;\n }\n case TypeID.collection: {\n return {\n typeID: type.typeID,\n base: mangleRadicals(funcName, debool(type))\n };\n }\n case TypeID.tuple: {\n const factors: Typification[] = [];\n for (let index = 1; index <= type.factors.length; ++index) {\n factors.push(mangleRadicals(funcName, component(type, index)!));\n }\n return {\n typeID: type.typeID,\n factors: factors\n };\n }\n }\n}\n\n/** Local variable data. */\ninterface LocalData {\n alias: string;\n level: number;\n useCount: number;\n type: Typification;\n}\n\n/** Local variables context. */\nclass LocalContext {\n private onError: (code: RSErrorCode, node: AstNode, params: string[]) => null;\n\n public data: LocalData[] = [];\n\n constructor(onError: (code: RSErrorCode, node: AstNode, params: string[]) => null) {\n this.onError = onError;\n }\n\n startScope(): void {\n for (const local of this.data) {\n if (local.level > 0) {\n local.level = local.level + 1;\n }\n }\n }\n\n endScope(node: AstNode, skipUnused: boolean = false): void {\n for (const local of this.data) {\n local.level--;\n if (!skipUnused && local.level === 0 && local.useCount === 0) {\n this.onError(RSErrorCode.localNotUsed, node, [local.alias]);\n }\n }\n }\n\n clearUnused(): void {\n this.data = this.data.filter(data => data.level > 0);\n }\n\n pushLocal(node: AstNode, type: Typification): boolean {\n const alias = getNodeText(node);\n const existing = this.data.find(data => data.alias === alias);\n if (existing) {\n if (existing.level > 0) {\n this.onError(RSErrorCode.localShadowing, node, [alias]);\n return false;\n } else {\n this.onError(RSErrorCode.localDoubleDeclare, node, [alias]);\n const index = this.data.indexOf(existing);\n if (index !== -1) {\n this.data.splice(index, 1);\n }\n }\n }\n this.data.push({ alias, type, level: 1, useCount: 0 });\n return true;\n }\n\n getLocalType(node: AstNode): Typification | null {\n const alias = getNodeText(node);\n const local = this.data.find(data => data.alias === alias);\n if (local === undefined) {\n this.onError(RSErrorCode.localUndeclared, node, [alias]);\n return null;\n } else if (local.level < 1) {\n this.onError(RSErrorCode.localOutOfScope, node, [alias]);\n return null;\n } else {\n local.useCount++;\n return local.type;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,IAAa,cAAb,MAAa,YAAY;CACvB,OAAwB,uBAAuB;CAE/C;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAsB;EAChC,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,UAAU;EACf,KAAK,SAAS,IAAI,aAAa,KAAK,QAAQ,KAAK,IAAI,CAAC;CACxD;CAEA,IACE,KACA,eACA,UACA,iBAA0B,OACH;EACvB,IAAI,IAAI,UACN,OAAO;EAET,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,WAAW;EAChB,KAAK,MAAM;EACX,OAAO,KAAK,cAAc,GAAG;CAC/B;CA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AQ,YAAY,iBAAiB,MAAM,CAAC,KAAK,CAAC;GACvD,OAAO;EACT,OAAO,IAAI,MAAM,QAAQ,GAAG;GAC1B,KAAK,QAAQ,YAAY,iBAAiB,MAAM,CAAC,KAAK,CAAC;GACvD,OAAO;EACT,OAAO;GACL,MAAM;GACN,OAAO,MAAM;EACf;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"type-auditor.js","names":[],"sources":["../../../src/rslang/semantic/type-auditor.ts"],"sourcesContent":["/**\n * Module: Type auditor for AST type checking.\n */\n\nimport { type AstNode, getNodeIndices, getNodeText } from '../../parsing';\nimport { annotateError, annotateType } from '../ast-annotations';\nimport { type ErrorReporter, RSErrorCode } from '../error';\nimport { labelRSLangNode, labelToken, labelType } from '../labels';\nimport { TokenID } from '../parser/token';\n\nimport {\n type Argument,\n bool,\n component,\n debool,\n type EchelonTuple,\n EmptySetT,\n type ExpressionType,\n IntegerT,\n isRadical,\n isTypification,\n LogicT,\n type Parametrized,\n tuple,\n type TypeContext,\n TypeID,\n type Typification\n} from './typification';\nimport {\n checkCompatibility,\n checkEquality,\n compareTemplated,\n hasGenerics,\n mergeTypifications,\n substituteBase\n} from './typification-api';\n\n/** Type auditor for AST type checking. */\nexport class TypeAuditor {\n private static readonly TYPE_DEDUCTION_DEPTH = 5;\n\n private context: TypeContext;\n private reporter?: ErrorReporter;\n private locals: LocalContext;\n private annotateTypes: boolean;\n private annotateErrors: boolean;\n\n constructor(context: TypeContext) {\n this.annotateTypes = false;\n this.annotateErrors = false;\n this.context = context;\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n public run(\n ast: AstNode,\n annotateTypes: boolean,\n reporter?: ErrorReporter,\n annotateErrors: boolean = false\n ): ExpressionType | null {\n if (ast.hasError) {\n return null;\n }\n this.annotateTypes = annotateTypes;\n this.annotateErrors = annotateErrors;\n this.reporter = reporter;\n this.clear();\n return this.dispatchVisit(ast);\n }\n\n private clear(): void {\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n private dispatchDeclare(node: AstNode, domain: Typification): boolean {\n const result = this.processDeclare(node, domain);\n if (result === true && this.annotateTypes) {\n annotateType(node, domain);\n }\n return result;\n }\n\n private processDeclare(node: AstNode, domain: Typification): boolean {\n switch (node.typeID) {\n case TokenID.ID_LOCAL:\n return this.declareLocal(node, domain);\n case TokenID.NT_TUPLE_DECL:\n return this.declareTuple(node, domain);\n case TokenID.NT_ENUM_DECL:\n return this.declareEnumeration(node, domain);\n }\n return false;\n }\n\n private declareLocal(node: AstNode, domain: Typification): boolean {\n return this.locals.pushLocal(node, domain);\n }\n\n private declareTuple(node: AstNode, domain: Typification): boolean {\n if (domain.typeID !== TypeID.tuple || domain.factors.length !== node.children.length) {\n this.onError(RSErrorCode.invalidCortegeDeclare, node.children[0]);\n return false;\n }\n for (let child = 0; child < node.children.length; child++) {\n if (!this.visitChildDeclaration(node, child, component(domain, child + 1)!)) {\n return false;\n }\n }\n return true;\n }\n\n private declareEnumeration(node: AstNode, domain: Typification): boolean {\n for (const child of node.children) {\n if (!this.dispatchDeclare(child, domain)) {\n return false;\n }\n }\n return true;\n }\n\n private dispatchVisit(node: AstNode): ExpressionType | null {\n const result = this.processVisit(node);\n if (result !== null && this.annotateTypes) {\n annotateType(node, result);\n }\n return result;\n }\n\n private processVisit(node: AstNode): ExpressionType | null {\n switch (node.typeID) {\n case TokenID.ID_GLOBAL:\n case TokenID.ID_FUNCTION:\n case TokenID.ID_PREDICATE:\n return this.visitGlobal(node);\n\n case TokenID.ID_LOCAL:\n return this.visitLocal(node);\n case TokenID.ID_RADICAL:\n return this.visitRadical(node);\n\n case TokenID.LIT_INTEGER:\n return IntegerT;\n case TokenID.LIT_WHOLE_NUMBERS:\n return bool(IntegerT);\n case TokenID.LIT_EMPTYSET:\n return this.visitEmptySet(node);\n\n case TokenID.NT_ARGUMENTS:\n return this.visitArgumentsEnum(node);\n case TokenID.NT_ARG_DECL:\n return this.visitArgument(node);\n\n case TokenID.PLUS:\n case TokenID.MINUS:\n case TokenID.MULTIPLY:\n return this.visitArithmetic(node);\n\n case TokenID.QUANTOR_UNIVERSAL:\n case TokenID.QUANTOR_EXISTS:\n return this.visitQuantifier(node);\n\n case TokenID.LOGIC_NOT:\n return this.visitNegation(node);\n\n case TokenID.LOGIC_AND:\n case TokenID.LOGIC_OR:\n case TokenID.LOGIC_IMPLICATION:\n case TokenID.LOGIC_EQUIVALENT:\n return this.visitLogicBinary(node);\n\n case TokenID.EQUAL:\n case TokenID.NOTEQUAL:\n return this.visitEquals(node);\n\n case TokenID.GREATER:\n case TokenID.LESSER:\n case TokenID.GREATER_OR_EQ:\n case TokenID.LESSER_OR_EQ:\n return this.visitIntegerPredicate(node);\n\n case TokenID.SET_IN:\n case TokenID.SET_NOT_IN:\n case TokenID.SUBSET:\n case TokenID.SUBSET_OR_EQ:\n case TokenID.NOT_SUBSET:\n return this.visitSetexprPredicate(node);\n\n case TokenID.DECART:\n return this.visitDecart(node);\n case TokenID.BOOLEAN:\n return this.visitBoolean(node);\n\n case TokenID.NT_TUPLE:\n return this.visitTuple(node);\n case TokenID.NT_ENUMERATION:\n return this.visitEnumeration(node);\n\n case TokenID.BIGPR:\n return this.visitProjectSet(node);\n case TokenID.SMALLPR:\n return this.visitProjectTuple(node);\n case TokenID.FILTER:\n return this.visitFilter(node);\n\n case TokenID.CARD:\n return this.visitCard(node);\n case TokenID.REDUCE:\n return this.visitReduce(node);\n case TokenID.BOOL:\n return this.visitBool(node);\n case TokenID.DEBOOL:\n return this.visitDebool(node);\n\n case TokenID.SET_UNION:\n case TokenID.SET_INTERSECTION:\n case TokenID.SET_MINUS:\n case TokenID.SET_SYMMETRIC_MINUS:\n return this.visitSetexprBinary(node);\n\n case TokenID.NT_FUNC_DEFINITION:\n return this.visitFunctionDefinition(node);\n\n case TokenID.NT_FUNC_CALL:\n return this.visitFunctionCall(node);\n\n case TokenID.ITERATE:\n return this.visitIterate(node);\n case TokenID.ASSIGN:\n return this.visitAssign(node);\n\n case TokenID.NT_DECLARATIVE_EXPR:\n return this.visitDeclarative(node);\n case TokenID.NT_IMPERATIVE_EXPR:\n return this.visitImperative(node);\n\n case TokenID.NT_RECURSIVE_FULL:\n case TokenID.NT_RECURSIVE_SHORT:\n return this.visitRecursion(node);\n }\n return null;\n }\n\n private onError(code: RSErrorCode, node: AstNode, params?: string[]): null {\n this.reporter?.({ code, from: node.from, to: node.to, params });\n if (this.annotateErrors) {\n annotateError(node, code, params);\n }\n return null;\n }\n\n private visitChild(node: AstNode, index: number): ExpressionType | null {\n if (index >= node.children.length) {\n return null;\n }\n return this.dispatchVisit(node.children[index]);\n }\n\n private visitChildDeclaration(node: AstNode, index: number, domain: Typification): boolean {\n if (index >= node.children.length) {\n return false;\n }\n if (!this.dispatchDeclare(node.children[index], domain)) {\n return false;\n }\n return true;\n }\n\n private visitAllAndReturn(node: AstNode, type: ExpressionType | null): ExpressionType | null {\n for (const child of node.children) {\n if (!this.dispatchVisit(child)) {\n return null;\n }\n }\n return type;\n }\n\n private childTypification(node: AstNode, index: number): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.expectedSetexpr, node.children[index], [labelType(result)]);\n return null;\n }\n return result as Typification;\n }\n\n private childLogic(node: AstNode, index: number): boolean {\n const result = this.visitChild(node, index);\n if (result === null) {\n return false;\n }\n if (result.typeID !== TypeID.logic) {\n this.onError(RSErrorCode.expectedLogic, node.children[index], [labelType(result)]);\n return false;\n }\n return true;\n }\n\n private childTypeDebool(\n node: AstNode,\n index: number,\n errorCode: RSErrorCode,\n operation?: string\n ): Typification | null {\n const result = this.childTypification(node, index);\n if (result === null) {\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n const params =\n errorCode === RSErrorCode.invalidTypeOperation && operation !== undefined\n ? [operation, labelType(result)]\n : [labelType(result)];\n this.onError(errorCode, node.children[index], params);\n return null;\n }\n return debool(result);\n }\n\n private childQuantifierDomain(node: AstNode, index: number, operator: string): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n return debool(result);\n }\n\n private visitLocal(node: AstNode): ExpressionType | null {\n return this.locals.getLocalType(node);\n }\n\n private visitGlobal(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n const type = this.context.get(alias);\n if (!type) {\n return this.onError(RSErrorCode.globalNotTyped, node, [alias]);\n }\n if (type.typeID === TypeID.function || type.typeID === TypeID.predicate) {\n return this.onError(RSErrorCode.globalFuncWithoutArgs, node, [alias]);\n }\n return type;\n }\n\n private visitFunctionDefinition(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n if (!this.visitChild(node, 0)) {\n return null;\n }\n\n const args: Argument[] = [];\n for (const local of this.locals.data) {\n if (local.level === 1) {\n args.push({ alias: local.alias, type: local.type });\n }\n }\n\n const result = this.visitChild(node, 1);\n if (result === null || result.typeID === TypeID.function || result.typeID === TypeID.predicate) {\n return null;\n }\n this.locals.endScope(node.children[1]);\n if (result.typeID === TypeID.logic) {\n return {\n typeID: TypeID.predicate,\n result: result,\n args: args\n };\n } else {\n return {\n typeID: TypeID.function,\n result: result,\n args: args\n };\n }\n }\n\n private visitFunctionCall(node: AstNode): ExpressionType | null {\n const funcName = getNodeText(node.children[0]);\n const funcType = this.context.get(funcName);\n if (funcType?.typeID !== TypeID.function && funcType?.typeID !== TypeID.predicate) {\n return this.onError(RSErrorCode.globalNotTyped, node.children[0], [funcName]);\n }\n if (this.annotateTypes) {\n annotateType(node.children[0], funcType);\n }\n\n const substitutes = this.checkFuncArguments(node, funcName, funcType);\n if (substitutes === null) {\n return null;\n }\n if (funcType.result.typeID === TypeID.logic) {\n return funcType.result;\n } else {\n const result = mangleRadicals(funcName, funcType.result);\n if (substitutes.size > 0) {\n substituteBase(result, substitutes);\n }\n return result;\n }\n }\n\n private visitRadical(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n if (!this.isInsideFuncArgument(node)) {\n return this.onError(RSErrorCode.radicalUsage, node, [alias]);\n }\n return bool({ typeID: TypeID.basic, baseID: alias });\n }\n\n private visitEmptySet(node: AstNode): ExpressionType | null {\n const invalidParents: TokenID[] = [\n TokenID.CARD,\n TokenID.DEBOOL,\n TokenID.SET_UNION,\n TokenID.SET_INTERSECTION,\n TokenID.SET_MINUS,\n TokenID.SET_SYMMETRIC_MINUS,\n TokenID.REDUCE,\n TokenID.BIGPR,\n TokenID.SMALLPR\n ];\n if (invalidParents.includes(node.parent?.typeID as TokenID)) {\n return this.onError(RSErrorCode.invalidEmptySetUsage, node);\n }\n return EmptySetT;\n }\n\n private visitArgument(node: AstNode): ExpressionType | null {\n const variable = node.children[0];\n if (variable.typeID === TokenID.NT_TUPLE_DECL) {\n return this.onError(RSErrorCode.invalidArgumentCortegeDeclare, variable);\n }\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return domain;\n }\n\n private visitCard(node: AstNode): ExpressionType | null {\n if (!this.childTypeDebool(node, 0, RSErrorCode.invalidCard)) {\n return null;\n }\n return IntegerT;\n }\n\n private visitArithmetic(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isArithmetic' in type1 && type1.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isArithmetic' in type2 && type2.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return result;\n }\n\n private visitIntegerPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isOrdered' in type1 && type1.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isOrdered' in type2 && type2.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitQuantifier(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const operator = labelRSLangNode(node);\n const domain = this.childQuantifierDomain(node, 1, operator);\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return LogicT;\n }\n\n private visitNegation(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0)) {\n return null;\n }\n return LogicT;\n }\n\n private visitLogicBinary(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0) || !this.childLogic(node, 1)) {\n return null;\n }\n return LogicT;\n }\n\n private visitEquals(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitSetexprPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n let type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n const isSubset = this.isSubset(node.typeID as TokenID);\n if (isSubset) {\n type2 = bool(type2);\n }\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n if (!checkCompatibility(type1, type2)) {\n if (isSubset) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(type1), labelType(type2), operator]);\n } else {\n return this.onError(RSErrorCode.invalidElementPredicate, node, [\n labelType(type1),\n operator,\n labelType(bool(type2))\n ]);\n }\n }\n return LogicT;\n }\n\n private visitDecart(node: AstNode): ExpressionType | null {\n const factors: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypeDebool(node, child, RSErrorCode.invalidDecart);\n if (type === null) {\n return null;\n } else {\n factors.push(type);\n }\n }\n return bool(tuple(factors));\n }\n\n private visitBoolean(node: AstNode): ExpressionType | null {\n const type = this.childTypeDebool(node, 0, RSErrorCode.invalidBoolean);\n if (type === null) {\n return null;\n }\n return bool(bool(type));\n }\n\n private visitTuple(node: AstNode): ExpressionType | null {\n const components: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypification(node, child);\n if (type === null) {\n return null;\n }\n components.push(type);\n }\n return tuple(components);\n }\n\n private visitEnumeration(node: AstNode): ExpressionType | null {\n let type: ExpressionType | null = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n\n const merge = mergeTypifications(type, childType);\n if (merge === null) {\n return this.onError(RSErrorCode.invalidEnumeration, node.children[child], [\n labelType(type),\n labelType(childType)\n ]);\n }\n type = merge;\n }\n return bool(type);\n }\n\n private visitBool(node: AstNode): ExpressionType | null {\n return this.visitEnumeration(node);\n }\n\n private visitDebool(node: AstNode): ExpressionType | null {\n return this.childTypeDebool(node, 0, RSErrorCode.invalidDebool);\n }\n\n private visitSetexprBinary(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypeDebool(node, 0, RSErrorCode.invalidTypeOperation, operator);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(bool(type1)), labelType(bool(type2)), operator]);\n }\n return bool(result);\n }\n\n private visitProjectSet(node: AstNode): ExpressionType | null {\n const argument = this.childTypeDebool(node, 0, RSErrorCode.invalidProjectionSet);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidProjectionSet, node.children[0], [\n labelRSLangNode(node),\n labelType(bool(argument))\n ]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.invalidProjectionSet, node.children[0], [\n labelRSLangNode(node),\n labelType(bool(argument))\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return bool(components[0]);\n } else {\n return bool(tuple(components));\n }\n }\n\n private visitProjectTuple(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return argument;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidProjectionTuple, node.children[0], [\n labelRSLangNode(node),\n labelType(argument)\n ]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.invalidProjectionTuple, node.children[0], [\n labelRSLangNode(node),\n labelType(argument)\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return components[0];\n } else {\n return tuple(components);\n }\n }\n\n private visitFilter(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const indices = getNodeIndices(node);\n const tupleParam = indices.length === node.children.length - 1;\n if (!tupleParam && node.children.length > 2) {\n const extraParam = node.children[indices.length];\n return this.onError(RSErrorCode.invalidFilterArity, extraParam ?? node, [\n String(indices.length),\n String(node.children.length - 1),\n operator\n ]);\n }\n\n const argument = this.childTypification(node, node.children.length - 1);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n const expectedArgument = this.expectedFilterArgumentLabel(indices);\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n expectedArgument\n ]);\n }\n\n const argBase = debool(argument) as EchelonTuple;\n const bases: Typification[] = [];\n for (const index of indices) {\n const newBase = component(argBase, index);\n if (newBase === null) {\n return this.onError(RSErrorCode.invalidFilterIndex, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n String(index),\n String(argBase.factors.length)\n ]);\n }\n bases.push(newBase);\n }\n\n if (tupleParam) {\n for (let child = 0; child + 1 < node.children.length; child++) {\n const param = this.childTypification(node, child);\n if (param === null) {\n return null;\n }\n const expectedParam = bool(bases[child]);\n if (param.typeID !== TypeID.collection || !checkCompatibility(bases[child], debool(param))) {\n return this.reportFilterParameterError(node, child, param, expectedParam, operator);\n }\n }\n } else {\n const param = this.childTypification(node, 0);\n if (param === null) {\n return null;\n }\n const paramType = param;\n const expected = bool(tuple(bases));\n if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) {\n return this.reportFilterParameterError(node, 0, paramType, expected, operator);\n }\n }\n return argument;\n }\n\n private expectedFilterArgumentLabel(indices: number[]): string {\n const maxIndex = Math.max(...indices, 0);\n if (maxIndex <= 1) {\n return labelType(bool({ typeID: TypeID.anyTypification }));\n }\n const factors: Typification[] = [];\n for (let index = 1; index <= maxIndex; index++) {\n factors.push({ typeID: TypeID.anyTypification });\n }\n return labelType(bool(tuple(factors)));\n }\n\n private reportFilterParameterError(\n node: AstNode,\n childIndex: number,\n param: Typification,\n expected: Typification,\n operator: string\n ): null {\n const wrapped = bool(param);\n if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) {\n return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [\n operator,\n labelType(param)\n ]);\n }\n return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [\n labelType(param),\n labelType(expected),\n operator\n ]);\n }\n\n private visitReduce(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.collection) {\n return this.onError(RSErrorCode.invalidReduce, node.children[0], [labelType(argument)]);\n }\n return debool(argument);\n }\n\n private visitArgumentsEnum(node: AstNode): ExpressionType | null {\n return this.visitAllAndReturn(node, LogicT);\n }\n\n private visitDeclarative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const domain = this.childTypeDebool(\n node,\n 1,\n RSErrorCode.invalidTypeOperation,\n labelToken(TokenID.NT_DECLARATIVE_EXPR)\n );\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return bool(domain);\n }\n\n private visitImperative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n for (let child = 1; child < node.children.length; child++) {\n if (!this.childLogic(node, child)) {\n return null;\n }\n }\n\n const type = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n\n this.locals.endScope(node);\n return bool(type);\n }\n\n private visitIterate(node: AstNode): ExpressionType | null {\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitAssign(node: AstNode): ExpressionType | null {\n const domain = this.childTypification(node, 1);\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitRecursion(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const initType = this.childTypification(node, 1);\n if (initType === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, initType)) {\n return null;\n }\n\n const isFull = node.typeID === TokenID.NT_RECURSIVE_FULL;\n const iterationIndex = isFull ? 3 : 2;\n\n let iterationValue = this.childTypification(node, iterationIndex);\n if (iterationValue === null) {\n return null;\n }\n if (!checkCompatibility(iterationValue, initType)) {\n return this.onError(RSErrorCode.typesNotEqual, node.children[iterationIndex], [\n labelType(iterationValue),\n labelType(initType),\n labelToken(node.typeID as TokenID)\n ]);\n }\n\n if (hasGenerics(initType)) {\n for (let retries = TypeAuditor.TYPE_DEDUCTION_DEPTH; retries > 0; retries--) {\n this.locals.endScope(node);\n this.locals.clearUnused();\n this.locals.startScope();\n if (!this.visitChildDeclaration(node, 0, iterationValue)) {\n return null;\n }\n const newIteration = this.childTypification(node, iterationIndex);\n if (newIteration === null) {\n return null;\n }\n if (checkEquality(newIteration, iterationValue)) {\n break;\n }\n iterationValue = newIteration;\n }\n }\n\n if (isFull) {\n if (!this.childLogic(node, 2)) {\n return null;\n }\n }\n\n this.locals.endScope(node);\n return iterationValue;\n }\n\n private isSubset(token: TokenID): boolean {\n return token === TokenID.SUBSET || token === TokenID.SUBSET_OR_EQ || token === TokenID.NOT_SUBSET;\n }\n\n private isInsideFuncArgument(node: AstNode): boolean {\n while (node.parent && node.parent !== node) {\n if (node.typeID === TokenID.NT_ARGUMENTS) return true;\n node = node.parent;\n }\n return false;\n }\n\n private checkFuncArguments(node: AstNode, alias: string, type: Parametrized): Map<string, Typification> | null {\n if (node.children.length - 1 !== type.args.length) {\n return this.onError(RSErrorCode.invalidArgsArity, node, [\n String(type.args.length),\n String(node.children.length - 1)\n ]);\n }\n\n const substitutes = new Map<string, Typification>();\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n const argType = mangleRadicals(alias, type.args[child - 1].type);\n if (!compareTemplated(substitutes, argType, childType)) {\n this.onError(RSErrorCode.invalidArgumentType, node.children[child], [\n `${type.args[child - 1].alias}∈${labelType(argType)}`,\n labelType(childType)\n ]);\n return null;\n }\n }\n return substitutes;\n }\n}\n\n// ========= Internals ========\nfunction mangleRadicals(funcName: string, type: Typification): Typification {\n switch (type.typeID) {\n default:\n throw new Error(`Unexpected type for ${funcName}: ${JSON.stringify(type)}`);\n case TypeID.anyTypification:\n case TypeID.integer:\n return type;\n case TypeID.basic: {\n if (isRadical(type.baseID)) {\n return {\n typeID: type.typeID,\n baseID: type.baseID + funcName\n };\n }\n return type;\n }\n case TypeID.collection: {\n return {\n typeID: type.typeID,\n base: mangleRadicals(funcName, debool(type))\n };\n }\n case TypeID.tuple: {\n const factors: Typification[] = [];\n for (let index = 1; index <= type.factors.length; ++index) {\n factors.push(mangleRadicals(funcName, component(type, index)!));\n }\n return {\n typeID: type.typeID,\n factors: factors\n };\n }\n }\n}\n\n/** Local variable data. */\ninterface LocalData {\n alias: string;\n level: number;\n useCount: number;\n type: Typification;\n}\n\n/** Local variables context. */\nclass LocalContext {\n private onError: (code: RSErrorCode, node: AstNode, params: string[]) => null;\n\n public data: LocalData[] = [];\n\n constructor(onError: (code: RSErrorCode, node: AstNode, params: string[]) => null) {\n this.onError = onError;\n }\n\n startScope(): void {\n for (const local of this.data) {\n if (local.level > 0) {\n local.level = local.level + 1;\n }\n }\n }\n\n endScope(node: AstNode, skipUnused: boolean = false): void {\n for (const local of this.data) {\n local.level--;\n if (!skipUnused && local.level === 0 && local.useCount === 0) {\n this.onError(RSErrorCode.localNotUsed, node, [local.alias]);\n }\n }\n }\n\n clearUnused(): void {\n this.data = this.data.filter(data => data.level > 0);\n }\n\n pushLocal(node: AstNode, type: Typification): boolean {\n const alias = getNodeText(node);\n const existing = this.data.find(data => data.alias === alias);\n if (existing) {\n if (existing.level > 0) {\n this.onError(RSErrorCode.localShadowing, node, [alias]);\n return false;\n } else {\n this.onError(RSErrorCode.localDoubleDeclare, node, [alias]);\n const index = this.data.indexOf(existing);\n if (index !== -1) {\n this.data.splice(index, 1);\n }\n }\n }\n this.data.push({ alias, type, level: 1, useCount: 0 });\n return true;\n }\n\n getLocalType(node: AstNode): Typification | null {\n const alias = getNodeText(node);\n const local = this.data.find(data => data.alias === alias);\n if (local === undefined) {\n this.onError(RSErrorCode.localUndeclared, node, [alias]);\n return null;\n } else if (local.level < 1) {\n this.onError(RSErrorCode.localOutOfScope, node, [alias]);\n return null;\n } else {\n local.useCount++;\n return local.type;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,IAAa,cAAb,MAAa,YAAY;CACvB,OAAwB,uBAAuB;CAE/C;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAsB;EAChC,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,UAAU;EACf,KAAK,SAAS,IAAI,aAAa,KAAK,QAAQ,KAAK,IAAI,CAAC;CACxD;CAEA,IACE,KACA,eACA,UACA,iBAA0B,OACH;EACvB,IAAI,IAAI,UACN,OAAO;EAET,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,WAAW;EAChB,KAAK,MAAM;EACX,OAAO,KAAK,cAAc,GAAG;CAC/B;CAEA,QAAsB;EACpB,KAAK,SAAS,IAAI,aAAa,KAAK,QAAQ,KAAK,IAAI,CAAC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AK,QAAQ,YAAY,iBAAiB,MAAM,CAAC,KAAK,CAAC;GACvD,OAAO;EACT,OAAO;GACL,MAAM;GACN,OAAO,MAAM;EACf;CACF;AACF"}
|
|
@@ -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-CB3HYTri.js";
|
|
3
3
|
import { n as ValueClassContext, t as ValueClass } from "../../value-class-CNI-lqXJ.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/semantic/value-auditor.d.ts
|
package/package.json
CHANGED
package/src/rslang/error.ts
CHANGED
|
@@ -33,6 +33,9 @@ export const RSErrorCode = {
|
|
|
33
33
|
missingOpenBracket: 0x840b, // 33803
|
|
34
34
|
missingCloseBracket: 0x840c, // 33804
|
|
35
35
|
invalidFilterSyntax: 0x8417, // 33815
|
|
36
|
+
expectedFunctionBody: 0x8418, // 33816
|
|
37
|
+
expectedExpressionBody: 0x8419, // 33817
|
|
38
|
+
expectedLogicBody: 0x841a, // 33818
|
|
36
39
|
expectedLocal: 0x8415, // 33813
|
|
37
40
|
expectedType: 0x8416, // 33814
|
|
38
41
|
|
|
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import { buildTree, printTree } from '../../parsing';
|
|
4
4
|
import { RSErrorCode, type RSErrorDescription } from '../error';
|
|
5
|
+
import { TypeClass } from '../semantic/typification';
|
|
5
6
|
|
|
6
7
|
import { parser } from './parser';
|
|
7
8
|
import { extractSyntaxErrors } from './syntax-errors';
|
|
@@ -81,9 +82,15 @@ const testErrorData = [
|
|
|
81
82
|
['F1', { code: RSErrorCode.globalFuncWithoutArgs, from: 0, to: 2, params: ['F1'] }],
|
|
82
83
|
['P1', { code: RSErrorCode.globalFuncWithoutArgs, from: 0, to: 2, params: ['P1'] }],
|
|
83
84
|
['F1[]', { code: RSErrorCode.globalFuncWithoutArgs, from: 0, to: 2, params: ['F1'] }],
|
|
84
|
-
['Fi1(S1)', { code: RSErrorCode.invalidFilterSyntax, from: 0, to: 4 }]
|
|
85
|
+
['Fi1(S1)', { code: RSErrorCode.invalidFilterSyntax, from: 0, to: 4 }],
|
|
86
|
+
['[α∈ℬ(X1×X1)]', { code: RSErrorCode.expectedFunctionBody, from: 12, to: 12 }]
|
|
85
87
|
];
|
|
86
88
|
|
|
89
|
+
const testIncompleteFormalData = [
|
|
90
|
+
['[α∈ℬ(X1×X1)]', TypeClass.function, RSErrorCode.expectedExpressionBody],
|
|
91
|
+
['[σ∈S1]', TypeClass.predicate, RSErrorCode.expectedLogicBody]
|
|
92
|
+
] as const;
|
|
93
|
+
|
|
87
94
|
describe('Testing RSParser correct inputs', () => {
|
|
88
95
|
testSuccess.forEach(([input, expectedTree]) => {
|
|
89
96
|
it(`Parse "${input}"`, () => {
|
|
@@ -115,6 +122,18 @@ describe('Testing RSParser error data', () => {
|
|
|
115
122
|
});
|
|
116
123
|
});
|
|
117
124
|
|
|
125
|
+
testIncompleteFormalData.forEach(([input, expected, code]) => {
|
|
126
|
+
it(`Parse incomplete formal "${input}" for ${expected}`, () => {
|
|
127
|
+
const tree = parser.parse(input);
|
|
128
|
+
const ast = buildTree(tree.cursor());
|
|
129
|
+
const errors: RSErrorDescription[] = [];
|
|
130
|
+
extractSyntaxErrors(ast, input, error => errors.push(error), false, { expected });
|
|
131
|
+
expect(errors.length).toBe(1);
|
|
132
|
+
expect(errors[0].code).toBe(code);
|
|
133
|
+
expect(errors[0].from).toBe(errors[0].to);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
118
137
|
it('Quantor expressions', () => {
|
|
119
138
|
const input = '∀X1∈X1 (1=1)';
|
|
120
139
|
const tree = parser.parse(input);
|
|
@@ -5,33 +5,48 @@
|
|
|
5
5
|
import { type AstNode, visitAstDFS } from '../../parsing';
|
|
6
6
|
import { annotateError } from '../ast-annotations';
|
|
7
7
|
import { type ErrorReporter, RSErrorCode, type RSErrorDescription } from '../error';
|
|
8
|
+
import { type TypeClass, TypeClass as TypeClassEnum } from '../semantic/typification';
|
|
8
9
|
|
|
9
|
-
import { Filter, Function, Predicate, Variable } from './parser.terms';
|
|
10
|
+
import { Arguments, Filter, Function, Function_decl, Predicate, Variable } from './parser.terms';
|
|
10
11
|
import { TokenID } from './token';
|
|
11
12
|
|
|
13
|
+
/** Options for syntax error extraction. */
|
|
14
|
+
export interface SyntaxErrorOptions {
|
|
15
|
+
expected?: TypeClass;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Extracts syntax errors from an AST. */
|
|
12
19
|
export function extractSyntaxErrors(
|
|
13
20
|
ast: AstNode,
|
|
14
21
|
expression: string,
|
|
15
22
|
reporter: ErrorReporter,
|
|
16
|
-
annotateErrors: boolean = false
|
|
23
|
+
annotateErrors: boolean = false,
|
|
24
|
+
options?: SyntaxErrorOptions
|
|
17
25
|
) {
|
|
18
26
|
const collected: RSErrorDescription[] = [];
|
|
19
|
-
const
|
|
27
|
+
const annotationTargets = new Map<RSErrorDescription, AstNode>();
|
|
28
|
+
const collect = (error: RSErrorDescription, target?: AstNode) => {
|
|
20
29
|
collected.push(error);
|
|
30
|
+
if (target !== undefined) {
|
|
31
|
+
annotationTargets.set(error, target);
|
|
32
|
+
}
|
|
21
33
|
};
|
|
22
34
|
|
|
23
35
|
const bracketError = extractBracketErrors(expression);
|
|
24
36
|
if (bracketError !== null) {
|
|
25
|
-
collect(bracketError);
|
|
26
|
-
if (annotateErrors) {
|
|
27
|
-
annotateError(ast, bracketError.code, bracketError.params);
|
|
28
|
-
}
|
|
37
|
+
collect(bracketError, ast);
|
|
29
38
|
}
|
|
30
39
|
const hasBracketErrors = bracketError !== null;
|
|
31
|
-
visitAstDFS(ast, node => extractInternal(node, expression, collect,
|
|
40
|
+
visitAstDFS(ast, node => extractInternal(node, expression, collect, hasBracketErrors, options));
|
|
32
41
|
|
|
33
42
|
for (const error of deduplicateErrors(collected)) {
|
|
34
43
|
reporter(error);
|
|
44
|
+
if (annotateErrors) {
|
|
45
|
+
const target = annotationTargets.get(error);
|
|
46
|
+
if (target !== undefined) {
|
|
47
|
+
annotateError(target, error.code, error.params);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
35
50
|
}
|
|
36
51
|
}
|
|
37
52
|
|
|
@@ -39,27 +54,21 @@ export function extractSyntaxErrors(
|
|
|
39
54
|
function extractInternal(
|
|
40
55
|
node: AstNode,
|
|
41
56
|
expression: string,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
collect: (error: RSErrorDescription, target: AstNode) => void,
|
|
58
|
+
ignoreUnknownErrors: boolean,
|
|
59
|
+
options?: SyntaxErrorOptions
|
|
45
60
|
) {
|
|
46
61
|
if (node.typeID !== TokenID.ERROR) {
|
|
47
62
|
return;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
function emit(target: AstNode, code: RSErrorCode, params?: readonly string[]) {
|
|
51
|
-
|
|
52
|
-
if (annotateErrors) {
|
|
53
|
-
annotateError(target, code, params);
|
|
54
|
-
}
|
|
66
|
+
collect({ code: code, from: target.from, to: target.to, params }, target);
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
const classified = classifyParseError(node, expression);
|
|
69
|
+
const classified = classifyParseError(node, expression, options);
|
|
58
70
|
if (classified !== null) {
|
|
59
|
-
|
|
60
|
-
if (annotateErrors) {
|
|
61
|
-
annotateError(node, classified.code, classified.params);
|
|
62
|
-
}
|
|
71
|
+
collect(classified, node);
|
|
63
72
|
return;
|
|
64
73
|
}
|
|
65
74
|
|
|
@@ -80,7 +89,16 @@ function extractInternal(
|
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
function classifyParseError(
|
|
92
|
+
function classifyParseError(
|
|
93
|
+
node: AstNode,
|
|
94
|
+
expression: string,
|
|
95
|
+
options?: SyntaxErrorOptions
|
|
96
|
+
): RSErrorDescription | null {
|
|
97
|
+
const incompleteFunctionDecl = detectIncompleteFunctionDecl(node, expression, options?.expected);
|
|
98
|
+
if (incompleteFunctionDecl !== null) {
|
|
99
|
+
return incompleteFunctionDecl;
|
|
100
|
+
}
|
|
101
|
+
|
|
84
102
|
const filterParen = detectFilterParenMismatch(node, expression);
|
|
85
103
|
if (filterParen !== null) {
|
|
86
104
|
return filterParen;
|
|
@@ -89,6 +107,56 @@ function classifyParseError(node: AstNode, expression: string): RSErrorDescripti
|
|
|
89
107
|
return detectGlobalFuncWithoutArgs(node, expression);
|
|
90
108
|
}
|
|
91
109
|
|
|
110
|
+
function detectIncompleteFunctionDecl(
|
|
111
|
+
node: AstNode,
|
|
112
|
+
expression: string,
|
|
113
|
+
expected?: TypeClass
|
|
114
|
+
): RSErrorDescription | null {
|
|
115
|
+
const funcDecl = findAncestor(node, isFunctionDeclNode);
|
|
116
|
+
if (funcDecl === null) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const bodyChild = funcDecl.children[funcDecl.children.length - 1];
|
|
121
|
+
if (bodyChild?.typeID !== TokenID.ERROR || node !== bodyChild) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const argsNode = funcDecl.children.find(child => child.typeID === Arguments || child.typeID === TokenID.NT_ARGUMENTS);
|
|
126
|
+
if (argsNode === undefined || subtreeHasError(argsNode)) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (expression.slice(funcDecl.to).trim().length > 0) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
code: incompleteFormalExpressionCode(expected),
|
|
136
|
+
from: bodyChild.from,
|
|
137
|
+
to: bodyChild.to
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function incompleteFormalExpressionCode(expected?: TypeClass): RSErrorCode {
|
|
142
|
+
switch (expected) {
|
|
143
|
+
case TypeClassEnum.function:
|
|
144
|
+
return RSErrorCode.expectedExpressionBody;
|
|
145
|
+
case TypeClassEnum.predicate:
|
|
146
|
+
case TypeClassEnum.logic:
|
|
147
|
+
return RSErrorCode.expectedLogicBody;
|
|
148
|
+
default:
|
|
149
|
+
return RSErrorCode.expectedFunctionBody;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function subtreeHasError(node: AstNode): boolean {
|
|
154
|
+
if (node.typeID === TokenID.ERROR) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return node.children.some(subtreeHasError);
|
|
158
|
+
}
|
|
159
|
+
|
|
92
160
|
function detectFilterParenMismatch(node: AstNode, expression: string): RSErrorDescription | null {
|
|
93
161
|
const filterNode = findAncestor(node, isFilterNode) ?? findRelatedNode(node, isFilterNode);
|
|
94
162
|
if (filterNode === null) {
|
|
@@ -133,37 +201,30 @@ function classifyFuncWithoutArgs(funcNode: AstNode, expression: string): RSError
|
|
|
133
201
|
const name = expression.slice(funcNode.from, funcNode.to);
|
|
134
202
|
const rest = expression.slice(funcNode.to);
|
|
135
203
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
}
|
|
204
|
+
const withoutArgs: RSErrorDescription = {
|
|
205
|
+
code: RSErrorCode.globalFuncWithoutArgs,
|
|
206
|
+
from: funcNode.from,
|
|
207
|
+
to: funcNode.to,
|
|
208
|
+
params: [name]
|
|
209
|
+
};
|
|
144
210
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
from: funcNode.from,
|
|
149
|
-
to: funcNode.to,
|
|
150
|
-
params: [name]
|
|
151
|
-
};
|
|
211
|
+
// Function with nothing (or only whitespace) after it is genuinely called without arguments.
|
|
212
|
+
if (/^\s*$/.test(rest)) {
|
|
213
|
+
return withoutArgs;
|
|
152
214
|
}
|
|
153
215
|
|
|
216
|
+
// Anything other than a bracketed argument form (e.g. parentheses or braces) is malformed call
|
|
217
|
+
// syntax: defer to the bracket/syntax error handling instead of reporting a missing-arguments error.
|
|
154
218
|
const openBracket = /^\s*\[/.exec(rest);
|
|
155
|
-
if (openBracket
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
params: [name]
|
|
165
|
-
};
|
|
166
|
-
}
|
|
219
|
+
if (openBracket === null) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const closeIdx = findMatchingCloseBracket(rest, openBracket[0].length - 1);
|
|
224
|
+
if (closeIdx >= 0) {
|
|
225
|
+
const inner = rest.slice(openBracket[0].length, closeIdx).trim();
|
|
226
|
+
if (inner.length === 0) {
|
|
227
|
+
return withoutArgs;
|
|
167
228
|
}
|
|
168
229
|
}
|
|
169
230
|
|
|
@@ -181,6 +242,10 @@ function findAncestor(node: AstNode, predicate: (node: AstNode) => boolean): Ast
|
|
|
181
242
|
return null;
|
|
182
243
|
}
|
|
183
244
|
|
|
245
|
+
function isFunctionDeclNode(node: AstNode): boolean {
|
|
246
|
+
return node.typeID === Function_decl || node.typeID === TokenID.NT_FUNC_DEFINITION;
|
|
247
|
+
}
|
|
248
|
+
|
|
184
249
|
function isFunctionNode(node: AstNode): boolean {
|
|
185
250
|
return node.typeID === Function || node.typeID === TokenID.ID_FUNCTION;
|
|
186
251
|
}
|
|
@@ -114,7 +114,9 @@ export class RSLangAnalyzer {
|
|
|
114
114
|
}
|
|
115
115
|
const ast = this.parse(expression);
|
|
116
116
|
if (ast.hasError) {
|
|
117
|
-
extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false
|
|
117
|
+
extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false, {
|
|
118
|
+
expected: options?.expected
|
|
119
|
+
});
|
|
118
120
|
return { success: false, type: null, valueClass: null, errors, ast };
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -157,12 +157,12 @@ const errorData = [
|
|
|
157
157
|
['R1', { code: RSErrorCode.radicalUsage, from: 0, to: 2, params: ['R1'] }],
|
|
158
158
|
['[a∈ℬ(R1)] R1\\a', { code: RSErrorCode.radicalUsage, from: 10, to: 12, params: ['R1'] }],
|
|
159
159
|
// Functions
|
|
160
|
-
['F1[X1]', { code: RSErrorCode.invalidArgsArity, from:
|
|
161
|
-
['F1[X1, X1, X1]', { code: RSErrorCode.invalidArgsArity, from:
|
|
160
|
+
['F1[X1]', { code: RSErrorCode.invalidArgsArity, from: 0, to: 6, params: ['2', '1'] }],
|
|
161
|
+
['F1[X1, X1, X1]', { code: RSErrorCode.invalidArgsArity, from: 0, to: 14, params: ['2', '3'] }],
|
|
162
162
|
['F1[X1, S1]', { code: RSErrorCode.invalidArgumentType, from: 7, to: 9, params: ['b∈ℬ(X1)', 'ℬ(X1×X1)'] }],
|
|
163
163
|
['F1[S1, X1]', { code: RSErrorCode.invalidArgumentType, from: 3, to: 5, params: ['a∈ℬ(X1)', 'ℬ(X1×X1)'] }],
|
|
164
|
-
['P1[X1]', { code: RSErrorCode.invalidArgsArity, from:
|
|
165
|
-
['P1[X1, X1, X1]', { code: RSErrorCode.invalidArgsArity, from:
|
|
164
|
+
['P1[X1]', { code: RSErrorCode.invalidArgsArity, from: 0, to: 6, params: ['2', '1'] }],
|
|
165
|
+
['P1[X1, X1, X1]', { code: RSErrorCode.invalidArgsArity, from: 0, to: 14, params: ['2', '3'] }],
|
|
166
166
|
['P1[X1, S1]', { code: RSErrorCode.invalidArgumentType, from: 7, to: 9, params: ['b∈ℬ(X1)', 'ℬ(X1×X1)'] }],
|
|
167
167
|
['P1[S1, X1]', { code: RSErrorCode.invalidArgumentType, from: 3, to: 5, params: ['a∈ℬ(X1)', 'ℬ(X1×X1)'] }],
|
|
168
168
|
// Integral
|
|
@@ -223,10 +223,7 @@ const errorData = [
|
|
|
223
223
|
{ code: RSErrorCode.invalidFilterArgumentType, from: 8, to: 13, params: ['Fi1', 'ℬℬ(X1)', 'ℬ(R0)'] }
|
|
224
224
|
],
|
|
225
225
|
['Fi1[1](S1)', { code: RSErrorCode.invalidFilterParameterType, from: 4, to: 5, params: ['Z', 'ℬ(X1)', 'Fi1'] }],
|
|
226
|
-
[
|
|
227
|
-
'Fi1[X1](ℬ(X1)×X1)',
|
|
228
|
-
{ code: RSErrorCode.invalidFilterBooleanEchelon, from: 4, to: 6, params: ['Fi1', 'ℬ(X1)', 'ℬℬ(X1)'] }
|
|
229
|
-
],
|
|
226
|
+
['Fi1[X1](ℬ(X1)×X1)', { code: RSErrorCode.invalidFilterBooleanEchelon, from: 4, to: 6, params: ['Fi1', 'ℬ(X1)'] }],
|
|
230
227
|
['Fi3[X1](S1)', { code: RSErrorCode.invalidFilterIndex, from: 8, to: 10, params: ['Fi3', 'ℬ(X1×X1)', '3', '2'] }],
|
|
231
228
|
['Fi1[X1,X1](S1)', { code: RSErrorCode.invalidFilterArity, from: 7, to: 9, params: ['1', '2', 'Fi1'] }],
|
|
232
229
|
[
|
|
@@ -328,6 +325,33 @@ describe('TypeAuditor', () => {
|
|
|
328
325
|
expectType('F4[Z]', 'ℬ(X1)');
|
|
329
326
|
});
|
|
330
327
|
|
|
328
|
+
it('Highlights the function call site for invalidArgsArity', () => {
|
|
329
|
+
typeContext.set('F7', {
|
|
330
|
+
typeID: TypeID.function,
|
|
331
|
+
result: bool(basic('X1')),
|
|
332
|
+
args: [
|
|
333
|
+
{ alias: 'a', type: bool(basic('X1')) },
|
|
334
|
+
{ alias: 'b', type: bool(basic('X1')) },
|
|
335
|
+
{ alias: 'c', type: bool(basic('X1')) }
|
|
336
|
+
]
|
|
337
|
+
});
|
|
338
|
+
typeContext.set('F8', {
|
|
339
|
+
typeID: TypeID.function,
|
|
340
|
+
result: bool(basic('X1')),
|
|
341
|
+
args: [
|
|
342
|
+
{ alias: 'a', type: bool(basic('X1')) },
|
|
343
|
+
{ alias: 'b', type: bool(basic('X1')) },
|
|
344
|
+
{ alias: 'c', type: bool(basic('X1')) }
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
expectError('F8[X1,F7[X1,X1],X1]', {
|
|
348
|
+
code: RSErrorCode.invalidArgsArity,
|
|
349
|
+
from: 6,
|
|
350
|
+
to: 15,
|
|
351
|
+
params: ['3', '2']
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
331
355
|
it('Templated nesting', () => {
|
|
332
356
|
typeContext.set('F2', {
|
|
333
357
|
typeID: TypeID.function,
|
|
@@ -837,8 +837,7 @@ export class TypeAuditor {
|
|
|
837
837
|
if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) {
|
|
838
838
|
return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [
|
|
839
839
|
operator,
|
|
840
|
-
labelType(param)
|
|
841
|
-
labelType(expected)
|
|
840
|
+
labelType(param)
|
|
842
841
|
]);
|
|
843
842
|
}
|
|
844
843
|
return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [
|
|
@@ -999,7 +998,7 @@ export class TypeAuditor {
|
|
|
999
998
|
|
|
1000
999
|
private checkFuncArguments(node: AstNode, alias: string, type: Parametrized): Map<string, Typification> | null {
|
|
1001
1000
|
if (node.children.length - 1 !== type.args.length) {
|
|
1002
|
-
return this.onError(RSErrorCode.invalidArgsArity, node
|
|
1001
|
+
return this.onError(RSErrorCode.invalidArgsArity, node, [
|
|
1003
1002
|
String(type.args.length),
|
|
1004
1003
|
String(node.children.length - 1)
|
|
1005
1004
|
]);
|