puffnfresh / roy

Small functional language that compiles to JavaScript.
http://roy.brianmckenna.org/
MIT License
834 stars 74 forks source link

IDL binding generator #18

Open puffnfresh opened 12 years ago

puffnfresh commented 12 years ago

Should be possible to take IDL:

http://en.wikipedia.org/wiki/Interface_description_language

And convert it to Roy type aliases:

type Document = {
  getElementById: String -> Element
} with Node

(etc)

Then with externs:

https://github.com/pufuwozu/roy/issues/17

We could:

external document = Document
paulmillr commented 12 years ago

So, it's adding static typing to existing things?

:+1:

piranha commented 12 years ago

Do you want to use some existing IDL? Or just Roy types? I don't really care though, anything would be nice.

puffnfresh commented 12 years ago

IDL definitions come with the DOM specifications (e.g. DOM level 2). They describe the type signatures used in those standards.

So for us: input is IDL, output is Roy type aliases. Using that we'd have statically typed bindings to the DOM.

piranha commented 12 years ago

Ah, great then, would really cool to have type-checked DOM manipulation! :)

DamonOehlman commented 12 years ago

I'd be happy to have a look at this one, if you had some pointers on where to start. I found an IDL grammar for antlr but haven't really got a good idea on how to convert this to something usable in JS land...

Compilers and parsers definitely aren't my strength, but I think this has some value and is reasonably self contained so would love to help out :)

puffnfresh commented 12 years ago

@DamonOehlman a better way to do this has come up since I filed it. Roy now outputs a .roym file which describes the exports of a module. The problem is that I haven't documented the format.

It looks something like:

obj: {x: Number, y: Number, t: String}

Where obj is an identifier the right hand side is a type. I'm guessing the IDL grammer will output something like this:

type Element = {
}
document: {
  getElementById: Function(String, Element)
}

Not sure if that will work since I haven't tested anything that complicated.

puffnfresh commented 11 years ago

Was told I should look into domconv, especially the WebKit fork (whose IDL contains some useful extensions):

https://github.com/ghcjs/domconv-webkit