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

271 lines
4.5 KiB
TypeScript
Raw Normal View History

/**
* Module: Models for RSLanguage.
*/
2023-09-11 20:31:54 +03:00
/**
* Represents formal expression.
*/
2023-09-11 20:31:54 +03:00
export interface IRSExpression {
expression: string
}
/**
* Represents syntax type.
*/
2023-09-11 20:31:54 +03:00
export enum Syntax {
UNDEF = 'undefined',
ASCII = 'ascii',
MATH = 'math'
}
/**
* Represents computability class.
*/
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-09-11 20:31:54 +03:00
export enum ParsingStatus {
UNDEF = 'undefined',
VERIFIED = 'verified',
INCORRECT = 'incorrect'
}
/**
* Represents parsing error description.
*/
2023-09-11 20:31:54 +03:00
export interface IRSErrorDescription {
errorType: RSErrorType
position: number
isCritical: boolean
params: string[]
}
/**
* Represents AST node.
*/
2023-09-11 20:31:54 +03:00
export interface ISyntaxTreeNode {
uid: number
parent: number
typeID: TokenID
start: number
finish: number
data: {
dataType: string
value: unknown
}
}
/**
* Represents Syntax tree for RSLang expression.
*/
2023-09-11 20:31:54 +03:00
export type SyntaxTree = ISyntaxTreeNode[]
/**
* Represents function argument definition.
*/
2023-11-06 02:20:16 +03:00
export interface IArgumentInfo {
2023-09-11 20:31:54 +03:00
alias: string
typification: string
}
/**
* Represents function argument value.
*/
export interface IArgumentValue extends IArgumentInfo {
2023-11-06 02:20:16 +03:00
value?: string
}
/**
* Represents results of expression parse in RSLang.
*/
2023-09-11 20:31:54 +03:00
export interface IExpressionParse {
parseResult: boolean
syntax: Syntax
typification: string
valueClass: ValueClass
errors: IRSErrorDescription[]
astText: string
ast: SyntaxTree
2023-11-06 02:20:16 +03:00
args: IArgumentInfo[]
2023-09-11 20:31:54 +03:00
}
/**
* Represents RSLang token types.
*/
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,
LIT_INTSET,
LIT_EMPTYSET,
// Aithmetic
PLUS,
MINUS,
MULTIPLY,
// Integer predicate symbols
GREATER,
LESSER,
GREATER_OR_EQ,
LESSER_OR_EQ,
// Equality comparison
EQUAL,
NOTEQUAL,
// Logic predicate symbols
FORALL,
EXISTS,
NOT,
EQUIVALENT,
IMPLICATION,
OR,
AND,
// Set theory predicate symbols
IN,
NOTIN,
SUBSET,
SUBSET_OR_EQ,
NOTSUBSET,
// Set theory operators
DECART,
UNION,
INTERSECTION,
SET_MINUS,
SYMMINUS,
BOOLEAN,
// Structure operations
BIGPR,
SMALLPR,
FILTER,
CARD,
BOOL,
DEBOOL,
REDUCE,
// Term constructions prefixes
DECLARATIVE,
RECURSIVE,
IMPERATIVE,
// Punctuation
PUNC_DEFINE,
PUNC_STRUCT,
PUNC_ASSIGN,
PUNC_ITERATE,
PUNC_PL,
PUNC_PR,
PUNC_CL,
PUNC_CR,
PUNC_SL,
PUNC_SR,
PUNC_BAR,
PUNC_COMMA,
PUNC_SEMICOLON,
// ======= 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,
NT_IMP_DECLARE,
NT_IMP_ASSIGN,
NT_IMP_LOGIC,
// ======= Helper tokens ========
INTERRUPT,
END
}
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,
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,
invalidEqualsEmpty = 34842,
globalStructure = 34844,
globalExpectedFunction = 34847,
emptySetUsage = 34848,
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-09-11 20:31:54 +03:00
export enum RSErrorClass {
LEXER,
PARSER,
SEMANTIC,
UNKNOWN
}