This commit adds validation logic in compiler to check for max allowed characters per line for scripts. This allows preventing bugs caused by limitation of terminal emulators. Other supporting changes: - Rename/refactor related code for clarity and better maintainability. - Drop `I` prefix from interfaces to align with latest convention. - Refactor CodeValidator to be functional rather than object-oriented for simplicity. - Refactor syntax definition construction to be functional and be part of rule for better separation of concerns. - Refactored validation logic to use an enum-based factory pattern for improved maintainability and scalability.
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import type { FunctionData } from '@/application/collections/';
|
|
import { sequenceEqual } from '@/application/Common/Array';
|
|
import type { ISharedFunctionCollection } from '@/application/Parser/Executable/Script/Compiler/Function/ISharedFunctionCollection';
|
|
import type { SharedFunctionsParser } from '@/application/Parser/Executable/Script/Compiler/Function/SharedFunctionsParser';
|
|
import type { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
|
import { SharedFunctionCollectionStub } from './SharedFunctionCollectionStub';
|
|
|
|
export function createSharedFunctionsParserStub() {
|
|
const callHistory = new Array<{
|
|
readonly functions: readonly FunctionData[],
|
|
readonly language: ScriptingLanguage,
|
|
}>();
|
|
|
|
const setupResults = new Array<{
|
|
readonly functions: readonly FunctionData[],
|
|
readonly result: ISharedFunctionCollection,
|
|
}>();
|
|
|
|
const findResult = (
|
|
functions: readonly FunctionData[],
|
|
): ISharedFunctionCollection | undefined => {
|
|
return setupResults
|
|
.find((result) => sequenceEqual(result.functions, functions))
|
|
?.result;
|
|
};
|
|
|
|
const parser: SharedFunctionsParser = (
|
|
functions: readonly FunctionData[],
|
|
language: ScriptingLanguage,
|
|
) => {
|
|
callHistory.push({
|
|
functions: Array.from(functions),
|
|
language,
|
|
});
|
|
const result = findResult(functions);
|
|
return result || new SharedFunctionCollectionStub();
|
|
};
|
|
|
|
const setup = (
|
|
functions: readonly FunctionData[],
|
|
result: ISharedFunctionCollection,
|
|
) => {
|
|
setupResults.push({ functions, result });
|
|
};
|
|
|
|
return {
|
|
parser,
|
|
setup,
|
|
callHistory,
|
|
};
|
|
}
|