diff --git a/parser/converter.js b/parser/converter.js index 6560cf8a..0d81fbd3 100644 --- a/parser/converter.js +++ b/parser/converter.js @@ -100,7 +100,7 @@ export default class TagConverter { parentTag: parentTag.longName, }) } - if (childTag !== undefined && parentTag && (childTag.parent === undefined || childTag.parent !== parentTag)) { + if (childTag !== undefined && i > 0 && (childTag.parent === undefined || childTag.parent !== parentTag)) { IssueError.generateAndThrow('invalidParentNode', { tag: this.tagLevels[i], parentTag: childTag.longName, diff --git a/parser/parsedHedGroup.js b/parser/parsedHedGroup.js index 0eb0c8eb..cc5c23cb 100644 --- a/parser/parsedHedGroup.js +++ b/parser/parsedHedGroup.js @@ -4,7 +4,7 @@ import { generateIssue, IssueError } from '../common/issues/issues' import { getParsedParentTags } from '../utils/hedData' import { getTagName } from '../utils/hedStrings' import ParsedHedSubstring from './parsedHedSubstring' -import { ParsedHedTag } from './parsedHedTag' +import { ParsedHed3Tag, ParsedHedTag } from './parsedHedTag' import ParsedHedColumnSplice from './parsedHedColumnSplice' /** @@ -73,13 +73,12 @@ export class ParsedHedGroup extends ParsedHedSubstring { if (!hedSchemas.isHed3) { return undefined } - const parsedTags = getParsedParentTags(hedSchemas, shortTag) const tags = group.tags.filter((tag) => { - if (!(tag instanceof ParsedHedTag)) { + if (!(tag instanceof ParsedHed3Tag)) { return false } - const parsedTag = parsedTags.get(tag.schema) - return tag.isDescendantOf(parsedTag) + const schemaTag = tag.schemaTag + return schemaTag.name === shortTag }) switch (tags.length) { case 0: diff --git a/parser/parsedHedTag.js b/parser/parsedHedTag.js index 6542f74e..edc2465c 100644 --- a/parser/parsedHedTag.js +++ b/parser/parsedHedTag.js @@ -379,31 +379,32 @@ export class ParsedHed3Tag extends ParsedHedTag { } /** - * Get the value-taking form of this tag. + * Get the schema tag object for this tag. * - * @returns {string} The value-taking form of this tag. + * @returns {SchemaTag} The schema tag object for this tag. */ - get takesValueFormattedTag() { - return this._memoize('takesValueFormattedTag', () => { - const takesValueType = 'takesValue' - for (const ancestor of ParsedHedTag.ancestorIterator(this.formattedTag)) { - const takesValueTag = replaceTagNameWithPound(ancestor) - if (this.schema?.tagHasAttribute(takesValueTag, takesValueType)) { - return takesValueTag - } + get schemaTag() { + return this._memoize('takesValueTag', () => { + if (this._schemaTag instanceof SchemaValueTag) { + return this._schemaTag.parent + } else { + return this._schemaTag } - return null }) } /** * Get the schema tag object for this tag's value-taking form. * - * @returns {SchemaTag} The schema tag object for this tag's value-taking form. + * @returns {SchemaValueTag} The schema tag object for this tag's value-taking form. */ get takesValueTag() { return this._memoize('takesValueTag', () => { - return this._schemaTag + if (this._schemaTag instanceof SchemaValueTag) { + return this._schemaTag + } else { + return undefined + } }) } @@ -414,7 +415,7 @@ export class ParsedHed3Tag extends ParsedHedTag { */ get takesValue() { return this._memoize('takesValue', () => { - return this.takesValueFormattedTag !== null + return this.takesValueTag !== undefined }) } diff --git a/validator/event/hed3.js b/validator/event/hed3.js index 5ea382bb..648ea3f7 100644 --- a/validator/event/hed3.js +++ b/validator/event/hed3.js @@ -396,9 +396,6 @@ export class Hed3Validator extends HedValidator { const definitionShortTag = 'Definition' const defExpandShortTag = 'Def-expand' const defShortTag = 'Def' - const definitionParentTags = getParsedParentTags(this.hedSchemas, definitionShortTag) - const defExpandParentTags = getParsedParentTags(this.hedSchemas, defExpandShortTag) - const defParentTags = getParsedParentTags(this.hedSchemas, defShortTag) const definitionName = tagGroup.definitionNameAndValue @@ -421,14 +418,10 @@ export class Hed3Validator extends HedValidator { }) } for (const innerTag of tag.tagIterator()) { - const nestedDefinitionParentTags = [ - ...definitionParentTags.values(), - ...defExpandParentTags.values(), - ...defParentTags.values(), - ] + const nestedDefinitionParentTags = [definitionShortTag, defExpandShortTag, defShortTag] if ( nestedDefinitionParentTags.some((parentTag) => { - return innerTag.isDescendantOf(parentTag) + return innerTag.schemaTag?.name === parentTag }) ) { this.pushIssue('nestedDefinition', { @@ -441,7 +434,7 @@ export class Hed3Validator extends HedValidator { definition: definitionName, column: tag.originalTag, }) - } else if (!tag.isDescendantOf(definitionParentTags.get(tag.schema))) { + } else if (tag.schemaTag?.name !== 'Definition') { this.pushIssue('illegalDefinitionGroupTag', { tag: tag, definition: definitionName, @@ -453,12 +446,11 @@ export class Hed3Validator extends HedValidator { /** * Check for missing HED 3 definitions. * - * @param {ParsedHedTag} tag The HED tag. + * @param {ParsedHed3Tag} tag The HED tag. * @param {string} defShortTag The short tag to check for. */ checkForMissingDefinitions(tag, defShortTag = 'Def') { - const defParentTags = getParsedParentTags(this.hedSchemas, defShortTag) - if (!tag.isDescendantOf(defParentTags.get(tag.schema))) { + if (tag.schemaTag?.name !== defShortTag) { return } const defName = ParsedHedGroup.findDefinitionName(tag.canonicalTag, defShortTag)