@rsconcept/domain 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/{analyzer-CqUJ3FO9.d.ts → analyzer-QxWs73gP.d.ts} +2 -2
  2. package/dist/{ast-annotations-DvB1VcUv.d.ts → ast-annotations-CtF7C9uK.d.ts} +2 -2
  3. package/dist/{calculator-DKxDpTdT.d.ts → calculator-REeX2ZS1.d.ts} +2 -2
  4. package/dist/{error-CLnXbkly.d.ts → error-toW0TUHF.d.ts} +6 -1
  5. package/dist/index.d.ts +4 -4
  6. package/dist/library/rsengine.d.ts +1 -1
  7. package/dist/library/rsform-api.d.ts +1 -1
  8. package/dist/library/rsform.d.ts +1 -1
  9. package/dist/rslang/ast-annotations.d.ts +1 -1
  10. package/dist/rslang/error.d.ts +1 -1
  11. package/dist/rslang/error.js +5 -0
  12. package/dist/rslang/error.js.map +1 -1
  13. package/dist/rslang/eval/calculator.d.ts +1 -1
  14. package/dist/rslang/eval/evaluator.d.ts +1 -1
  15. package/dist/rslang/index.d.ts +4 -4
  16. package/dist/rslang/labels.d.ts +1 -1
  17. package/dist/rslang/labels.js +1 -1
  18. package/dist/rslang/labels.js.map +1 -1
  19. package/dist/rslang/parser/normalize.js +5 -1
  20. package/dist/rslang/parser/normalize.js.map +1 -1
  21. package/dist/rslang/parser/syntax-errors/index.d.ts +22 -0
  22. package/dist/rslang/parser/syntax-errors/index.js +2 -0
  23. package/dist/rslang/semantic/analyzer.d.ts +1 -1
  24. package/dist/rslang/semantic/analyzer.js +1 -1
  25. package/dist/rslang/semantic/type-auditor.d.ts +1 -1
  26. package/dist/rslang/semantic/value-auditor.d.ts +1 -1
  27. package/dist/{rslang/parser/syntax-errors.js → syntax-errors-B6c2vsan.js} +421 -233
  28. package/dist/syntax-errors-B6c2vsan.js.map +1 -0
  29. package/package.json +1 -1
  30. package/src/rslang/error.ts +5 -0
  31. package/src/rslang/labels.ts +1 -1
  32. package/src/rslang/parser/README.md +73 -0
  33. package/src/rslang/parser/normalize.ts +5 -1
  34. package/src/rslang/parser/parser.test.ts +53 -0
  35. package/src/rslang/parser/syntax-errors/README.md +61 -0
  36. package/src/rslang/parser/syntax-errors/ast-utils.ts +112 -0
  37. package/src/rslang/parser/syntax-errors/classify.ts +70 -0
  38. package/src/rslang/parser/syntax-errors/context.ts +25 -0
  39. package/src/rslang/parser/syntax-errors/error-builders.ts +28 -0
  40. package/src/rslang/parser/syntax-errors/expression-errors.ts +255 -0
  41. package/src/rslang/parser/syntax-errors/function-calls.ts +76 -0
  42. package/src/rslang/parser/syntax-errors/generators.ts +315 -0
  43. package/src/rslang/parser/syntax-errors/incomplete-formal.ts +68 -0
  44. package/src/rslang/parser/syntax-errors/incomplete-operands.ts +184 -0
  45. package/src/rslang/parser/syntax-errors/index.ts +102 -0
  46. package/src/rslang/parser/syntax-errors/trailing-slot.ts +45 -0
  47. package/dist/rslang/parser/syntax-errors.d.ts +0 -14
  48. package/dist/rslang/parser/syntax-errors.js.map +0 -1
  49. package/src/rslang/parser/syntax-errors.ts +0 -929
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-errors-B6c2vsan.js","names":["TypeClassEnum"],"sources":["../src/rslang/parser/syntax-errors/context.ts","../src/rslang/parser/syntax-errors/ast-utils.ts","../src/rslang/parser/syntax-errors/function-calls.ts","../src/rslang/parser/syntax-errors/error-builders.ts","../src/rslang/parser/syntax-errors/generators.ts","../src/rslang/parser/syntax-errors/trailing-slot.ts","../src/rslang/parser/syntax-errors/incomplete-formal.ts","../src/rslang/parser/syntax-errors/incomplete-operands.ts","../src/rslang/parser/syntax-errors/classify.ts","../src/rslang/parser/syntax-errors/expression-errors.ts","../src/rslang/parser/syntax-errors/index.ts"],"sourcesContent":["/**\n * Types for the parse-error classifier pipeline.\n */\n\nimport type { AstNode } from '../../../parsing';\nimport type { RSErrorDescription } from '../../error';\nimport type { TypeClass } from '../../semantic/typification';\n\n/** Shared state passed through parse-error classifiers. */\nexport interface ClassifyContext {\n hasBracketErrors: boolean;\n expected?: TypeClass;\n}\n\n/** Classifies a single ERROR node into a specific syntax error, if possible. */\nexport type ErrorClassifier = (\n node: AstNode,\n expression: string,\n context: ClassifyContext\n) => RSErrorDescription | null;\n\n/** Skips classifiers that conflict with bracket-level diagnostics. */\nexport function whenNoBracketErrors(classifier: ErrorClassifier): ErrorClassifier {\n return (node, expression, context) => (context.hasBracketErrors ? null : classifier(node, expression, context));\n}\n","/**\n * AST navigation helpers and node-type predicates for classifiers.\n *\n * Predicates accept grammar terms **or** {@link TokenID} because `normalizeAST` runs before\n * error extraction and leaves `hasError` subtrees unnormalized — see `parser/README.md`.\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { Filter, Function, Function_decl, Logic_quantor, Predicate } from '../parser.terms';\nimport { TokenID } from '../token';\n\nexport function 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\nexport function 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\nexport function isDescendantOf(ancestor: AstNode, node: AstNode): boolean {\n let current: AstNode | null = node.parent;\n while (current !== null) {\n if (current === ancestor) {\n return true;\n }\n current = current.parent;\n }\n return false;\n}\n\nexport function subtreeHasError(node: AstNode): boolean {\n if (node.typeID === TokenID.ERROR) {\n return true;\n }\n return node.children.some(subtreeHasError);\n}\n\nexport function isFunctionDeclNode(node: AstNode): boolean {\n return node.typeID === Function_decl || node.typeID === TokenID.NT_FUNC_DEFINITION;\n}\n\nexport function isQuantifierNode(node: AstNode): boolean {\n return node.typeID === Logic_quantor;\n}\n\nexport function isFunctionNode(node: AstNode): boolean {\n return node.typeID === Function || node.typeID === TokenID.ID_FUNCTION;\n}\n\nexport function isPredicateNode(node: AstNode): boolean {\n return node.typeID === Predicate || node.typeID === TokenID.ID_PREDICATE;\n}\n\nexport function isFilterNode(node: AstNode): boolean {\n return node.typeID === Filter || node.typeID === TokenID.FILTER;\n}\n\nexport function findMatchingCloseBracket(expression: string, openPos: number): number {\n if (expression[openPos] !== '[') {\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\nexport function getErrorOperandNode(node: AstNode): AstNode | null {\n if (node.typeID === TokenID.ERROR) {\n return node;\n }\n if (node.children.length === 1) {\n return getErrorOperandNode(node.children[0]);\n }\n return null;\n}\n\nexport function isErrorPlaceholder(node: AstNode): boolean {\n if (node.typeID === TokenID.ERROR) {\n return true;\n }\n if (node.children.length === 0) {\n return false;\n }\n return node.children.every(child => isErrorPlaceholder(child));\n}\n","/**\n * Malformed calls: `Fi…(…)`, `F1` / `P1` without or with wrong argument brackets.\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { RSErrorCode, type RSErrorDescription } from '../../error';\n\nimport {\n findAncestor,\n findMatchingCloseBracket,\n findRelatedNode,\n isFilterNode,\n isFunctionNode,\n isPredicateNode\n} from './ast-utils';\nimport type { ErrorClassifier } from './context';\n\nexport const classifyFilterParenMismatch: ErrorClassifier = (node, expression) => {\n const filterNode = findAncestor(node, isFilterNode) ?? findRelatedNode(node, isFilterNode);\n if (filterNode === null || expression[filterNode.to] !== '(') {\n return null;\n }\n\n return {\n code: RSErrorCode.invalidFilterSyntax,\n from: filterNode.from,\n to: filterNode.to + 1\n };\n};\n\nexport const classifyGlobalFuncCall: ErrorClassifier = (node, expression) => {\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 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 if (/^\\s*$/.test(rest)) {\n return withoutArgs;\n }\n\n if (/^\\s*\\(/.test(rest)) {\n return {\n code: RSErrorCode.globalFuncParenCall,\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 return null;\n }\n\n const closeIdx = findMatchingCloseBracket(rest, openBracket[0].length - 1);\n if (closeIdx >= 0 && rest.slice(openBracket[0].length, closeIdx).trim().length === 0) {\n return withoutArgs;\n }\n\n return null;\n}\n","/**\n * Small helpers for building `RSErrorDescription` values from AST nodes.\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { type RSErrorCode, type RSErrorDescription } from '../../error';\n\nexport function errorAt(node: AstNode, code: RSErrorCode, params?: readonly string[]): RSErrorDescription {\n return {\n code,\n from: node.from,\n to: node.to,\n params\n };\n}\n\nexport function hasOnlyClosingSuffix(expression: string, from: number): boolean {\n const suffix = expression.slice(from).trim();\n return suffix.length === 0 || /^[\\]\\)\\}]*$/.test(suffix);\n}\n\nexport function sliceText(node: AstNode, expression: string): string {\n return expression.slice(node.from, node.to);\n}\n\nexport function isTextToken(node: AstNode, expression: string, text: string): boolean {\n return sliceText(node, expression) === text;\n}\n","/**\n * Incomplete generator bodies: declarative `D{…}`, imperative `I{…}`, recursive `R{…}`.\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { RSErrorCode, type RSErrorDescription } from '../../error';\nimport { Declarative, Imp_blocks, Imperative, Recursion, Setexpr } from '../parser.terms';\nimport { TokenID } from '../token';\n\nimport { findAncestor, isDescendantOf, isErrorPlaceholder, subtreeHasError } from './ast-utils';\nimport type { ErrorClassifier } from './context';\nimport { errorAt, isTextToken } from './error-builders';\n\nexport const classifyIncompleteGenerator: ErrorClassifier = (node, expression) =>\n detectIncompleteDeclarative(node, expression) ??\n detectIncompleteImperative(node, expression) ??\n detectIncompleteRecursion(node, expression);\n\nexport function isIncompleteGeneratorBodyCode(code: RSErrorCode): boolean {\n return (\n code === RSErrorCode.expectedDeclarativeBody ||\n code === RSErrorCode.expectedImperativeBody ||\n code === RSErrorCode.expectedRecursiveBody\n );\n}\n\ninterface GeneratorBodySlot {\n nodes: AstNode[];\n headerEndIndex: number;\n}\n\nfunction detectIncompleteDeclarative(node: AstNode, expression: string): RSErrorDescription | null {\n const generatorNode = findAncestor(\n node,\n target => target.typeID === Declarative || target.typeID === TokenID.NT_DECLARATIVE_EXPR\n );\n return detectIncompleteGeneratorBody(node, expression, generatorNode, RSErrorCode.expectedDeclarativeBody, slot =>\n isIncompleteDeclarativeBody(slot.nodes)\n );\n}\n\nfunction detectIncompleteImperative(node: AstNode, expression: string): RSErrorDescription | null {\n const generatorNode = findAncestor(\n node,\n target => target.typeID === Imperative || target.typeID === TokenID.NT_IMPERATIVE_EXPR\n );\n return detectIncompleteGeneratorBody(node, expression, generatorNode, RSErrorCode.expectedImperativeBody, slot =>\n isIncompleteImperativeBody(slot, expression)\n );\n}\n\nfunction detectIncompleteRecursion(node: AstNode, expression: string): RSErrorDescription | null {\n const generatorNode = findAncestor(node, target => target.typeID === Recursion);\n return detectIncompleteGeneratorBody(node, expression, generatorNode, RSErrorCode.expectedRecursiveBody, slot =>\n isIncompleteRecursionBody(slot.nodes)\n );\n}\n\nfunction detectIncompleteGeneratorBody(\n node: AstNode,\n expression: string,\n generatorNode: AstNode | null,\n code: RSErrorCode,\n isIncomplete: (slot: GeneratorBodySlot) => boolean\n): RSErrorDescription | null {\n if (generatorNode === null || expression.slice(generatorNode.to).trim().length > 0) {\n return null;\n }\n\n const slot = getGeneratorBodySlot(generatorNode, expression);\n if (slot === null || !isIncomplete(slot) || !generatorHeaderIsValid(generatorNode, expression, slot.headerEndIndex)) {\n return null;\n }\n\n if (!isErrorInBodySlot(node, slot, generatorNode)) {\n return null;\n }\n\n return errorAt(node, code);\n}\n\nfunction getGeneratorBodySlot(generatorNode: AstNode, expression: string): GeneratorBodySlot | null {\n if (generatorNode.typeID === Declarative || generatorNode.typeID === TokenID.NT_DECLARATIVE_EXPR) {\n return getDeclarativeBodySlot(generatorNode, expression);\n }\n if (generatorNode.typeID === Imperative || generatorNode.typeID === TokenID.NT_IMPERATIVE_EXPR) {\n return getImperativeBodySlot(generatorNode, expression);\n }\n if (generatorNode.typeID === Recursion) {\n return getRecursionBodySlot(generatorNode, expression);\n }\n return null;\n}\n\nfunction getDeclarativeBodySlot(declNode: AstNode, expression: string): GeneratorBodySlot | null {\n const pipeIndex = declNode.children.findIndex(child => isTextToken(child, expression, '|'));\n if (pipeIndex >= 0) {\n return {\n nodes: contentChildren(declNode, expression, pipeIndex + 1),\n headerEndIndex: pipeIndex + 1\n };\n }\n\n const domainNode = findDeclarativeDomain(declNode, expression);\n if (domainNode === null) {\n return null;\n }\n\n const domainIndex = declNode.children.indexOf(domainNode);\n return {\n nodes: contentChildren(declNode, expression, domainIndex + 1),\n headerEndIndex: domainIndex + 1\n };\n}\n\nfunction getImperativeBodySlot(impNode: AstNode, expression: string): GeneratorBodySlot | null {\n const pipeIndex = impNode.children.findIndex(child => isTextToken(child, expression, '|'));\n if (pipeIndex >= 0) {\n return {\n nodes: contentChildren(impNode, expression, pipeIndex + 1),\n headerEndIndex: pipeIndex + 1\n };\n }\n\n const tupleNode = findImperativeTuple(impNode);\n if (tupleNode === null) {\n return null;\n }\n\n const tupleIndex = impNode.children.indexOf(tupleNode);\n return {\n nodes: contentChildren(impNode, expression, tupleIndex + 1),\n headerEndIndex: tupleIndex + 1\n };\n}\n\nfunction getRecursionBodySlot(recNode: AstNode, expression: string): GeneratorBodySlot | null {\n const initNode = findRecursionInit(recNode, expression);\n if (initNode === null) {\n return null;\n }\n\n const initIndex = recNode.children.indexOf(initNode);\n const afterInit = contentChildren(recNode, expression, initIndex + 1);\n const lastPipeIndex = findLastPipeIndex(afterInit, expression);\n if (lastPipeIndex < 0) {\n return {\n nodes: afterInit,\n headerEndIndex: initIndex + 1\n };\n }\n\n return {\n nodes: afterInit.slice(lastPipeIndex + 1),\n headerEndIndex: recNode.children.indexOf(afterInit[lastPipeIndex]) + 1\n };\n}\n\nfunction contentChildren(generatorNode: AstNode, expression: string, fromIndex: number): AstNode[] {\n return generatorNode.children.slice(fromIndex).filter(child => !isClosingBrace(child, expression));\n}\n\nfunction findDeclarativeDomain(declNode: AstNode, expression: string): AstNode | null {\n const inIndex = declNode.children.findIndex(child => isTextToken(child, expression, '∈'));\n if (inIndex < 0) {\n return null;\n }\n\n for (let index = inIndex + 1; index < declNode.children.length; index++) {\n const child = declNode.children[index];\n if (isTextToken(child, expression, '|') || isClosingBrace(child, expression)) {\n break;\n }\n if (child.typeID === Setexpr) {\n return child;\n }\n }\n\n return null;\n}\n\nfunction findImperativeTuple(impNode: AstNode): AstNode | null {\n for (const child of impNode.children) {\n if (child.typeID === Setexpr) {\n return child;\n }\n }\n return null;\n}\n\nfunction findLastPipeIndex(nodes: AstNode[], expression: string): number {\n for (let index = nodes.length - 1; index >= 0; index--) {\n if (isTextToken(nodes[index], expression, '|')) {\n return index;\n }\n }\n return -1;\n}\n\nfunction generatorHeaderIsValid(generatorNode: AstNode, expression: string, headerEndIndex: number): boolean {\n for (let index = 0; index < headerEndIndex; index++) {\n const child = generatorNode.children[index];\n if (child.typeID === TokenID.ERROR) {\n return false;\n }\n if (isStructuralGeneratorToken(child, expression)) {\n continue;\n }\n if (subtreeHasError(child)) {\n return false;\n }\n }\n return true;\n}\n\nfunction isIncompleteDeclarativeBody(nodes: AstNode[]): boolean {\n return isEmptyOrErrorOnlyBody(nodes);\n}\n\nfunction isIncompleteImperativeBody(slot: GeneratorBodySlot, expression: string): boolean {\n if (slot.nodes.length === 0) {\n return true;\n }\n if (slot.nodes.length === 1 && slot.nodes[0].typeID === Imp_blocks) {\n return isImpBlocksIncomplete(slot.nodes[0], expression);\n }\n return isEmptyOrErrorOnlyBody(slot.nodes);\n}\n\nfunction isIncompleteRecursionBody(nodes: AstNode[]): boolean {\n return isEmptyOrErrorOnlyBody(nodes);\n}\n\nfunction isEmptyOrErrorOnlyBody(nodes: AstNode[]): boolean {\n if (nodes.length === 0) {\n return true;\n }\n if (nodes.length === 1) {\n return isErrorPlaceholder(nodes[0]);\n }\n return false;\n}\n\nfunction isImpBlocksIncomplete(blocksNode: AstNode, expression: string): boolean {\n if (blocksNode.children.length === 0) {\n return true;\n }\n\n const lastChild = blocksNode.children[blocksNode.children.length - 1];\n if (lastChild.typeID === TokenID.ERROR) {\n return true;\n }\n if (isTextToken(lastChild, expression, ';')) {\n return true;\n }\n if (lastChild.typeID === Setexpr && isErrorPlaceholder(lastChild)) {\n return true;\n }\n\n return false;\n}\n\nfunction isErrorInBodySlot(errorNode: AstNode, slot: GeneratorBodySlot, generatorNode: AstNode): boolean {\n if (slot.nodes.length === 0) {\n const bodyStart = generatorNode.children[slot.headerEndIndex]?.from ?? generatorNode.from;\n return errorNode.from >= bodyStart;\n }\n\n for (const bodyNode of slot.nodes) {\n if (errorNode === bodyNode || isDescendantOf(bodyNode, errorNode)) {\n if (isErrorPlaceholder(bodyNode)) {\n return true;\n }\n if (bodyNode.typeID === Imp_blocks && isImpBlocksTailError(bodyNode, errorNode)) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nfunction isImpBlocksTailError(blocksNode: AstNode, errorNode: AstNode): boolean {\n const lastChild = blocksNode.children[blocksNode.children.length - 1];\n return lastChild.typeID === TokenID.ERROR && (errorNode === lastChild || isDescendantOf(lastChild, errorNode));\n}\n\nfunction findRecursionInit(recursionNode: AstNode, expression: string): AstNode | null {\n const assignIndex = recursionNode.children.findIndex(child => isTextToken(child, expression, ':='));\n if (assignIndex < 0) {\n return null;\n }\n\n for (let index = assignIndex + 1; index < recursionNode.children.length; index++) {\n const child = recursionNode.children[index];\n if (child.typeID === TokenID.ERROR) {\n break;\n }\n if (isTextToken(child, expression, '|') || isClosingBrace(child, expression)) {\n continue;\n }\n return child;\n }\n\n return null;\n}\n\nfunction isClosingBrace(node: AstNode, expression: string): boolean {\n return node.typeID !== TokenID.ERROR && isTextToken(node, expression, '}');\n}\n\nfunction isStructuralGeneratorToken(node: AstNode, expression: string): boolean {\n const text = expression.slice(node.from, node.to);\n return text === '{' || text === '}' || text === '|' || text === '∈' || text === ':=' || text === ';';\n}\n","/**\n * Reusable pattern: container header is valid, last child is `ERROR`, input ends here.\n *\n * @see incomplete-formal.ts — function declarations, quantifiers\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { type RSErrorCode, type RSErrorDescription } from '../../error';\nimport { TokenID } from '../token';\n\nimport { errorAt } from './error-builders';\n\nexport function detectTrailingErrorSlot(\n node: AstNode,\n expression: string,\n container: AstNode | null,\n options: {\n headerValid?: (container: AstNode) => boolean;\n code: RSErrorCode | ((container: AstNode, bodyChild: AstNode) => RSErrorCode | null);\n }\n): RSErrorDescription | null {\n if (container === null) {\n return null;\n }\n\n const bodyChild = container.children[container.children.length - 1];\n if (bodyChild?.typeID !== TokenID.ERROR || node !== bodyChild) {\n return null;\n }\n\n if (expression.slice(container.to).trim().length > 0) {\n return null;\n }\n\n if (options.headerValid !== undefined && !options.headerValid(container)) {\n return null;\n }\n\n const code = typeof options.code === 'function' ? options.code(container, bodyChild) : options.code;\n if (code === null) {\n return null;\n }\n\n return errorAt(bodyChild, code);\n}\n","/**\n * Incomplete formal headers: `[α∈…]` declarations and quantifiers (`∀α∈…`).\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { RSErrorCode, type RSErrorDescription } from '../../error';\nimport { TypeClass as TypeClassEnum } from '../../semantic/typification';\nimport { Arguments, Variable_pack } from '../parser.terms';\nimport { TokenID } from '../token';\n\nimport { findAncestor, isFunctionDeclNode, isQuantifierNode, subtreeHasError } from './ast-utils';\nimport type { ClassifyContext, ErrorClassifier } from './context';\nimport { detectTrailingErrorSlot } from './trailing-slot';\n\nexport const classifyIncompleteFormal: ErrorClassifier = (node, expression, context) =>\n detectIncompleteFunctionDecl(node, expression, context.expected) ?? detectIncompleteQuantifier(node, expression);\n\nfunction detectIncompleteFunctionDecl(\n node: AstNode,\n expression: string,\n expected?: ClassifyContext['expected']\n): RSErrorDescription | null {\n return detectTrailingErrorSlot(node, expression, findAncestor(node, isFunctionDeclNode), {\n headerValid: container => {\n const argsNode = container.children.find(\n child => child.typeID === Arguments || child.typeID === TokenID.NT_ARGUMENTS\n );\n return argsNode !== undefined && !subtreeHasError(argsNode);\n },\n code: () => incompleteFormalExpressionCode(expected)\n });\n}\n\nfunction incompleteFormalExpressionCode(expected?: ClassifyContext['expected']): 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 detectIncompleteQuantifier(node: AstNode, expression: string): RSErrorDescription | null {\n return detectTrailingErrorSlot(node, expression, findAncestor(node, isQuantifierNode), {\n headerValid: container => {\n const varPack = container.children.find(\n child => child.typeID === Variable_pack || child.typeID === TokenID.NT_ENUM_DECL\n );\n return varPack !== undefined && !subtreeHasError(varPack);\n },\n code: (container, bodyChild) => {\n const inIndex = container.children.findIndex(child => expression.slice(child.from, child.to) === '∈');\n if (inIndex < 0) {\n return RSErrorCode.expectedQuantifierDomain;\n }\n\n const domainChild = container.children[inIndex + 1];\n if (domainChild === undefined || domainChild === bodyChild || subtreeHasError(domainChild)) {\n return RSErrorCode.expectedQuantifierDomain;\n }\n\n return RSErrorCode.expectedQuantifierBody;\n }\n });\n}\n","/**\n * Incomplete operators and bracket argument lists (`P1[S1, ]`).\n *\n * Tuple enums `(α,β,)` intentionally stay `unknownSyntax` — not `expectedArgument`.\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { RSErrorCode, type RSErrorDescription } from '../../error';\nimport { Boolean, Expr_enum_min2, Logic_binary, Logic_predicates, Logic_unary, Setexpr_binary } from '../parser.terms';\nimport { TokenID } from '../token';\n\nimport {\n findAncestor,\n findMatchingCloseBracket,\n getErrorOperandNode,\n isFilterNode,\n isFunctionNode,\n isPredicateNode,\n subtreeHasError\n} from './ast-utils';\nimport type { ErrorClassifier } from './context';\nimport { errorAt, hasOnlyClosingSuffix, isTextToken, sliceText } from './error-builders';\n\nexport const classifyIncompleteOperands: ErrorClassifier = (node, expression) =>\n detectIncompleteUnaryOperand(node, expression) ??\n detectIncompleteBinaryOperand(node, expression) ??\n detectIncompleteBooleanOperand(node, expression);\n\nexport const classifyIncompleteArgument: ErrorClassifier = (node, expression) =>\n detectIncompleteArgument(node, expression);\n\nfunction detectIncompleteUnaryOperand(node: AstNode, expression: string): RSErrorDescription | null {\n const unaryNode = findAncestor(node, target => target.typeID === Logic_unary);\n if (unaryNode === null) {\n return null;\n }\n\n const operandChild = unaryNode.children[unaryNode.children.length - 1];\n if (operandChild?.typeID !== TokenID.ERROR || node !== operandChild) {\n return null;\n }\n\n if (expression.slice(unaryNode.to).trim().length > 0) {\n return null;\n }\n\n const operatorChild = unaryNode.children[0];\n if (operatorChild === undefined || operatorChild === operandChild) {\n return null;\n }\n\n if (!isTextToken(operatorChild, expression, '¬')) {\n return null;\n }\n\n return errorAt(operandChild, RSErrorCode.expectedUnaryOperand);\n}\n\nfunction detectIncompleteBinaryOperand(node: AstNode, expression: string): RSErrorDescription | null {\n const binaryNode = findAncestor(\n node,\n target => target.typeID === Logic_binary || target.typeID === Logic_predicates || target.typeID === Setexpr_binary\n );\n if (binaryNode === null) {\n return null;\n }\n\n const operandChild = binaryNode.children[binaryNode.children.length - 1];\n if (operandChild?.typeID !== TokenID.ERROR || node !== operandChild) {\n return null;\n }\n\n if (expression.slice(binaryNode.to).trim().length > 0) {\n return null;\n }\n\n if (binaryNode.children.length < 2) {\n return null;\n }\n\n const leftChild = binaryNode.children[0];\n if (leftChild.typeID === TokenID.ERROR || subtreeHasError(leftChild)) {\n return null;\n }\n\n return errorAt(operandChild, RSErrorCode.expectedRightOperand);\n}\n\nfunction detectIncompleteBooleanOperand(node: AstNode, expression: string): RSErrorDescription | null {\n const booleanNode = findAncestor(node, target => target.typeID === Boolean);\n if (booleanNode === null) {\n return null;\n }\n\n const operandChild = findTrailingErrorOperand(booleanNode, expression);\n if (operandChild === null || node !== operandChild) {\n return null;\n }\n\n if (!hasOnlyClosingSuffix(expression, booleanNode.to)) {\n return null;\n }\n\n return errorAt(operandChild, RSErrorCode.expectedRightOperand);\n}\n\nfunction detectIncompleteArgument(node: AstNode, expression: string): RSErrorDescription | null {\n const enumNode = findAncestor(node, target => target.typeID === Expr_enum_min2);\n if (enumNode === null || !isLegitimateArgumentEnum(enumNode, expression)) {\n return null;\n }\n\n const errorChild = findEnumArgumentError(enumNode, expression);\n if (errorChild === null || node !== errorChild || !hasOnlyClosingSuffix(expression, enumNode.to)) {\n return null;\n }\n\n return errorAt(errorChild, RSErrorCode.expectedArgument);\n}\n\nfunction findTrailingErrorOperand(container: AstNode, expression: string): AstNode | null {\n for (let index = container.children.length - 1; index >= 0; index--) {\n const child = container.children[index];\n if (isOperandStructuralToken(child, expression)) {\n continue;\n }\n return getErrorOperandNode(child);\n }\n return null;\n}\n\nfunction findEnumArgumentError(enumNode: AstNode, expression: string): AstNode | null {\n for (const child of enumNode.children) {\n if (isTextToken(child, expression, ',')) {\n continue;\n }\n const errorNode = getErrorOperandNode(child);\n if (errorNode !== null) {\n return errorNode;\n }\n }\n return null;\n}\n\nfunction isOperandStructuralToken(node: AstNode, expression: string): boolean {\n const text = sliceText(node, expression);\n return text === '(' || text === ')' || text === 'ℬ';\n}\n\nfunction isLegitimateArgumentEnum(enumNode: AstNode, expression: string): boolean {\n return findCallHostForBracketEnum(enumNode, expression) !== null;\n}\n\nfunction findCallHostForBracketEnum(enumNode: AstNode, expression: string): AstNode | null {\n let current: AstNode | null = enumNode.parent;\n while (current !== null) {\n for (const child of current.children) {\n if (!isFunctionNode(child) && !isPredicateNode(child) && !isFilterNode(child)) {\n continue;\n }\n if (isEnumInCallBrackets(enumNode, child, expression)) {\n return child;\n }\n }\n current = current.parent;\n }\n return null;\n}\n\nfunction isEnumInCallBrackets(enumNode: AstNode, nameNode: AstNode, expression: string): boolean {\n const rest = expression.slice(nameNode.to);\n const match = /^\\s*\\[/.exec(rest);\n if (match === null) {\n return false;\n }\n\n const openPos = nameNode.to + match.index + match[0].indexOf('[');\n const closePos = findMatchingCloseBracket(expression, openPos);\n if (closePos < 0) {\n return false;\n }\n\n return enumNode.from > openPos && enumNode.from < closePos;\n}\n","/**\n * Parse-error classification: ordered classifier chain and P8400 fallback.\n *\n * Register new detectors in `PARSE_ERROR_CLASSIFIERS` (first match wins).\n */\n\nimport type { AstNode } from '../../../parsing';\nimport { RSErrorCode, type RSErrorDescription } from '../../error';\nimport { Variable } from '../parser.terms';\n\nimport type { ClassifyContext, ErrorClassifier } from './context';\nimport { whenNoBracketErrors } from './context';\nimport { classifyFilterParenMismatch, classifyGlobalFuncCall } from './function-calls';\nimport { classifyIncompleteGenerator } from './generators';\nimport { classifyIncompleteFormal } from './incomplete-formal';\nimport { classifyIncompleteArgument, classifyIncompleteOperands } from './incomplete-operands';\n\nconst PARSE_ERROR_CLASSIFIERS: ErrorClassifier[] = [\n classifyIncompleteFormal,\n classifyIncompleteGenerator,\n whenNoBracketErrors(classifyIncompleteOperands),\n whenNoBracketErrors(classifyIncompleteArgument),\n classifyFilterParenMismatch,\n classifyGlobalFuncCall\n];\n\n/** Runs classifiers in priority order for one `ERROR` AST node. */\nexport function classifyParseError(\n node: AstNode,\n expression: string,\n context: ClassifyContext\n): RSErrorDescription | null {\n for (const classifier of PARSE_ERROR_CLASSIFIERS) {\n const error = classifier(node, expression, context);\n if (error !== null) {\n return error;\n }\n }\n return null;\n}\n\n/** Default rules when no classifier matched: `expectedLocal` or `unknownSyntax`. */\nexport function classifyFallbackError(\n node: AstNode,\n ignoreUnknownErrors: boolean\n): { error: RSErrorDescription; target: AstNode } | null {\n const parent = node.parent;\n if (parent === null) {\n return ignoreUnknownErrors\n ? null\n : { error: { code: RSErrorCode.unknownSyntax, from: node.from, to: node.to }, target: node };\n }\n\n if (parent.typeID === Variable) {\n return {\n error: { code: RSErrorCode.expectedLocal, from: parent.from, to: parent.to },\n target: parent\n };\n }\n\n if (ignoreUnknownErrors) {\n return null;\n }\n\n const target = node.from === node.to ? parent : node;\n return {\n error: { code: RSErrorCode.unknownSyntax, from: target.from, to: target.to },\n target\n };\n}\n","/**\n * Expression-level diagnostics (no AST required) and error deduplication.\n */\n\nimport { RSErrorCode, type RSErrorDescription } from '../../error';\n\ntype OpenBracket = '(' | '[' | '{';\ntype CloseBracket = ')' | ']' | '}';\n\ninterface BracketFrame {\n bracket: OpenBracket;\n index: number;\n}\n\nconst ALLOWED_EXPRESSION_CHARS = buildAllowedExpressionChars();\n\nfunction buildAllowedExpressionChars(): Set<string> {\n const chars = new Set<string>();\n for (const chunk of [\n '0123456789',\n 'abcdefghijklmnopqrstuvwxyz',\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',\n '_',\n '∅¬∀∃⇔⇒∨&ℬ+-*∪\\\\∆∩×∈∉⊆⊄⊂<>≥≤≠=,:;|[]{}()'\n ]) {\n for (const symbol of chunk) {\n chars.add(symbol);\n }\n }\n for (let codePoint = 0x03b1; codePoint <= 0x03c9; codePoint++) {\n chars.add(String.fromCodePoint(codePoint));\n }\n return chars;\n}\n\nfunction isAllowedExpressionChar(symbol: string): boolean {\n return /\\s/u.test(symbol) || ALLOWED_EXPRESSION_CHARS.has(symbol);\n}\n\nexport function extractForbiddenCharacterErrors(expression: string): RSErrorDescription[] {\n const errors: RSErrorDescription[] = [];\n let pos = 0;\n\n while (pos < expression.length) {\n const symbol = expression[pos];\n if (isAllowedExpressionChar(symbol)) {\n pos++;\n continue;\n }\n\n const start = pos;\n while (pos < expression.length && !isAllowedExpressionChar(expression[pos])) {\n pos++;\n }\n\n errors.push({\n code: RSErrorCode.forbiddenCharacter,\n from: start,\n to: pos,\n params: [expression.slice(start, pos)]\n });\n }\n\n return errors;\n}\n\nexport function 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\nexport function 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 const filtered = result.filter(\n error => error.code !== RSErrorCode.unknownSyntax || !specific.some(item => rangesOverlap(error, item))\n );\n return collapseContiguousUnknownSyntax(filtered);\n}\n\nfunction collapseContiguousUnknownSyntax(errors: RSErrorDescription[]): RSErrorDescription[] {\n const unknowns = errors.filter(error => error.code === RSErrorCode.unknownSyntax);\n if (unknowns.length <= 1) {\n return errors;\n }\n\n const others = errors.filter(error => error.code !== RSErrorCode.unknownSyntax);\n const sorted = [...unknowns].sort((left, right) => left.from - right.from || left.to - right.to);\n const merged: RSErrorDescription[] = [];\n\n let clusterFrom = sorted[0].from;\n let clusterTo = sorted[0].to;\n\n for (let index = 1; index < sorted.length; index++) {\n const error = sorted[index];\n if (error.from <= clusterTo) {\n clusterTo = Math.max(clusterTo, error.to);\n continue;\n }\n\n merged.push({ code: RSErrorCode.unknownSyntax, from: clusterFrom, to: clusterTo });\n clusterFrom = error.from;\n clusterTo = error.to;\n }\n\n merged.push({ code: RSErrorCode.unknownSyntax, from: clusterFrom, to: clusterTo });\n return [...others, ...merged];\n}\n\nfunction rangesOverlap(a: RSErrorDescription, b: RSErrorDescription): boolean {\n return a.from < b.to && b.from < a.to;\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","/**\n * Syntax error extraction — public entry point.\n *\n * Expects the **hybrid** AST produced by `normalizeAST` (see `parser/README.md`).\n * See {@link ./README.md} for pipeline, classifier order, and how to add codes.\n *\n * @module rslang/parser/syntax-errors\n */\n\nimport { type AstNode, visitAstDFS } from '../../../parsing';\nimport { annotateError } from '../../ast-annotations';\nimport { type ErrorReporter, type RSErrorDescription } from '../../error';\nimport { type TypeClass } from '../../semantic/typification';\nimport { TokenID } from '../token';\n\nimport { classifyFallbackError, classifyParseError } from './classify';\nimport { deduplicateErrors, extractBracketErrors, extractForbiddenCharacterErrors } from './expression-errors';\nimport { isIncompleteGeneratorBodyCode } from './generators';\n\n/** When set, refines incomplete formal headers (`[α∈…]`, quantifiers). */\nexport interface SyntaxErrorOptions {\n expected?: TypeClass;\n}\n\n/**\n * Walks a parsed expression AST and reports syntax errors.\n *\n * @param ast - Root AST from `buildTree(parser.parse(expression))`\n * @param expression - Original source text (positions must match the AST)\n * @param reporter - Called once per deduplicated error\n * @param annotateErrors - When true, also calls `annotateError` on the triggering node\n * @param options - Optional typification hint for incomplete formal expressions\n */\nexport function extractSyntaxErrors(\n ast: AstNode,\n expression: string,\n reporter: ErrorReporter,\n annotateErrors: boolean = false,\n options?: SyntaxErrorOptions\n) {\n const forbiddenErrors = extractForbiddenCharacterErrors(expression);\n if (forbiddenErrors.length > 0) {\n for (const error of forbiddenErrors) {\n reporter(error);\n if (annotateErrors) {\n annotateError(ast, error.code, error.params);\n }\n }\n return;\n }\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 const hasBracketErrors = bracketError !== null;\n visitAstDFS(ast, node => extractInternal(node, expression, collect, hasBracketErrors, options));\n\n const hasIncompleteGenerator = collected.some(error => isIncompleteGeneratorBodyCode(error.code));\n if (bracketError !== null && !hasIncompleteGenerator) {\n collect(bracketError, ast);\n }\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\nfunction extractInternal(\n node: AstNode,\n expression: string,\n collect: (error: RSErrorDescription, target: AstNode) => void,\n hasBracketErrors: boolean,\n options?: SyntaxErrorOptions\n) {\n if (node.typeID !== TokenID.ERROR) {\n return;\n }\n\n const classified = classifyParseError(node, expression, { hasBracketErrors, expected: options?.expected });\n if (classified !== null) {\n collect(classified, node);\n return;\n }\n\n const fallback = classifyFallbackError(node, hasBracketErrors);\n if (fallback !== null) {\n collect(fallback.error, fallback.target);\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,oBAAoB,YAA8C;CAChF,QAAQ,MAAM,YAAY,YAAa,QAAQ,mBAAmB,OAAO,WAAW,MAAM,YAAY,OAAO;AAC/G;;;ACbA,SAAgB,aAAa,MAAe,WAAuD;CACjG,IAAI,UAA0B;CAC9B,OAAO,YAAY,MAAM;EACvB,IAAI,UAAU,OAAO,GACnB,OAAO;EAET,UAAU,QAAQ;CACpB;CACA,OAAO;AACT;AAEA,SAAgB,gBAAgB,MAAe,WAAyD;CACtG,IAAI,UAA0B,KAAK;CACnC,OAAO,YAAY,MAAM;EACvB,KAAK,MAAM,SAAS,QAAQ,UAC1B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K,MAAM,SAAS,iBAAiB;GACnC,SAAS,KAAK;GACd,IAAI,gBACF,cAAc,KAAK,MAAM,MAAM,MAAM,MAAM;EAE/C;EACA;CACF;CAEA,MAAM,YAAkC,CAAC;CACzC,MAAM,oCAAoB,IAAI,IAAiC;CAC/D,MAAM,WAAW,OAA2B,WAAqB;EAC/D,UAAU,KAAK,KAAK;EACpB,IAAI,WAAW,QACb,kBAAkB,IAAI,OAAO,MAAM;CAEvC;CAEA,MAAM,eAAe,qBAAqB,UAAU;CACpD,MAAM,mBAAmB,iBAAiB;CAC1C,YAAY,MAAK,SAAQ,gBAAgB,MAAM,YAAY,SAAS,kBAAkB,OAAO,CAAC;CAE9F,MAAM,yBAAyB,UAAU,MAAK,UAAS,8BAA8B,MAAM,IAAI,CAAC;CAChG,IAAI,iBAAiB,QAAQ,CAAC,wBAC5B,QAAQ,cAAc,GAAG;CAG3B,KAAK,MAAM,SAAS,kBAAkB,SAAS,GAAG;EAChD,SAAS,KAAK;EACd,IAAI,gBAAgB;GAClB,MAAM,SAAS,kBAAkB,IAAI,KAAK;GAC1C,IAAI,WAAW,QACb,cAAc,QAAQ,MAAM,MAAM,MAAM,MAAM;EAElD;CACF;AACF;AAEA,SAAS,gBACP,MACA,YACA,SACA,kBACA,SACA;CACA,IAAI,KAAK,WAAW,QAAQ,OAC1B;CAGF,MAAM,aAAa,mBAAmB,MAAM,YAAY;EAAE;EAAkB,UAAU,SAAS;CAAS,CAAC;CACzG,IAAI,eAAe,MAAM;EACvB,QAAQ,YAAY,IAAI;EACxB;CACF;CAEA,MAAM,WAAW,sBAAsB,MAAM,gBAAgB;CAC7D,IAAI,aAAa,MACf,QAAQ,SAAS,OAAO,SAAS,MAAM;AAE3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsconcept/domain",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Shared TypeScript domain for RS language, RSForm, RSModel, RSEngine, OSS, and concept-text helpers.",
5
5
  "license": "MIT",
6
6
  "author": "IRBorisov",
@@ -41,6 +41,11 @@ export const RSErrorCode = {
41
41
  expectedDeclarativeBody: 0x841c, // 33820
42
42
  expectedImperativeBody: 0x841d, // 33821
43
43
  expectedRecursiveBody: 0x841e, // 33822
44
+ expectedQuantifierDomain: 0x841f, // 33823
45
+ expectedRightOperand: 0x8420, // 33824
46
+ expectedUnaryOperand: 0x8421, // 33825
47
+ globalFuncParenCall: 0x8422, // 33826
48
+ expectedArgument: 0x8423, // 33827
44
49
  expectedLocal: 0x8415, // 33813
45
50
  expectedType: 0x8416, // 33814
46
51
 
@@ -56,7 +56,7 @@ export function labelToken(id: TokenID): string {
56
56
  return text ?? 'UNKNOWN TOKEN: ' + String(id);
57
57
  }
58
58
 
59
- /** Generates label for {@link AstNodeBase}. */
59
+ /** Generates label for {@link AstNodeBase}. Unnormalized grammar nodes fall through to `node.data.value` (Lezer name). */
60
60
  export function labelRSLangNode(node: AstNodeBase): string {
61
61
  // prettier-ignore
62
62
  switch (node.typeID) {
@@ -0,0 +1,73 @@
1
+ # RSLang parser pipeline
2
+
3
+ Lezer grammar (`rslang.grammar`) → generated `parser.ts` / `parser.terms.ts` → `buildTree` →
4
+ `normalizeAST` → analysis, diagnostics, evaluation.
5
+
6
+ ## Hybrid AST (intentional)
7
+
8
+ After `buildTree`, every node carries a numeric `typeID`. There are **two namespaces**:
9
+
10
+ | Namespace | Source | Examples | Used when |
11
+ | --------------- | ------------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------- |
12
+ | Grammar terms | `parser.terms.ts` (Lezer) | `Setexpr`, `Declarative`, `Logic_quantor`, `Function_decl` | Raw parse tree; **unchanged** subtrees that still contain errors |
13
+ | Semantic tokens | `token.ts` (`TokenID`) | `NT_DECLARATIVE_EXPR`, `QUANTOR_UNIVERSAL`, `ID_FUNCTION`, `PLUS` | Successfully normalized subtrees |
14
+
15
+ `normalizeAST` walks the tree and rewrites grammar nodes into `TokenID` shapes (flatten wrappers,
16
+ promote literals, attach operator tokens, etc.). It **skips any node whose subtree contains an
17
+ `ERROR` node** (`hasError === true`):
18
+
19
+ ```ts
20
+ if (node.hasError) {
21
+ return;
22
+ }
23
+ ```
24
+
25
+ So a single AST is often **hybrid**: valid fragments are already `TokenID` nodes; broken branches
26
+ keep grammar `typeID`s and may still contain `[ERROR]` children. This is deliberate — not a bug
27
+ and not an intermediate build artifact.
28
+
29
+ ### Why normalize before syntax errors
30
+
31
+ `RSLangAnalyzer.parse()` always runs `normalizeAST` first, then `extractSyntaxErrors` on the same
32
+ tree (`semantic/analyzer.ts`). Reasons:
33
+
34
+ 1. **One tree for the whole pipeline** — type/value auditors, evaluator, and the Portal AST view
35
+ all consume the same structure.
36
+ 2. **Better diagnostics on valid fragments** — e.g. a malformed tail does not block normalizing
37
+ `F1` to `ID_FUNCTION` or `+` to `PLUS` in the rest of the expression.
38
+ 3. **Classifiers see both layers** — predicates in `syntax-errors/ast-utils.ts` accept grammar
39
+ _or_ token ids (`Function_decl` / `NT_FUNC_DEFINITION`, `Declarative` / `NT_DECLARATIVE_EXPR`, …)
40
+ because error-containing ancestors are never rewritten.
41
+
42
+ Do **not** reorder to “errors first, normalize second” without reworking every classifier and the
43
+ 217+ parser tests.
44
+
45
+ ### What users see on the Portal
46
+
47
+ **Syntax tree** (`tx.rsexpression.ast`, RS expression editor):
48
+
49
+ - Default click: `checkFull` → `flattenAst(parse.ast)` → graph labeled with `labelRSLangNode`.
50
+ - Normalized nodes: `DECLARATIVE`, `CALL`, `∀`, identifiers, `[ERROR]`, etc.
51
+ - Skipped subtrees: Lezer names from `node.data.value` (`Setexpr`, `Declarative`, …) — the
52
+ hybrid shape is visible next to semantic labels.
53
+ - Ctrl/Cmd+click (debug): raw `buildTree(parser.parse(text))` **without** `normalizeAST` — pure
54
+ grammar tree.
55
+
56
+ A fully valid expression normalizes entirely to `TokenID`; hybrid trees appear when the expression
57
+ has syntax errors (or is incomplete), which matches what error reporting and the tree view show.
58
+
59
+ ## Module map
60
+
61
+ | Module | Role |
62
+ | ------------------------------ | ------------------------------------------------------ |
63
+ | `rslang.grammar` | Syntax definition; run `npm run generate` after edits |
64
+ | `parser.ts`, `parser.terms.ts` | Generated LR parser (do not hand-edit) |
65
+ | `token.ts` | `TokenID` enum for normalized AST |
66
+ | `normalize.ts` | Grammar → `TokenID` transform |
67
+ | `syntax-errors/` | Syntax diagnostics (`0x8400`–`0x8423`); see its README |
68
+ | `expression-generator.ts` | Normalized AST → source text (inverse of normalize) |
69
+
70
+ ## Tests
71
+
72
+ - `parser.test.ts` — Lezer tree shape (`printTree`) and error codes on the **normalized** AST.
73
+ - `normalize.test.ts` — normalized tree shape (`printAst` + `labelRSLangNode`).
@@ -1,5 +1,9 @@
1
1
  /**
2
- * Module: Transforming AST to a simple form.
2
+ * Rewrites the Lezer parse tree into semantic {@link TokenID} nodes.
3
+ *
4
+ * Skips any node with `hasError` (subtree contains a parse `ERROR`). Those branches keep grammar
5
+ * `typeID`s from `parser.terms` — the tree becomes **hybrid** until the expression is valid.
6
+ * See `parser/README.md` (hybrid AST) and `syntax-errors/README.md`.
3
7
  */
4
8
 
5
9
  import { type AstNode, visitAstDFS } from '../../parsing';
@@ -96,6 +96,8 @@ const testIncompleteFormalData = [
96
96
  ['[ξ∈X1]', TypeClass.logic, { code: RSErrorCode.expectedLogicBody, from: 6, to: 6 }],
97
97
  ['∀α∈X1', TypeClass.logic, { code: RSErrorCode.expectedQuantifierBody, from: 5, to: 5 }],
98
98
  ['∃β∈S2', TypeClass.logic, { code: RSErrorCode.expectedQuantifierBody, from: 5, to: 5 }],
99
+ ['∀α', TypeClass.logic, { code: RSErrorCode.expectedQuantifierDomain, from: 2, to: 2 }],
100
+ ['∀α∈', TypeClass.logic, { code: RSErrorCode.expectedQuantifierDomain, from: 3, to: 3 }],
99
101
  ['D{ξ∈X1 |', TypeClass.function, { code: RSErrorCode.expectedDeclarativeBody, from: 8, to: 8 }],
100
102
  ['D{ξ∈X1 |}', TypeClass.function, { code: RSErrorCode.expectedDeclarativeBody, from: 8, to: 8 }],
101
103
  ['D{ξ∈X1}', TypeClass.function, { code: RSErrorCode.expectedDeclarativeBody, from: 6, to: 7 }],
@@ -107,6 +109,35 @@ const testIncompleteFormalData = [
107
109
  ['R{ξ:=D1}', TypeClass.function, { code: RSErrorCode.expectedRecursiveBody, from: 7, to: 8 }]
108
110
  ] as const;
109
111
 
112
+ const testSpecifiedSyntaxData = [
113
+ ['1=', { code: RSErrorCode.expectedRightOperand, from: 2, to: 2 }],
114
+ ['1+', { code: RSErrorCode.expectedRightOperand, from: 2, to: 2 }],
115
+ ['1=1&', { code: RSErrorCode.expectedRightOperand, from: 4, to: 4 }],
116
+ ['1=1⇒', { code: RSErrorCode.expectedRightOperand, from: 4, to: 4 }],
117
+ ['¬', { code: RSErrorCode.expectedUnaryOperand, from: 1, to: 1 }],
118
+ ['ℬ()', { code: RSErrorCode.expectedRightOperand, from: 2, to: 2 }],
119
+ ['P1(S1)', { code: RSErrorCode.globalFuncParenCall, from: 0, to: 2, params: ['P1'] }],
120
+ ['P1()', { code: RSErrorCode.globalFuncParenCall, from: 0, to: 2, params: ['P1'] }],
121
+ ['F1(S1)', { code: RSErrorCode.globalFuncParenCall, from: 0, to: 2, params: ['F1'] }],
122
+ ['P1[S1, ]', { code: RSErrorCode.expectedArgument, from: 7, to: 7 }],
123
+ ['X1∈', { code: RSErrorCode.expectedRightOperand, from: 3, to: 3 }],
124
+ ['ξ:=', { code: RSErrorCode.expectedRightOperand, from: 3, to: 3 }]
125
+ ] as const;
126
+
127
+ const testUnknownSyntaxData = [
128
+ ['1==1', { code: RSErrorCode.unknownSyntax, from: 0, to: 2 }],
129
+ ['=1', { code: RSErrorCode.unknownSyntax, from: 0, to: 1 }],
130
+ ['∈X1', { code: RSErrorCode.unknownSyntax, from: 0, to: 1 }],
131
+ ['∀', { code: RSErrorCode.unknownSyntax, from: 0, to: 1 }],
132
+ ['∃∈X1', { code: RSErrorCode.unknownSyntax, from: 0, to: 1 }],
133
+ ['&1=1', { code: RSErrorCode.unknownSyntax, from: 0, to: 1 }],
134
+ ['P1[,S1]', { code: RSErrorCode.unknownSyntax, from: 3, to: 4 }],
135
+ ['(,β)', { code: RSErrorCode.unknownSyntax, from: 1, to: 1 }],
136
+ ['(α,β,)', { code: RSErrorCode.unknownSyntax, from: 1, to: 5 }],
137
+ ['F1[S1][S2]', { code: RSErrorCode.unknownSyntax, from: 6, to: 10 }],
138
+ [':∈X1', { code: RSErrorCode.unknownSyntax, from: 0, to: 2 }]
139
+ ] as const;
140
+
110
141
  describe('Testing RSParser correct inputs', () => {
111
142
  testSuccess.forEach(([input, expectedTree]) => {
112
143
  it(`Parse "${input}"`, () => {
@@ -149,6 +180,28 @@ describe('Testing RSParser error data', () => {
149
180
  });
150
181
  });
151
182
 
183
+ testSpecifiedSyntaxData.forEach(([input, expectedError]) => {
184
+ it(`Parse specified syntax "${input}"`, () => {
185
+ const tree = parser.parse(input);
186
+ const ast = buildTree(tree.cursor());
187
+ const errors: RSErrorDescription[] = [];
188
+ extractSyntaxErrors(ast, input, error => errors.push(error));
189
+ expect(errors.length).toBe(1);
190
+ expect(errors[0]).toMatchObject(expectedError);
191
+ });
192
+ });
193
+
194
+ testUnknownSyntaxData.forEach(([input, expectedError]) => {
195
+ it(`Parse unknown syntax "${input}"`, () => {
196
+ const tree = parser.parse(input);
197
+ const ast = buildTree(tree.cursor());
198
+ const errors: RSErrorDescription[] = [];
199
+ extractSyntaxErrors(ast, input, error => errors.push(error));
200
+ expect(errors.length).toBe(1);
201
+ expect(errors[0]).toMatchObject(expectedError);
202
+ });
203
+ });
204
+
152
205
  it('Quantor expressions', () => {
153
206
  const input = '∀X1∈X1 (1=1)';
154
207
  const tree = parser.parse(input);
@@ -0,0 +1,61 @@
1
+ # Syntax error reporting
2
+
3
+ Turns Lezer `ERROR` nodes and raw expression text into `RSErrorDescription` values
4
+ (codes `0x8400`–`0x8423`, see `rstool/docs/DIAGNOSTICS.md`).
5
+
6
+ **Input AST:** always **after** `normalizeAST` (see [../README.md](../README.md#hybrid-ast-intentional)).
7
+ Classifiers must handle both grammar terms (`parser.terms`) and `TokenID` values on the same tree.
8
+
9
+ ## Pipeline (`index.ts`)
10
+
11
+ 1. **Forbidden characters** — scan the source string; if any illegal symbol is found, report only those errors and stop.
12
+ 2. **AST walk** — for each `ERROR` node, run classifiers (`classify.ts`) or fall back to `unknownSyntax` / `expectedLocal`.
13
+ 3. **Bracket pass** — one expression-level bracket diagnostic (`missingCloseBracket`, `bracketMismatch`, …), unless an incomplete D/I/R body was already reported (generator may legally end with `}` while brackets look wrong).
14
+ 4. **Deduplication** — drop overlaps; prefer specific codes over `unknownSyntax`; keep a single `unknownSyntax` when several ERROR nodes fire.
15
+
16
+ `options.expected` (`TypeClass`) refines incomplete formal headers: `[α∈X1]` → `expectedLogicBody` vs `expectedExpressionBody`.
17
+
18
+ ## Classifier chain (`classify.ts`)
19
+
20
+ Order matters — first match wins:
21
+
22
+ | Priority | Module | Codes (examples) |
23
+ | -------- | ------------------------ | ---------------------------------------------------------------------------- |
24
+ | 1 | `incomplete-formal.ts` | `expectedFunctionBody`, `expectedQuantifierBody`, `expectedQuantifierDomain` |
25
+ | 2 | `generators.ts` | `expectedDeclarativeBody`, `expectedImperativeBody`, `expectedRecursiveBody` |
26
+ | 3 | `incomplete-operands.ts` | `expectedRightOperand`, `expectedUnaryOperand` (skipped when bracket errors) |
27
+ | 4 | `incomplete-operands.ts` | `expectedArgument` — only `F[…]` / `P[…]` lists, not tuples |
28
+ | 5 | `function-calls.ts` | `invalidFilterSyntax`, `globalFuncWithoutArgs`, `globalFuncParenCall` |
29
+
30
+ Fallback: `expectedLocal` under `Variable`; otherwise `unknownSyntax` (`0x8400`).
31
+
32
+ ## Shared patterns
33
+
34
+ - **`trailing-slot.ts`** — header parsed, last child is `ERROR`, input ends: `[α∈X1]`, `∀α∈X1`, etc.
35
+ - **`whenNoBracketErrors`** (`context.ts`) — operand/argument classifiers must not compete with bracket diagnostics.
36
+ - **`expression-errors.ts`** — text-level checks independent of AST shape.
37
+ - **`ast-utils.ts` predicates** — `isFunctionDeclNode`, `isFilterNode`, … match grammar **or** token
38
+ `typeID` because `normalizeAST` does not rewrite `hasError` subtrees.
39
+
40
+ ## Adding a new error code
41
+
42
+ 1. Add `RSErrorCode` in `rslang/error.ts` and strings in frontend i18n + `DIAGNOSTICS.md`.
43
+ 2. Implement `ErrorClassifier` in the appropriate module (or new file).
44
+ 3. Register it in `PARSE_ERROR_CLASSIFIERS` in `classify.ts` at the right priority.
45
+ 4. Add cases to `parser.test.ts` (`testSpecifiedSyntaxData` / `testUnknownSyntaxData`).
46
+
47
+ ## File map
48
+
49
+ | File | Role |
50
+ | ------------------------ | ----------------------------------------------------------- |
51
+ | `index.ts` | Public API: `extractSyntaxErrors` |
52
+ | `classify.ts` | Classifier registry + fallback |
53
+ | `context.ts` | `ClassifyContext`, `ErrorClassifier`, `whenNoBracketErrors` |
54
+ | `trailing-slot.ts` | Reusable incomplete-trailing-body detector |
55
+ | `ast-utils.ts` | Tree navigation, node predicates, bracket matching |
56
+ | `error-builders.ts` | `errorAt`, text-token helpers |
57
+ | `expression-errors.ts` | Forbidden chars, brackets, dedup |
58
+ | `incomplete-formal.ts` | `[…]` declarations, quantifiers |
59
+ | `incomplete-operands.ts` | Operators, `ℬ()`, bracket argument lists |
60
+ | `generators.ts` | D{…}, I{…}, R{…} incomplete bodies |
61
+ | `function-calls.ts` | Fi, F/P call syntax |
@@ -0,0 +1,112 @@
1
+ /**
2
+ * AST navigation helpers and node-type predicates for classifiers.
3
+ *
4
+ * Predicates accept grammar terms **or** {@link TokenID} because `normalizeAST` runs before
5
+ * error extraction and leaves `hasError` subtrees unnormalized — see `parser/README.md`.
6
+ */
7
+
8
+ import type { AstNode } from '../../../parsing';
9
+ import { Filter, Function, Function_decl, Logic_quantor, Predicate } from '../parser.terms';
10
+ import { TokenID } from '../token';
11
+
12
+ export function findAncestor(node: AstNode, predicate: (node: AstNode) => boolean): AstNode | null {
13
+ let current: AstNode | null = node;
14
+ while (current !== null) {
15
+ if (predicate(current)) {
16
+ return current;
17
+ }
18
+ current = current.parent;
19
+ }
20
+ return null;
21
+ }
22
+
23
+ export function findRelatedNode(node: AstNode, predicate: (target: AstNode) => boolean): AstNode | null {
24
+ let current: AstNode | null = node.parent;
25
+ while (current !== null) {
26
+ for (const child of current.children) {
27
+ if (predicate(child)) {
28
+ return child;
29
+ }
30
+ }
31
+ current = current.parent;
32
+ }
33
+ return null;
34
+ }
35
+
36
+ export function isDescendantOf(ancestor: AstNode, node: AstNode): boolean {
37
+ let current: AstNode | null = node.parent;
38
+ while (current !== null) {
39
+ if (current === ancestor) {
40
+ return true;
41
+ }
42
+ current = current.parent;
43
+ }
44
+ return false;
45
+ }
46
+
47
+ export function subtreeHasError(node: AstNode): boolean {
48
+ if (node.typeID === TokenID.ERROR) {
49
+ return true;
50
+ }
51
+ return node.children.some(subtreeHasError);
52
+ }
53
+
54
+ export function isFunctionDeclNode(node: AstNode): boolean {
55
+ return node.typeID === Function_decl || node.typeID === TokenID.NT_FUNC_DEFINITION;
56
+ }
57
+
58
+ export function isQuantifierNode(node: AstNode): boolean {
59
+ return node.typeID === Logic_quantor;
60
+ }
61
+
62
+ export function isFunctionNode(node: AstNode): boolean {
63
+ return node.typeID === Function || node.typeID === TokenID.ID_FUNCTION;
64
+ }
65
+
66
+ export function isPredicateNode(node: AstNode): boolean {
67
+ return node.typeID === Predicate || node.typeID === TokenID.ID_PREDICATE;
68
+ }
69
+
70
+ export function isFilterNode(node: AstNode): boolean {
71
+ return node.typeID === Filter || node.typeID === TokenID.FILTER;
72
+ }
73
+
74
+ export function findMatchingCloseBracket(expression: string, openPos: number): number {
75
+ if (expression[openPos] !== '[') {
76
+ return -1;
77
+ }
78
+
79
+ let depth = 0;
80
+ for (let index = openPos; index < expression.length; index++) {
81
+ const symbol = expression[index];
82
+ if (symbol === '[') {
83
+ depth++;
84
+ } else if (symbol === ']') {
85
+ depth--;
86
+ if (depth === 0) {
87
+ return index;
88
+ }
89
+ }
90
+ }
91
+ return -1;
92
+ }
93
+
94
+ export function getErrorOperandNode(node: AstNode): AstNode | null {
95
+ if (node.typeID === TokenID.ERROR) {
96
+ return node;
97
+ }
98
+ if (node.children.length === 1) {
99
+ return getErrorOperandNode(node.children[0]);
100
+ }
101
+ return null;
102
+ }
103
+
104
+ export function isErrorPlaceholder(node: AstNode): boolean {
105
+ if (node.typeID === TokenID.ERROR) {
106
+ return true;
107
+ }
108
+ if (node.children.length === 0) {
109
+ return false;
110
+ }
111
+ return node.children.every(child => isErrorPlaceholder(child));
112
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Parse-error classification: ordered classifier chain and P8400 fallback.
3
+ *
4
+ * Register new detectors in `PARSE_ERROR_CLASSIFIERS` (first match wins).
5
+ */
6
+
7
+ import type { AstNode } from '../../../parsing';
8
+ import { RSErrorCode, type RSErrorDescription } from '../../error';
9
+ import { Variable } from '../parser.terms';
10
+
11
+ import type { ClassifyContext, ErrorClassifier } from './context';
12
+ import { whenNoBracketErrors } from './context';
13
+ import { classifyFilterParenMismatch, classifyGlobalFuncCall } from './function-calls';
14
+ import { classifyIncompleteGenerator } from './generators';
15
+ import { classifyIncompleteFormal } from './incomplete-formal';
16
+ import { classifyIncompleteArgument, classifyIncompleteOperands } from './incomplete-operands';
17
+
18
+ const PARSE_ERROR_CLASSIFIERS: ErrorClassifier[] = [
19
+ classifyIncompleteFormal,
20
+ classifyIncompleteGenerator,
21
+ whenNoBracketErrors(classifyIncompleteOperands),
22
+ whenNoBracketErrors(classifyIncompleteArgument),
23
+ classifyFilterParenMismatch,
24
+ classifyGlobalFuncCall
25
+ ];
26
+
27
+ /** Runs classifiers in priority order for one `ERROR` AST node. */
28
+ export function classifyParseError(
29
+ node: AstNode,
30
+ expression: string,
31
+ context: ClassifyContext
32
+ ): RSErrorDescription | null {
33
+ for (const classifier of PARSE_ERROR_CLASSIFIERS) {
34
+ const error = classifier(node, expression, context);
35
+ if (error !== null) {
36
+ return error;
37
+ }
38
+ }
39
+ return null;
40
+ }
41
+
42
+ /** Default rules when no classifier matched: `expectedLocal` or `unknownSyntax`. */
43
+ export function classifyFallbackError(
44
+ node: AstNode,
45
+ ignoreUnknownErrors: boolean
46
+ ): { error: RSErrorDescription; target: AstNode } | null {
47
+ const parent = node.parent;
48
+ if (parent === null) {
49
+ return ignoreUnknownErrors
50
+ ? null
51
+ : { error: { code: RSErrorCode.unknownSyntax, from: node.from, to: node.to }, target: node };
52
+ }
53
+
54
+ if (parent.typeID === Variable) {
55
+ return {
56
+ error: { code: RSErrorCode.expectedLocal, from: parent.from, to: parent.to },
57
+ target: parent
58
+ };
59
+ }
60
+
61
+ if (ignoreUnknownErrors) {
62
+ return null;
63
+ }
64
+
65
+ const target = node.from === node.to ? parent : node;
66
+ return {
67
+ error: { code: RSErrorCode.unknownSyntax, from: target.from, to: target.to },
68
+ target
69
+ };
70
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Types for the parse-error classifier pipeline.
3
+ */
4
+
5
+ import type { AstNode } from '../../../parsing';
6
+ import type { RSErrorDescription } from '../../error';
7
+ import type { TypeClass } from '../../semantic/typification';
8
+
9
+ /** Shared state passed through parse-error classifiers. */
10
+ export interface ClassifyContext {
11
+ hasBracketErrors: boolean;
12
+ expected?: TypeClass;
13
+ }
14
+
15
+ /** Classifies a single ERROR node into a specific syntax error, if possible. */
16
+ export type ErrorClassifier = (
17
+ node: AstNode,
18
+ expression: string,
19
+ context: ClassifyContext
20
+ ) => RSErrorDescription | null;
21
+
22
+ /** Skips classifiers that conflict with bracket-level diagnostics. */
23
+ export function whenNoBracketErrors(classifier: ErrorClassifier): ErrorClassifier {
24
+ return (node, expression, context) => (context.hasBracketErrors ? null : classifier(node, expression, context));
25
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Small helpers for building `RSErrorDescription` values from AST nodes.
3
+ */
4
+
5
+ import type { AstNode } from '../../../parsing';
6
+ import { type RSErrorCode, type RSErrorDescription } from '../../error';
7
+
8
+ export function errorAt(node: AstNode, code: RSErrorCode, params?: readonly string[]): RSErrorDescription {
9
+ return {
10
+ code,
11
+ from: node.from,
12
+ to: node.to,
13
+ params
14
+ };
15
+ }
16
+
17
+ export function hasOnlyClosingSuffix(expression: string, from: number): boolean {
18
+ const suffix = expression.slice(from).trim();
19
+ return suffix.length === 0 || /^[\]\)\}]*$/.test(suffix);
20
+ }
21
+
22
+ export function sliceText(node: AstNode, expression: string): string {
23
+ return expression.slice(node.from, node.to);
24
+ }
25
+
26
+ export function isTextToken(node: AstNode, expression: string, text: string): boolean {
27
+ return sliceText(node, expression) === text;
28
+ }