Skip to content

Commit

Permalink
Bypass broken parent tag generator and fix remaining test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Oct 9, 2024
1 parent 9d82533 commit f501cc2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion parser/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions parser/parsedHedGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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:
Expand Down
29 changes: 15 additions & 14 deletions parser/parsedHedTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}

Expand All @@ -414,7 +415,7 @@ export class ParsedHed3Tag extends ParsedHedTag {
*/
get takesValue() {
return this._memoize('takesValue', () => {
return this.takesValueFormattedTag !== null
return this.takesValueTag !== undefined
})
}

Expand Down
18 changes: 5 additions & 13 deletions validator/event/hed3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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', {
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit f501cc2

Please sign in to comment.