-
Notifications
You must be signed in to change notification settings - Fork 93
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
Grammar generator from XML #779
Grammar generator from XML #779
Conversation
@datho7561 @xorye @fbricon I created a draft PR with the generator (XML -> XSD, XML -> DTD). The generation is not perfect because it misses some features (like managing maxOccurs, etc), but as it's a big PR, you can start to review the code, the API and comments. To see what the generator can do it, I suggest you that you read tests for generating XSD and DTD). I will continue to improve the generation of those grammar, but any review feedback are welcome! |
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Show resolved
Hide resolved
d47cab5
to
39ef689
Compare
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
if (attributes != null) { | ||
for (int j = 0; j < attributes.getLength(); j++) { | ||
Attr attr = (Attr) attributes.item(i); | ||
elementDecl.getAttribute(attr.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could have a method ElementDeclaration#addAttribute
instead? Just an idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to improve attributes cardinality, so please keep like this to get the attribute declaration.
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
3c62883
to
c575f16
Compare
c575f16
to
61b0166
Compare
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/generators/Cardinality.java
Show resolved
Hide resolved
...se.lemminx/src/main/java/org/eclipse/lemminx/extensions/generators/ContainerDeclaration.java
Show resolved
Hide resolved
...ipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/generators/ElementDeclaration.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/IXMLFullFormatter.java
Outdated
Show resolved
Hide resolved
...nx/src/test/java/org/eclipse/lemminx/extensions/generators/xml2dtd/XML2DTDGeneratorTest.java
Outdated
Show resolved
Hide resolved
...nx/src/test/java/org/eclipse/lemminx/extensions/generators/xml2dtd/XML2DTDGeneratorTest.java
Show resolved
Hide resolved
...nx/src/main/java/org/eclipse/lemminx/extensions/generators/AbstractXML2GrammarGenerator.java
Outdated
Show resolved
Hide resolved
...ipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/generators/ChildrenProperties.java
Outdated
Show resolved
Hide resolved
cb02740
to
e56fc1e
Compare
The PR looks good |
...ipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/generators/ElementDeclaration.java
Show resolved
Hide resolved
e56fc1e
to
0111b53
Compare
84022e1
to
73715a0
Compare
161d3f0
to
3c0f4d4
Compare
I opened issue #788 about multiplicity. @angelozerr, do you think that it makes sense to try to fix this now or in a future PR? |
3c0f4d4
to
3f40d90
Compare
Good catch, fixed! |
...emminx/src/main/java/org/eclipse/lemminx/extensions/generators/xml2dtd/XML2DTDGenerator.java
Outdated
Show resolved
Hide resolved
3f40d90
to
9be0ef9
Compare
Fixed! |
Should we also worry about something like this? <root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="zero-one-schema.xsd">
<a>
<b />
</a>
<a></a>
</root> Generates: <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="a" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="b" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> Which makes the second occurrence of |
720d008
to
71845ed
Compare
...nx/src/test/java/org/eclipse/lemminx/extensions/generators/xml2dtd/XML2DTDGeneratorTest.java
Outdated
Show resolved
Hide resolved
71845ed
to
cf7bf38
Compare
Fixes eclipse-lemminx#778 Signed-off-by: azerr <azerr@redhat.com>
Yes, it was a bug which should be fixed. The <root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="zero-one-schema.xsd">
<a>
<b />
</a>
<a></a>
</root> generates now <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="a" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element name="b" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> |
Grammar generator from XML
Fixes #778
Signed-off-by: azerr azerr@redhat.com