ConceptPortal-public/rsconcept/frontend/src/models/rslang.ts

268 lines
4.6 KiB
TypeScript
Raw Normal View History

/**
* Module: Models for RSLanguage.
*/
2023-09-11 20:31:54 +03:00
/**
* Represents formal expression.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export interface IRSExpression {
2023-12-28 14:04:44 +03:00
expression: string;
2023-09-11 20:31:54 +03:00
}
/**
* Represents syntax type.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export enum Syntax {
UNDEF = 'undefined',
ASCII = 'ascii',
MATH = 'math'
}
/**
* Represents computability class.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export enum ValueClass {
INVALID = 'invalid', // incalculable
2023-09-11 20:31:54 +03:00
VALUE = 'value',
PROPERTY = 'property'
}
/**
* Represents parsing status.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export enum ParsingStatus {
UNDEF = 'undefined',
VERIFIED = 'verified',
INCORRECT = 'incorrect'
}
/**
* Represents parsing error description.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export interface IRSErrorDescription {
2023-12-28 14:04:44 +03:00
errorType: RSErrorType;
position: number;
isCritical: boolean;
params: string[];
2023-09-11 20:31:54 +03:00
}
/**
* Represents AST node.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export interface ISyntaxTreeNode {
2023-12-28 14:04:44 +03:00
uid: number;
parent: number;
typeID: TokenID;
start: number;
finish: number;
2023-09-11 20:31:54 +03:00
data: {
2023-12-28 14:04:44 +03:00
dataType: string;
value: unknown;
};
2023-09-11 20:31:54 +03:00
}
/**
* Represents Syntax tree for RSLang expression.
2023-12-28 14:04:44 +03:00
*/
export type SyntaxTree = ISyntaxTreeNode[];
2023-09-11 20:31:54 +03:00
/**
* Represents function argument definition.
2023-12-28 14:04:44 +03:00
*/
2023-11-06 02:20:16 +03:00
export interface IArgumentInfo {
2023-12-28 14:04:44 +03:00
alias: string;
typification: string;
2023-09-11 20:31:54 +03:00
}
/**
* Represents function argument value.
2023-12-28 14:04:44 +03:00
*/
export interface IArgumentValue extends IArgumentInfo {
2023-12-28 14:04:44 +03:00
value?: string;
2023-11-06 02:20:16 +03:00
}
/**
* Represents results of expression parse in RSLang.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export interface IExpressionParse {
2023-12-28 14:04:44 +03:00
parseResult: boolean;
syntax: Syntax;
typification: string;
valueClass: ValueClass;
errors: IRSErrorDescription[];
astText: string;
ast: SyntaxTree;
args: IArgumentInfo[];
2023-09-11 20:31:54 +03:00
}
/**
* Represents RSLang token types.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export enum TokenID {
// Global, local IDs and literals
ID_LOCAL = 258,
ID_GLOBAL,
ID_FUNCTION,
ID_PREDICATE,
ID_RADICAL,
LIT_INTEGER,
2023-12-27 19:34:39 +03:00
LIT_WHOLE_NUMBERS,
2023-09-11 20:31:54 +03:00
LIT_EMPTYSET,
2023-12-27 19:34:39 +03:00
// Arithmetic
2023-09-11 20:31:54 +03:00
PLUS,
MINUS,
MULTIPLY,
// Integer predicate symbols
GREATER,
LESSER,
GREATER_OR_EQ,
LESSER_OR_EQ,
// Equality comparison
EQUAL,
NOTEQUAL,
// Logic predicate symbols
2023-12-27 19:34:39 +03:00
QUANTOR_UNIVERSAL,
QUANTOR_EXISTS,
LOGIC_NOT,
LOGIC_EQUIVALENT,
LOGIC_IMPLICATION,
LOGIC_OR,
LOGIC_AND,
2023-09-11 20:31:54 +03:00
// Set theory predicate symbols
2023-12-27 19:34:39 +03:00
SET_IN,
SET_NOT_IN,
2023-09-11 20:31:54 +03:00
SUBSET,
SUBSET_OR_EQ,
2023-12-27 19:34:39 +03:00
NOT_SUBSET,
2023-09-11 20:31:54 +03:00
// Set theory operators
DECART,
2023-12-27 19:34:39 +03:00
SET_UNION,
SET_INTERSECTION,
2023-09-11 20:31:54 +03:00
SET_MINUS,
2023-12-27 19:34:39 +03:00
SET_SYMMETRIC_MINUS,
2023-09-11 20:31:54 +03:00
BOOLEAN,
// Structure operations
BIGPR,
SMALLPR,
FILTER,
CARD,
BOOL,
DEBOOL,
REDUCE,
// Term constructions prefixes
DECLARATIVE,
RECURSIVE,
IMPERATIVE,
ITERATE,
ASSIGN,
2023-09-11 20:31:54 +03:00
// Punctuation
2023-12-27 19:34:39 +03:00
PUNCTUATION_DEFINE,
PUNCTUATION_STRUCT,
PUNCTUATION_PL,
PUNCTUATION_PR,
PUNCTUATION_CL,
PUNCTUATION_CR,
PUNCTUATION_SL,
PUNCTUATION_SR,
PUNCTUATION_BAR,
PUNCTUATION_COMMA,
PUNCTUATION_SEMICOLON,
2023-09-11 20:31:54 +03:00
// ======= Non-terminal tokens =========
NT_ENUM_DECL,
NT_TUPLE,
NT_ENUMERATION,
NT_TUPLE_DECL,
NT_ARG_DECL,
NT_FUNC_DEFINITION,
NT_ARGUMENTS,
NT_FUNC_CALL,
NT_DECLARATIVE_EXPR,
NT_IMPERATIVE_EXPR,
NT_RECURSIVE_FULL,
NT_RECURSIVE_SHORT,
// ======= Helper tokens ========
INTERRUPT,
END
}
2024-08-26 17:25:07 +03:00
/**
* Represents RSLang expression error types.
*/
2023-09-11 20:31:54 +03:00
export enum RSErrorType {
2023-10-04 18:46:52 +03:00
unknownSymbol = 33283,
2023-09-11 20:31:54 +03:00
syntax = 33792,
2023-12-26 14:23:51 +03:00
missingParenthesis = 33798,
2023-09-11 20:31:54 +03:00
missingCurlyBrace = 33799,
invalidQuantifier = 33800,
2024-05-12 13:58:28 +03:00
invalidImperative = 33801,
2023-09-11 20:31:54 +03:00
expectedArgDeclaration = 33812,
expectedLocal = 33813,
localDoubleDeclare = 10241,
localNotUsed = 10242,
localUndeclared = 34817,
localShadowing = 34818,
typesNotEqual = 34819,
globalNotTyped = 34820,
invalidDecart = 34821,
invalidBoolean = 34822,
invalidTypeOperation = 34823,
invalidCard = 34824,
invalidDebool = 34825,
globalFuncMissing = 34826,
globalFuncWithoutArgs = 34827,
invalidReduce = 34832,
invalidProjectionTuple = 34833,
invalidProjectionSet = 34834,
invalidEnumeration = 34835,
2023-12-26 14:23:51 +03:00
invalidBinding = 34836,
2023-09-11 20:31:54 +03:00
localOutOfScope = 34837,
2023-12-26 14:23:51 +03:00
invalidElementPredicate = 34838,
invalidArgsArity = 34840,
2023-09-11 20:31:54 +03:00
invalidArgumentType = 34841,
globalStructure = 34844,
globalExpectedFunction = 34847,
radicalUsage = 34849,
invalidFilterArgumentType = 34850,
invalidFilterArity = 34851,
arithmeticNotSupported = 34852,
typesNotCompatible = 34853,
orderingNotSupported = 34854,
// !!!! Добавлены по сравнению с ConceptCore !!!!!
globalNonemptyBase = 34855,
globalUnexpectedType = 34856,
globalEmptyDerived = 34857,
2023-09-11 20:31:54 +03:00
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
globalNoValue = 34880,
invalidPropertyUsage = 34881,
globalMissingAST = 34882,
globalFuncNoInterpretation = 34883
}
/**
* Represents error class.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export enum RSErrorClass {
LEXER,
PARSER,
SEMANTIC,
UNKNOWN
2023-12-28 14:04:44 +03:00
}