From d14ce2a32de005188b7e58260df44e9bdbfec4cc Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Mon, 22 Apr 2024 22:21:11 +0900 Subject: [PATCH] [USDA Parser] Report syntax error when attribute metadataum exists for timesampled attribute and attribute connection --- src/ascii-parser.cc | 53 +++++++++++++++++-- .../fail-case/timesamples-attr-meta-001.usda | 5 ++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tests/usda/fail-case/timesamples-attr-meta-001.usda diff --git a/src/ascii-parser.cc b/src/ascii-parser.cc index ac79fc27..cd1a29a0 100644 --- a/src/ascii-parser.cc +++ b/src/ascii-parser.cc @@ -3392,17 +3392,18 @@ bool AsciiParser::ParseBasicPrimAttr(bool array_qual, } else { std::vector value; if (!ParseBasicTypeArray(&value)) { - PUSH_ERROR_AND_RETURN("Failed to parse " + - std::string(value::TypeTraits::type_name()) + - " array."); + PUSH_ERROR_AND_RETURN(fmt::format("Failed to parse Primtive Attribute {} type = {}[]", primattr_name, + std::string(value::TypeTraits::type_name()))); } // Empty array allowed. - DCOUT("Got it: ty = " + std::string(value::TypeTraits::type_name()) + + DCOUT("Got it: primatrr " << primattr_name << ", ty = " + std::string(value::TypeTraits::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)) { @@ -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 value; if (!ReadBasicType(&value)) { @@ -3814,6 +3831,20 @@ bool AsciiParser::ParsePrimProps(std::map *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); @@ -3856,6 +3887,20 @@ bool AsciiParser::ParsePrimProps(std::map *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; diff --git a/tests/usda/fail-case/timesamples-attr-meta-001.usda b/tests/usda/fail-case/timesamples-attr-meta-001.usda new file mode 100644 index 00000000..2e794c35 --- /dev/null +++ b/tests/usda/fail-case/timesamples-attr-meta-001.usda @@ -0,0 +1,5 @@ +#usda 1.0 + +def "bora" { + float a.timeSamples = {1: 1.0} ( elementSize = 1 ) +}