import { SpecifyError, specifyErrors } from '../../errors/index.js'; import { BuiltInParserRuleSignature } from '../internals/BuiltInParserRuleSignature.js'; export function pickLastParserInParserRule(rule: BuiltInParserRuleSignature) { const index = rule.parsers?.length > 0 ? rule.parsers?.length - 1 : 0; const maybeParserConfig = rule.parsers?.[index]; if (!maybeParserConfig) { throw new SpecifyError({ errorKey: specifyErrors.PARSERS_ENGINE_INVALID_PARSER_INPUT.errorKey, publicMessage: `Unknown built-in parser at index #${index}" on rule "${ rule.name ?? 'Unknown rule' }".`, }); } return maybeParserConfig; }