@rsconcept/domain 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{analyzer-A82AxKdS.d.ts → analyzer-CqUJ3FO9.d.ts} +2 -2
- package/dist/{ast-annotations-YzvwjoFW.d.ts → ast-annotations-DvB1VcUv.d.ts} +2 -2
- package/dist/{calculator-Cyy9eYyx.d.ts → calculator-DKxDpTdT.d.ts} +2 -2
- package/dist/{error-Cv4sntcy.d.ts → error-CLnXbkly.d.ts} +6 -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 +5 -0
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +1 -1
- package/dist/rslang/eval/evaluator.d.ts +1 -1
- package/dist/rslang/index.d.ts +4 -4
- package/dist/rslang/parser/syntax-errors.d.ts +1 -1
- package/dist/rslang/parser/syntax-errors.js +257 -1
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +1 -1
- package/package.json +1 -1
- package/src/rslang/error.ts +5 -0
- package/src/rslang/parser/parser.test.ts +60 -6
- package/src/rslang/parser/syntax-errors.ts +485 -4
|
@@ -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-CLnXbkly.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-CqUJ3FO9.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-CLnXbkly.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-DvB1VcUv.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-CLnXbkly.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-DKxDpTdT.d.ts.map
|
|
@@ -24,6 +24,7 @@ type ErrorReporter = (error: RSErrorDescription) => void;
|
|
|
24
24
|
/** Represents RSLang expression error types. */
|
|
25
25
|
declare const RSErrorCode: {
|
|
26
26
|
readonly unknownSyntax: 33792;
|
|
27
|
+
readonly forbiddenCharacter: 33793;
|
|
27
28
|
readonly bracketMismatch: 33801;
|
|
28
29
|
readonly doubleParenthesis: 33802;
|
|
29
30
|
readonly missingOpenBracket: 33803;
|
|
@@ -32,6 +33,10 @@ declare const RSErrorCode: {
|
|
|
32
33
|
readonly expectedFunctionBody: 33816;
|
|
33
34
|
readonly expectedExpressionBody: 33817;
|
|
34
35
|
readonly expectedLogicBody: 33818;
|
|
36
|
+
readonly expectedQuantifierBody: 33819;
|
|
37
|
+
readonly expectedDeclarativeBody: 33820;
|
|
38
|
+
readonly expectedImperativeBody: 33821;
|
|
39
|
+
readonly expectedRecursiveBody: 33822;
|
|
35
40
|
readonly expectedLocal: 33813;
|
|
36
41
|
readonly expectedType: 33814;
|
|
37
42
|
readonly localDoubleDeclare: 10241;
|
|
@@ -96,4 +101,4 @@ declare function getRSErrorPrefix(code: RSErrorCode): string;
|
|
|
96
101
|
declare function isCritical(code: RSErrorCode): boolean;
|
|
97
102
|
//#endregion
|
|
98
103
|
export { RSErrorInfo as a, RSErrorDescription as i, RSErrorClass as n, getRSErrorPrefix as o, RSErrorCode as r, isCritical as s, ErrorReporter as t };
|
|
99
|
-
//# sourceMappingURL=error-
|
|
104
|
+
//# sourceMappingURL=error-CLnXbkly.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-CLnXbkly.js";
|
|
13
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-DvB1VcUv.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-DKxDpTdT.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-CqUJ3FO9.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-DKxDpTdT.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-CqUJ3FO9.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-CqUJ3FO9.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-DvB1VcUv.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-CLnXbkly.js";
|
|
2
2
|
export { ErrorReporter, RSErrorClass, RSErrorCode, RSErrorDescription, RSErrorInfo, getRSErrorPrefix, isCritical };
|
package/dist/rslang/error.js
CHANGED
|
@@ -11,6 +11,7 @@ const RSErrorClass = {
|
|
|
11
11
|
/** Represents RSLang expression error types. */
|
|
12
12
|
const RSErrorCode = {
|
|
13
13
|
unknownSyntax: 33792,
|
|
14
|
+
forbiddenCharacter: 33793,
|
|
14
15
|
bracketMismatch: 33801,
|
|
15
16
|
doubleParenthesis: 33802,
|
|
16
17
|
missingOpenBracket: 33803,
|
|
@@ -19,6 +20,10 @@ const RSErrorCode = {
|
|
|
19
20
|
expectedFunctionBody: 33816,
|
|
20
21
|
expectedExpressionBody: 33817,
|
|
21
22
|
expectedLogicBody: 33818,
|
|
23
|
+
expectedQuantifierBody: 33819,
|
|
24
|
+
expectedDeclarativeBody: 33820,
|
|
25
|
+
expectedImperativeBody: 33821,
|
|
26
|
+
expectedRecursiveBody: 33822,
|
|
22
27
|
expectedLocal: 33813,
|
|
23
28
|
expectedType: 33814,
|
|
24
29
|
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 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 invalidEnumeration: 0x8813, // 34835\n projectionSetArgumentNotSet: 0x8830, // 34864\n projectionSetArgumentNotTupleSet: 0x8831, // 34865\n projectionSetIndexOutOfRange: 0x8832, // 34866\n projectionTupleArgumentNotTuple: 0x8833, // 34867\n projectionTupleIndexOutOfRange: 0x8834, // 34868\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 localOutOfScopeParentheses: 0x882e, // 34862\n localUndeclaredInSubexpr: 0x882f, // 34863\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,oBAAoB;CACpB,6BAA6B;CAC7B,kCAAkC;CAClC,8BAA8B;CAC9B,iCAAiC;CACjC,gCAAgC;CAChC,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,cAAc;CACd,2BAA2B;CAC3B,oBAAoB;CACpB,wBAAwB;CACxB,oBAAoB;CACpB,sBAAsB;CACtB,eAAe;CACf,iBAAiB;CACjB,+BAA+B;CAC/B,yBAAyB;CACzB,4BAA4B;CAC5B,oBAAoB;CACpB,6BAA6B;CAC7B,4BAA4B;CAC5B,0BAA0B;CAE1B,eAAe;CACf,sBAAsB;CAGtB,kBAAkB;CAClB,aAAa;CACb,kBAAkB;CAClB,mBAAmB;CACnB,iBAAiB;CACjB,mBAAmB;CACnB,iBAAiB;CACjB,yBAAyB;CACzB,iBAAiB;CAEjB,iBAAiB;CACjB,sBAAsB;AACxB;AAGA,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;;AAG5B,SAAS,gBAAgB,OAAkC;CACzD,KAAK,QAAQ,2BAA2B,GACtC,OAAO,aAAa;MACf,KAAK,QAAQ,sBAAsB,GACxC,OAAO,aAAa;MACf,KAAK,QAAQ,uBAAuB,GACzC,OAAO,aAAa;MACf,KAAK,QAAQ,yBAAyB,GAC3C,OAAO,aAAa;MAEpB,OAAO,aAAa;AAExB;;AAGA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;CAEzC,QAAQ,gBAAgB,IAAI,GAA5B;EACE,KAAK,aAAa,OAAO,OAAO,MAAM;EACtC,KAAK,aAAa,QAAQ,OAAO,MAAM;EACvC,KAAK,aAAa,UAAU,OAAO,MAAM;EACzC,KAAK,aAAa,YAAY,OAAO,MAAM;EAC3C,KAAK,aAAa,SAAS,OAAO,MAAM;CAC1C;AACF;;AAGA,SAAgB,WAAW,MAA4B;CACrD,OAAO,SAAS,YAAY,sBAAsB,SAAS,YAAY;AACzE"}
|
|
1
|
+
{"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 forbiddenCharacter: 0x8401, // 33793\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 expectedQuantifierBody: 0x841b, // 33819\n expectedDeclarativeBody: 0x841c, // 33820\n expectedImperativeBody: 0x841d, // 33821\n expectedRecursiveBody: 0x841e, // 33822\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 invalidEnumeration: 0x8813, // 34835\n projectionSetArgumentNotSet: 0x8830, // 34864\n projectionSetArgumentNotTupleSet: 0x8831, // 34865\n projectionSetIndexOutOfRange: 0x8832, // 34866\n projectionTupleArgumentNotTuple: 0x8833, // 34867\n projectionTupleIndexOutOfRange: 0x8834, // 34868\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 localOutOfScopeParentheses: 0x882e, // 34862\n localUndeclaredInSubexpr: 0x882f, // 34863\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,oBAAoB;CACpB,iBAAiB;CACjB,mBAAmB;CACnB,oBAAoB;CACpB,qBAAqB;CACrB,qBAAqB;CACrB,sBAAsB;CACtB,wBAAwB;CACxB,mBAAmB;CACnB,wBAAwB;CACxB,yBAAyB;CACzB,wBAAwB;CACxB,uBAAuB;CACvB,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,oBAAoB;CACpB,6BAA6B;CAC7B,kCAAkC;CAClC,8BAA8B;CAC9B,iCAAiC;CACjC,gCAAgC;CAChC,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,cAAc;CACd,2BAA2B;CAC3B,oBAAoB;CACpB,wBAAwB;CACxB,oBAAoB;CACpB,sBAAsB;CACtB,eAAe;CACf,iBAAiB;CACjB,+BAA+B;CAC/B,yBAAyB;CACzB,4BAA4B;CAC5B,oBAAoB;CACpB,6BAA6B;CAC7B,4BAA4B;CAC5B,0BAA0B;CAE1B,eAAe;CACf,sBAAsB;CAGtB,kBAAkB;CAClB,aAAa;CACb,kBAAkB;CAClB,mBAAmB;CACnB,iBAAiB;CACjB,mBAAmB;CACnB,iBAAiB;CACjB,yBAAyB;CACzB,iBAAiB;CAEjB,iBAAiB;CACjB,sBAAsB;AACxB;AAGA,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;;AAG5B,SAAS,gBAAgB,OAAkC;CACzD,KAAK,QAAQ,2BAA2B,GACtC,OAAO,aAAa;MACf,KAAK,QAAQ,sBAAsB,GACxC,OAAO,aAAa;MACf,KAAK,QAAQ,uBAAuB,GACzC,OAAO,aAAa;MACf,KAAK,QAAQ,yBAAyB,GAC3C,OAAO,aAAa;MAEpB,OAAO,aAAa;AAExB;;AAGA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;CAEzC,QAAQ,gBAAgB,IAAI,GAA5B;EACE,KAAK,aAAa,OAAO,OAAO,MAAM;EACtC,KAAK,aAAa,QAAQ,OAAO,MAAM;EACvC,KAAK,aAAa,UAAU,OAAO,MAAM;EACzC,KAAK,aAAa,YAAY,OAAO,MAAM;EAC3C,KAAK,aAAa,SAAS,OAAO,MAAM;CAC1C;AACF;;AAGA,SAAgB,WAAW,MAA4B;CACrD,OAAO,SAAS,YAAY,sBAAsB,SAAS,YAAY;AACzE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-
|
|
1
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-DKxDpTdT.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-CLnXbkly.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-CLnXbkly.js";
|
|
3
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "../ast-annotations-DvB1VcUv.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-DKxDpTdT.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-CqUJ3FO9.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,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
2
|
import { g as TypeClass } from "../../typification-Dk-fisgO.js";
|
|
3
|
-
import { t as ErrorReporter } from "../../error-
|
|
3
|
+
import { t as ErrorReporter } from "../../error-CLnXbkly.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/parser/syntax-errors.d.ts
|
|
6
6
|
/** Options for syntax error extraction. */
|
|
@@ -11,6 +11,14 @@ import "./parser.terms.js";
|
|
|
11
11
|
*/
|
|
12
12
|
/** Extracts syntax errors from an AST. */
|
|
13
13
|
function extractSyntaxErrors(ast, expression, reporter, annotateErrors = false, options) {
|
|
14
|
+
const forbiddenErrors = extractForbiddenCharacterErrors(expression);
|
|
15
|
+
if (forbiddenErrors.length > 0) {
|
|
16
|
+
for (const error of forbiddenErrors) {
|
|
17
|
+
reporter(error);
|
|
18
|
+
if (annotateErrors) annotateError(ast, error.code, error.params);
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
14
22
|
const collected = [];
|
|
15
23
|
const annotationTargets = /* @__PURE__ */ new Map();
|
|
16
24
|
const collect = (error, target) => {
|
|
@@ -18,9 +26,10 @@ function extractSyntaxErrors(ast, expression, reporter, annotateErrors = false,
|
|
|
18
26
|
if (target !== void 0) annotationTargets.set(error, target);
|
|
19
27
|
};
|
|
20
28
|
const bracketError = extractBracketErrors(expression);
|
|
21
|
-
if (bracketError !== null) collect(bracketError, ast);
|
|
22
29
|
const hasBracketErrors = bracketError !== null;
|
|
23
30
|
visitAstDFS(ast, (node) => extractInternal(node, expression, collect, hasBracketErrors, options));
|
|
31
|
+
const hasIncompleteGenerator = collected.some((error) => isIncompleteGeneratorBodyCode(error.code));
|
|
32
|
+
if (bracketError !== null && !hasIncompleteGenerator) collect(bracketError, ast);
|
|
24
33
|
for (const error of deduplicateErrors(collected)) {
|
|
25
34
|
reporter(error);
|
|
26
35
|
if (annotateErrors) {
|
|
@@ -55,6 +64,10 @@ function extractInternal(node, expression, collect, ignoreUnknownErrors, options
|
|
|
55
64
|
function classifyParseError(node, expression, options) {
|
|
56
65
|
const incompleteFunctionDecl = detectIncompleteFunctionDecl(node, expression, options?.expected);
|
|
57
66
|
if (incompleteFunctionDecl !== null) return incompleteFunctionDecl;
|
|
67
|
+
const incompleteQuantifier = detectIncompleteQuantifier(node, expression);
|
|
68
|
+
if (incompleteQuantifier !== null) return incompleteQuantifier;
|
|
69
|
+
const incompleteGenerator = detectIncompleteGenerator(node, expression);
|
|
70
|
+
if (incompleteGenerator !== null) return incompleteGenerator;
|
|
58
71
|
const filterParen = detectFilterParenMismatch(node, expression);
|
|
59
72
|
if (filterParen !== null) return filterParen;
|
|
60
73
|
return detectGlobalFuncWithoutArgs(node, expression);
|
|
@@ -81,6 +94,210 @@ function incompleteFormalExpressionCode(expected) {
|
|
|
81
94
|
default: return RSErrorCode.expectedFunctionBody;
|
|
82
95
|
}
|
|
83
96
|
}
|
|
97
|
+
function detectIncompleteQuantifier(node, expression) {
|
|
98
|
+
const quantNode = findAncestor(node, isQuantifierNode);
|
|
99
|
+
if (quantNode === null) return null;
|
|
100
|
+
const bodyChild = quantNode.children[quantNode.children.length - 1];
|
|
101
|
+
if (bodyChild?.typeID !== TokenID.ERROR || node !== bodyChild) return null;
|
|
102
|
+
const headerChildren = quantNode.children.slice(0, -1);
|
|
103
|
+
if (headerChildren.length < 3) return null;
|
|
104
|
+
const varPack = headerChildren.find((child) => child.typeID === 31 || child.typeID === TokenID.NT_ENUM_DECL);
|
|
105
|
+
if (varPack === void 0 || subtreeHasError(varPack)) return null;
|
|
106
|
+
const domainChild = headerChildren[headerChildren.length - 1];
|
|
107
|
+
if (domainChild === varPack || subtreeHasError(domainChild)) return null;
|
|
108
|
+
if (expression.slice(quantNode.to).trim().length > 0) return null;
|
|
109
|
+
return {
|
|
110
|
+
code: RSErrorCode.expectedQuantifierBody,
|
|
111
|
+
from: bodyChild.from,
|
|
112
|
+
to: bodyChild.to
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function detectIncompleteGenerator(node, expression) {
|
|
116
|
+
return detectIncompleteDeclarative(node, expression) ?? detectIncompleteImperative(node, expression) ?? detectIncompleteRecursion(node, expression);
|
|
117
|
+
}
|
|
118
|
+
function detectIncompleteDeclarative(node, expression) {
|
|
119
|
+
return detectIncompleteGeneratorBody(node, expression, findAncestor(node, (target) => target.typeID === 60 || target.typeID === TokenID.NT_DECLARATIVE_EXPR), RSErrorCode.expectedDeclarativeBody, (slot) => isIncompleteDeclarativeBody(slot));
|
|
120
|
+
}
|
|
121
|
+
function detectIncompleteImperative(node, expression) {
|
|
122
|
+
return detectIncompleteGeneratorBody(node, expression, findAncestor(node, (target) => target.typeID === 64 || target.typeID === TokenID.NT_IMPERATIVE_EXPR), RSErrorCode.expectedImperativeBody, (slot) => isIncompleteImperativeBody(slot, expression));
|
|
123
|
+
}
|
|
124
|
+
function detectIncompleteRecursion(node, expression) {
|
|
125
|
+
return detectIncompleteGeneratorBody(node, expression, findAncestor(node, (target) => target.typeID === 68), RSErrorCode.expectedRecursiveBody, (slot) => isIncompleteRecursionBody(slot));
|
|
126
|
+
}
|
|
127
|
+
function detectIncompleteGeneratorBody(node, expression, generatorNode, code, isIncomplete) {
|
|
128
|
+
if (generatorNode === null) return null;
|
|
129
|
+
if (expression.slice(generatorNode.to).trim().length > 0) return null;
|
|
130
|
+
const slot = getGeneratorBodySlot(generatorNode, expression);
|
|
131
|
+
if (slot === null || !isIncomplete(slot)) return null;
|
|
132
|
+
if (!generatorHeaderIsValid(generatorNode, expression, slot.headerEndIndex)) return null;
|
|
133
|
+
if (!isErrorInBodySlot(node, slot, generatorNode)) return null;
|
|
134
|
+
return incompleteGeneratorError(code, node);
|
|
135
|
+
}
|
|
136
|
+
function getGeneratorBodySlot(generatorNode, expression) {
|
|
137
|
+
if (generatorNode.typeID === 60 || generatorNode.typeID === TokenID.NT_DECLARATIVE_EXPR) return getDeclarativeBodySlot(generatorNode, expression);
|
|
138
|
+
if (generatorNode.typeID === 64 || generatorNode.typeID === TokenID.NT_IMPERATIVE_EXPR) return getImperativeBodySlot(generatorNode, expression);
|
|
139
|
+
if (generatorNode.typeID === 68) return getRecursionBodySlot(generatorNode, expression);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
function getDeclarativeBodySlot(declNode, expression) {
|
|
143
|
+
const pipeIndex = declNode.children.findIndex((child) => isPipeToken(child, expression));
|
|
144
|
+
if (pipeIndex >= 0) return {
|
|
145
|
+
nodes: contentChildren(declNode, expression, pipeIndex + 1),
|
|
146
|
+
headerEndIndex: pipeIndex + 1
|
|
147
|
+
};
|
|
148
|
+
const domainNode = findDeclarativeDomain(declNode, expression);
|
|
149
|
+
if (domainNode === null) return null;
|
|
150
|
+
const domainIndex = declNode.children.indexOf(domainNode);
|
|
151
|
+
return {
|
|
152
|
+
nodes: contentChildren(declNode, expression, domainIndex + 1),
|
|
153
|
+
headerEndIndex: domainIndex + 1
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function getImperativeBodySlot(impNode, expression) {
|
|
157
|
+
const pipeIndex = impNode.children.findIndex((child) => isPipeToken(child, expression));
|
|
158
|
+
if (pipeIndex >= 0) return {
|
|
159
|
+
nodes: contentChildren(impNode, expression, pipeIndex + 1),
|
|
160
|
+
headerEndIndex: pipeIndex + 1
|
|
161
|
+
};
|
|
162
|
+
const tupleNode = findImperativeTuple(impNode);
|
|
163
|
+
if (tupleNode === null) return null;
|
|
164
|
+
const tupleIndex = impNode.children.indexOf(tupleNode);
|
|
165
|
+
return {
|
|
166
|
+
nodes: contentChildren(impNode, expression, tupleIndex + 1),
|
|
167
|
+
headerEndIndex: tupleIndex + 1
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function getRecursionBodySlot(recNode, expression) {
|
|
171
|
+
const initNode = findRecursionInit(recNode, expression);
|
|
172
|
+
if (initNode === null) return null;
|
|
173
|
+
const initIndex = recNode.children.indexOf(initNode);
|
|
174
|
+
const afterInit = contentChildren(recNode, expression, initIndex + 1);
|
|
175
|
+
const lastPipeIndex = findLastPipeIndex(afterInit, expression);
|
|
176
|
+
if (lastPipeIndex < 0) return {
|
|
177
|
+
nodes: afterInit,
|
|
178
|
+
headerEndIndex: initIndex + 1
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
nodes: afterInit.slice(lastPipeIndex + 1),
|
|
182
|
+
headerEndIndex: recNode.children.indexOf(afterInit[lastPipeIndex]) + 1
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function contentChildren(generatorNode, expression, fromIndex) {
|
|
186
|
+
return generatorNode.children.slice(fromIndex).filter((child) => !isClosingBrace(child, expression));
|
|
187
|
+
}
|
|
188
|
+
function findDeclarativeDomain(declNode, expression) {
|
|
189
|
+
const inIndex = declNode.children.findIndex((child) => expression.slice(child.from, child.to) === "∈");
|
|
190
|
+
if (inIndex < 0) return null;
|
|
191
|
+
for (let index = inIndex + 1; index < declNode.children.length; index++) {
|
|
192
|
+
const child = declNode.children[index];
|
|
193
|
+
if (isPipeToken(child, expression) || isClosingBrace(child, expression)) break;
|
|
194
|
+
if (child.typeID === 38) return child;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
function findImperativeTuple(impNode) {
|
|
199
|
+
for (const child of impNode.children) if (child.typeID === 38) return child;
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
function findLastPipeIndex(nodes, expression) {
|
|
203
|
+
for (let index = nodes.length - 1; index >= 0; index--) if (isPipeToken(nodes[index], expression)) return index;
|
|
204
|
+
return -1;
|
|
205
|
+
}
|
|
206
|
+
function generatorHeaderIsValid(generatorNode, expression, headerEndIndex) {
|
|
207
|
+
for (let index = 0; index < headerEndIndex; index++) {
|
|
208
|
+
const child = generatorNode.children[index];
|
|
209
|
+
if (child.typeID === TokenID.ERROR) return false;
|
|
210
|
+
if (isStructuralGeneratorToken(child, expression)) continue;
|
|
211
|
+
if (subtreeHasError(child)) return false;
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
function isIncompleteDeclarativeBody(slot) {
|
|
216
|
+
return isEmptyOrErrorOnlyBody(slot.nodes);
|
|
217
|
+
}
|
|
218
|
+
function isIncompleteImperativeBody(slot, expression) {
|
|
219
|
+
if (slot.nodes.length === 0) return true;
|
|
220
|
+
if (slot.nodes.length === 1 && slot.nodes[0].typeID === 65) return isImpBlocksIncomplete(slot.nodes[0], expression);
|
|
221
|
+
return isEmptyOrErrorOnlyBody(slot.nodes);
|
|
222
|
+
}
|
|
223
|
+
function isIncompleteRecursionBody(slot) {
|
|
224
|
+
return isEmptyOrErrorOnlyBody(slot.nodes);
|
|
225
|
+
}
|
|
226
|
+
function isEmptyOrErrorOnlyBody(nodes) {
|
|
227
|
+
if (nodes.length === 0) return true;
|
|
228
|
+
if (nodes.length === 1) return isErrorPlaceholder(nodes[0]);
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
function isImpBlocksIncomplete(blocksNode, expression) {
|
|
232
|
+
if (blocksNode.children.length === 0) return true;
|
|
233
|
+
const lastChild = blocksNode.children[blocksNode.children.length - 1];
|
|
234
|
+
if (lastChild.typeID === TokenID.ERROR) return true;
|
|
235
|
+
if (isSemicolonToken(lastChild, expression)) return true;
|
|
236
|
+
if (lastChild.typeID === 38 && isErrorPlaceholder(lastChild)) return true;
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
function isErrorInBodySlot(errorNode, slot, generatorNode) {
|
|
240
|
+
if (slot.nodes.length === 0) {
|
|
241
|
+
const bodyStart = generatorNode.children[slot.headerEndIndex]?.from ?? generatorNode.from;
|
|
242
|
+
return errorNode.from >= bodyStart;
|
|
243
|
+
}
|
|
244
|
+
for (const bodyNode of slot.nodes) if (errorNode === bodyNode || isDescendantOf(bodyNode, errorNode)) {
|
|
245
|
+
if (isErrorPlaceholder(bodyNode)) return true;
|
|
246
|
+
if (bodyNode.typeID === 65 && isImpBlocksTailError(bodyNode, errorNode)) return true;
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
function isImpBlocksTailError(blocksNode, errorNode) {
|
|
251
|
+
const lastChild = blocksNode.children[blocksNode.children.length - 1];
|
|
252
|
+
return lastChild.typeID === TokenID.ERROR && (errorNode === lastChild || isDescendantOf(lastChild, errorNode));
|
|
253
|
+
}
|
|
254
|
+
function isErrorPlaceholder(node) {
|
|
255
|
+
if (node.typeID === TokenID.ERROR) return true;
|
|
256
|
+
if (node.children.length === 0) return false;
|
|
257
|
+
return node.children.every((child) => isErrorPlaceholder(child));
|
|
258
|
+
}
|
|
259
|
+
function isDescendantOf(ancestor, node) {
|
|
260
|
+
let current = node.parent;
|
|
261
|
+
while (current !== null) {
|
|
262
|
+
if (current === ancestor) return true;
|
|
263
|
+
current = current.parent;
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
function findRecursionInit(recursionNode, expression) {
|
|
268
|
+
const assignIndex = recursionNode.children.findIndex((child) => expression.slice(child.from, child.to) === ":=");
|
|
269
|
+
if (assignIndex < 0) return null;
|
|
270
|
+
for (let index = assignIndex + 1; index < recursionNode.children.length; index++) {
|
|
271
|
+
const child = recursionNode.children[index];
|
|
272
|
+
if (child.typeID === TokenID.ERROR) break;
|
|
273
|
+
if (isPipeToken(child, expression) || isClosingBrace(child, expression)) continue;
|
|
274
|
+
return child;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
function incompleteGeneratorError(code, errorNode) {
|
|
279
|
+
return {
|
|
280
|
+
code,
|
|
281
|
+
from: errorNode.from,
|
|
282
|
+
to: errorNode.to
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function isIncompleteGeneratorBodyCode(code) {
|
|
286
|
+
return code === RSErrorCode.expectedDeclarativeBody || code === RSErrorCode.expectedImperativeBody || code === RSErrorCode.expectedRecursiveBody;
|
|
287
|
+
}
|
|
288
|
+
function isPipeToken(node, expression) {
|
|
289
|
+
return expression.slice(node.from, node.to) === "|";
|
|
290
|
+
}
|
|
291
|
+
function isSemicolonToken(node, expression) {
|
|
292
|
+
return expression.slice(node.from, node.to) === ";";
|
|
293
|
+
}
|
|
294
|
+
function isClosingBrace(node, expression) {
|
|
295
|
+
return node.typeID !== TokenID.ERROR && expression.slice(node.from, node.to) === "}";
|
|
296
|
+
}
|
|
297
|
+
function isStructuralGeneratorToken(node, expression) {
|
|
298
|
+
const text = expression.slice(node.from, node.to);
|
|
299
|
+
return text === "{" || text === "}" || text === "|" || text === "∈" || text === ":=" || text === ";";
|
|
300
|
+
}
|
|
84
301
|
function subtreeHasError(node) {
|
|
85
302
|
if (node.typeID === TokenID.ERROR) return true;
|
|
86
303
|
return node.children.some(subtreeHasError);
|
|
@@ -137,6 +354,9 @@ function findAncestor(node, predicate) {
|
|
|
137
354
|
function isFunctionDeclNode(node) {
|
|
138
355
|
return node.typeID === 76 || node.typeID === TokenID.NT_FUNC_DEFINITION;
|
|
139
356
|
}
|
|
357
|
+
function isQuantifierNode(node) {
|
|
358
|
+
return node.typeID === 29;
|
|
359
|
+
}
|
|
140
360
|
function isFunctionNode(node) {
|
|
141
361
|
return node.typeID === 69 || node.typeID === TokenID.ID_FUNCTION;
|
|
142
362
|
}
|
|
@@ -174,6 +394,42 @@ function deduplicateErrors(errors) {
|
|
|
174
394
|
function rangesOverlap(a, b) {
|
|
175
395
|
return a.from < b.to && b.from < a.to;
|
|
176
396
|
}
|
|
397
|
+
const ALLOWED_EXPRESSION_CHARS = buildAllowedExpressionChars();
|
|
398
|
+
function buildAllowedExpressionChars() {
|
|
399
|
+
const chars = /* @__PURE__ */ new Set();
|
|
400
|
+
for (const chunk of [
|
|
401
|
+
"0123456789",
|
|
402
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
403
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
404
|
+
"_",
|
|
405
|
+
"∅¬∀∃⇔⇒∨&ℬ+-*∪\\∆∩×∈∉⊆⊄⊂<>≥≤≠=,:;|[]{}()"
|
|
406
|
+
]) for (const symbol of chunk) chars.add(symbol);
|
|
407
|
+
for (let codePoint = 945; codePoint <= 969; codePoint++) chars.add(String.fromCodePoint(codePoint));
|
|
408
|
+
return chars;
|
|
409
|
+
}
|
|
410
|
+
function isAllowedExpressionChar(symbol) {
|
|
411
|
+
return /\s/u.test(symbol) || ALLOWED_EXPRESSION_CHARS.has(symbol);
|
|
412
|
+
}
|
|
413
|
+
function extractForbiddenCharacterErrors(expression) {
|
|
414
|
+
const errors = [];
|
|
415
|
+
let pos = 0;
|
|
416
|
+
while (pos < expression.length) {
|
|
417
|
+
const symbol = expression[pos];
|
|
418
|
+
if (isAllowedExpressionChar(symbol)) {
|
|
419
|
+
pos++;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const start = pos;
|
|
423
|
+
while (pos < expression.length && !isAllowedExpressionChar(expression[pos])) pos++;
|
|
424
|
+
errors.push({
|
|
425
|
+
code: RSErrorCode.forbiddenCharacter,
|
|
426
|
+
from: start,
|
|
427
|
+
to: pos,
|
|
428
|
+
params: [expression.slice(start, pos)]
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return errors;
|
|
432
|
+
}
|
|
177
433
|
function extractBracketErrors(expression) {
|
|
178
434
|
const stack = [];
|
|
179
435
|
for (let pos = 0; pos < expression.length; pos++) {
|