Code generation for Scalatags

105 views
Skip to first unread message

Richard Gomes

unread,
Jul 27, 2014, 4:53:25 PM7/27/14
to scal...@googlegroups.com
Hello everyone,

I've stumbled with a difficulty involving several attributes missing in Scalatags.
I've sent a push request contributing some definitions but a quick visual inspection in the HTML 4.01 DTD tells me that there are several other missing attributes.

I've found tools which reads a DTD and generate XSD. One of these tools is particularly interessant because there's an example of generation of code which would match the DTD. So, thought that with relatively little effort would be possible to read, for example, the HTML 4.01 Transitional.dtd and automagically generate scalatags.generic.{Tags, Attrs} and scalatags.text.{Tags}.

The big selling point is that code generation once done write eliminates the need of manually reading the specs in MDN and writing down attribute by attribute in Scala. The big disadvantage is that it would not generate any comments at all for attributes. But it would be possible, at least, to map with certainty all tags which are missing, given a certain DTD. This would help on SVG, MathML and several other cases.

Thoughts?

-- Richard Gomes

Haoyi Li

unread,
Jul 27, 2014, 9:07:46 PM7/27/14
to Richard Gomes, scal...@googlegroups.com
I feel that it's not such a huge deal to write/copy them down manually; the DTD doesn't change much, or often. Furthermore, a pretty large fraction of Scalatags' usefulness for HTML (for me at least) is the abilities to inline styles into it, which doesn't really apply to other markups and doesn't have a DTD i'm aware of.

On the other hand, if you can pull it off and get it to work well, I'd be all for it =) it would be cool to have Scalatags bindings for other markups, but I'm not going to put in the effort to write/maintain them since I don't have a use case.


--
You received this message because you are subscribed to the Google Groups "Scalatags" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatags+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Gomes

unread,
Jul 29, 2014, 8:26:29 PM7/29/14
to Haoyi Li, scal...@googlegroups.com
Hello Li,

I've done something very basic (and possibly wrong or at least incomplete) by employing linux text tools.
Long story short, I've found sort of 2 dozen attributes missing from HTML 4.01 Transitional.

This approach serves to me for my immediate purposes and tests, but... if it's not correct... it's simply wrong.
I will investigate a bit more this subject and let you know.

For the moment, I've detected that the current master on http://github.com/lihaoyi/scalatags does not compile :(
So, I guess we should really have a tool which guarantees that the right thing is generated.

Cheers

Richard Gomes
http://rgomes.info
http://www.linkedin.com/in/rgomes
mobile: +44(77)9955-6813
inum: +883(5100)0800-9804
sip:rgo...@ippi.fr

Haoyi Li

unread,
Jul 29, 2014, 8:30:55 PM7/29/14
to Richard Gomes, scal...@googlegroups.com
Yeah, the master is broken, gimme a day or so and I'll put a fixed version up =)

Yeah, continuous integration and build-and-test-on-diff would be nice. I don't know how/haven't set that up yet.

Richard Gomes

unread,
Jul 30, 2014, 6:08:42 AM7/30/14
to scal...@googlegroups.com, rgome...@gmail.com
FYI,

In my account there's a version with additional attributes which I retrieved from the DTD.
In a nutshell, they were obtained from '#IMPLIED' and '#REQUIRED' attributes from the DTD.
Just look at the bottom of the file:

    https://github.com/frgomes/scalatags/blob/master/shared/main/scala/scalatags/generic/Attrs.scala

As I said before: this approach is probably wrong and incomplete. I will spend some more effort (as time permits) trying to obtain a proper list of attributes, using a proper parser, instead of a hammered shell script.

I guess that it would be possible to retrieve groups of attributes where eventually an attribute could belong to several groups. What I mean to say is that it would be possible to provide strict semantics conformant to HTML4.01 and/or other schemas. But I know that such sort of consistency is outside of the plans of Scalatags. Just to let you know and share ideas.

Regarding CI and this sort of stuff:
I just merge locally on my machine and run "sbt test" before pushing onto git.
Ci is beautiful for showing off test coverage ;-)  ... not something I'm deeply concerned.

Cheers

Richard Gomes

unread,
Jul 30, 2014, 6:03:13 PM7/30/14
to scal...@googlegroups.com
Hello Li,

None of the tools I've tried to convert DTD to other formats seem to be robust enough :(
But I found these pages below which contain all information we need, I suppose.

HTML4   http://www.w3.org/TR/html4/index/attributes.html

HTML4.01 http://www.w3.org/TR/html401/index/attributes.html

Please let me know if you wish I process these pages and generate data structures or code.

Thanks


Richard Gomes
http://rgomes.info
http://www.linkedin.com/in/rgomes
mobile: +44(77)9955-6813
inum: +883(5100)0800-9804
sip:rgo...@ippi.fr

Reply all
Reply to author
Forward
0 new messages