Skip to content

Commit

Permalink
[USDA Parser] Report syntax error when attribute metadataum exists fo…
Browse files Browse the repository at this point in the history
…r timesampled attribute and attribute connection
  • Loading branch information
syoyo committed Apr 22, 2024
1 parent 30ed6a2 commit d14ce2a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
53 changes: 49 additions & 4 deletions src/ascii-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3392,17 +3392,18 @@ bool AsciiParser::ParseBasicPrimAttr(bool array_qual,
} else {
std::vector<T> value;
if (!ParseBasicTypeArray(&value)) {
PUSH_ERROR_AND_RETURN("Failed to parse " +
std::string(value::TypeTraits<T>::type_name()) +
" array.");
PUSH_ERROR_AND_RETURN(fmt::format("Failed to parse Primtive Attribute {} type = {}[]", primattr_name,
std::string(value::TypeTraits<T>::type_name())));
}

// Empty array allowed.
DCOUT("Got it: ty = " + std::string(value::TypeTraits<T>::type_name()) +
DCOUT("Got it: primatrr " << primattr_name << ", ty = " + std::string(value::TypeTraits<T>::type_name()) +
", sz = " + std::to_string(value.size()));
var.set_value(value);
}

#if 0
// FIXME: Disable duplicated parsing attribute connection here, since parsing attribute connection will be handled in ParsePrimProps().
} else if (hasConnect(primattr_name)) {
std::string value; // TODO: Use Path
if (!ReadPathIdentifier(&value)) {
Expand All @@ -3425,6 +3426,22 @@ bool AsciiParser::ParseBasicPrimAttr(bool array_qual,

// TODO: Use Path
var.set_value(abs_path.full_path_name());

// Check if attribute metadatum is not authored.
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

char c;
if (!LookChar1(&c)) {
return false;
}

if (c == '(') {
PUSH_ERROR_AND_RETURN(fmt::format("Attribute connection cannot have attribute metadataum: {}", primattr_name));
}

#endif
} else {
nonstd::optional<T> value;
if (!ReadBasicType(&value)) {
Expand Down Expand Up @@ -3814,6 +3831,20 @@ bool AsciiParser::ParsePrimProps(std::map<std::string, Property> *props, std::ve
PUSH_ERROR_AND_RETURN(fmt::format("Invalid relative Path: {}. error = {}", path.full_path_name(), err));
}

// Check if attribute metadatum is not authored.
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

char c;
if (!LookChar1(&c)) {
return false;
}

if (c == '(') {
PUSH_ERROR_AND_RETURN(fmt::format("Attribute connection cannot have attribute metadataum: {}", primattr_name));
}

Property p(abs_path, /* value typename */ type_name, custom_qual);
if (value_blocked) {
p.attribute().set_blocked(true);
Expand Down Expand Up @@ -3856,6 +3887,20 @@ bool AsciiParser::ParsePrimProps(std::map<std::string, Property> *props, std::ve
}
}

// Check if attribute metadatum is not authored.
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

char c;
if (!LookChar1(&c)) {
return false;
}

if (c == '(') {
PUSH_ERROR_AND_RETURN(fmt::format("TimeSampled Attribute cannot have attribute metadataum: {}", primattr_name));
}

//std::string varname = removeSuffix(primattr_name, ".timeSamples");
Attribute attr;
primvar::PrimVar var;
Expand Down
5 changes: 5 additions & 0 deletions tests/usda/fail-case/timesamples-attr-meta-001.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#usda 1.0

def "bora" {
float a.timeSamples = {1: 1.0} ( elementSize = 1 )
}

0 comments on commit d14ce2a

Please sign in to comment.