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

More precise typing of XML elements #177

Open
jclark opened this issue Jun 2, 2019 · 8 comments
Open

More precise typing of XML elements #177

jclark opened this issue Jun 2, 2019 · 8 comments
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Jun 2, 2019

We can build on #176 to provide more precise typing of XML elements, by making an xmlelement have type parameters xmlelement<E,A,C>, where

  • E is a subtype of string specifying the element name
  • A is a subtype of map<string> specifying attributes, and
  • C is a subtype of xml<xmlelement|string> specifying type of x.getChildren().strip() (this is because you want comments, PIs, and whitespace to always automatically allowed)

We can then use our type system to write a useful schema for an XML document. Other things that would make this work better include:

  • add xml.getChildrenStrip()
  • xmlempty that matches an empty xml sequence (for empty elements)
  • if ns is declared as a namespace prefix
    • allow ns:x as a const string and type standing for the corresponding expanded name
    • allow ns:foo as the name of a field in a record type (for namespace qualified attributes)
    • allow ns:* as a subtype of string type

This doesn't deal with the ordering or cardinality of child elements. I think ordering would be very hard, but perhaps cardinality is doable. By cardinality I mean saying that this element has between M and N elements named foo (typically M is 0 or 1 and M is 1 or unlimited).

@jclark jclark added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Jun 2, 2019
@jclark jclark added this to the 2019Rn milestone Jun 2, 2019
@jclark jclark mentioned this issue Jun 3, 2019
@sanjiva
Copy link
Contributor

sanjiva commented Jun 3, 2019

If we are doing cardinality we should consider it for records to be able to do better schemas for json too.

See: https://docs.google.com/document/d/1U7tCYaTC9Xx2pKeNrH-Xdw14zPHGm9T2uWTE52SPw10/edit for json schema to Ballerina mapping work.

@jclark
Copy link
Collaborator Author

jclark commented Jun 3, 2019

What is cardinality for records in JSON schema?

@jclark
Copy link
Collaborator Author

jclark commented Jun 3, 2019

So in our terms a min/max constraint on the length of a mapping value? That's pretty funky. Not obvious to me what the use cases for that are.

@sanjiva
Copy link
Contributor

sanjiva commented Jun 3, 2019

Yes that's what it means. Definitely funky ..

@jclark
Copy link
Collaborator Author

jclark commented Jun 3, 2019

There's a reasonably obvious syntax for us for the array case T[5...17], which I think it much more common.

@jclark
Copy link
Collaborator Author

jclark commented Jun 28, 2019

Note that this issue is not about extending the value space of the XML basic type to handle the PSVI (see issue #249), it's about being able to describe useful subtypes of the our current XML value space.

@jclark
Copy link
Collaborator Author

jclark commented Jun 28, 2019

There is an obvious way to handle ordering and cardinality, which is described in issue #251.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

2 participants