Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some identifiers are not supported #8

Open
alopatindev opened this issue Oct 6, 2020 · 1 comment
Open

Some identifiers are not supported #8

alopatindev opened this issue Oct 6, 2020 · 1 comment

Comments

@alopatindev
Copy link

alopatindev commented Oct 6, 2020

#[macro_use]
extern crate yaserde_derive;

use log::debug;
use std::io::prelude::*;
use xml_schema_derive::XmlSchema;
use yaserde::{YaDeserialize, YaSerialize};

#[derive(Debug, XmlSchema)]
#[xml_schema(source = "a.xsd")]
struct SimpleTypeSchema;

fn main() {}

Example 1:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="a">
    <xs:sequence>
      <xs:element name="b">
        <xs:complexType>
          <xs:sequence>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
error[E0433]: failed to resolve: use of undeclared type or module `b`
 --> src/main.rs:9:17
  |
9 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^ use of undeclared type or module `b`
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `b` in this scope
 --> src/main.rs:9:17
  |
9 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^
  |                 |
  |                 similarly named struct `B` defined here
  |                 help: a struct with a similar name exists: `B`

Example 2:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="a">
    <xs:sequence>
      <xs:element name="ref">
        <xs:complexType>
          <xs:sequence>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
error: expected identifier, found keyword `ref`
 --> src/main.rs:9:17
  |
9 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^ expected identifier, found keyword
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can escape reserved keywords to use them as identifiers
  |
9 | #[derive(Debug, r#ref)]
  |                 ^^^^^

error: expected type, found keyword `ref`
 --> src/main.rs:9:17
  |
9 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^ expected type
  |

Example 3:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="a">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="b.c" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
error: proc-macro derive panicked
 --> src/main.rs:9:17
  |
9 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^
  |
  = help: message: `"b.cs"` is not a valid identifier
@ryanavella
Copy link
Contributor

I got a similar error with the following XSD file, which is sometimes used to informally validate USX files: https://gist.github.com/jonBitgood/51e70fbbd536950432f64c5c2d8a4743

Maybe some kind of encoding would make sense here? By that I mean something similar to e.g. percent-encoding, but only yielding characters that are valid in Rust identifiers.

Another option could be to filter out the problematic characters, and disambiguate collisions by some other means such as placing them in separate modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants