diff --git a/src/application/Parser/CategoryParser.ts b/src/application/Parser/CategoryParser.ts index d602415..a83fd83 100644 --- a/src/application/Parser/CategoryParser.ts +++ b/src/application/Parser/CategoryParser.ts @@ -3,6 +3,8 @@ import type { } from '@/application/collections/'; import { Script } from '@/domain/Script'; import { Category } from '@/domain/Category'; +import { NodeValidator } from '@/application/Parser/NodeValidation/NodeValidator'; +import { NodeType } from '@/application/Parser/NodeValidation/NodeType'; import { parseDocUrls } from './DocumentationParser'; import { ICategoryCollectionParseContext } from './Script/ICategoryCollectionParseContext'; import { parseScript } from './Script/ScriptParser'; @@ -12,35 +14,67 @@ let categoryIdCounter = 0; export function parseCategory( category: CategoryData, context: ICategoryCollectionParseContext, + factory: CategoryFactoryType = CategoryFactory, ): Category { if (!context) { throw new Error('missing context'); } - ensureValid(category); + return parseCategoryRecursively({ + categoryData: category, + context, + factory, + }); +} + +interface ICategoryParseContext { + readonly categoryData: CategoryData, + readonly context: ICategoryCollectionParseContext, + readonly factory: CategoryFactoryType, + readonly parentCategory?: CategoryData, +} +// eslint-disable-next-line consistent-return +function parseCategoryRecursively(context: ICategoryParseContext): Category { + ensureValidCategory(context.categoryData, context.parentCategory); const children: ICategoryChildren = { subCategories: new Array(), subScripts: new Array