ceylon / ceylon-runtime

DEPRECATED
24 stars 5 forks source link

A Ceylon module that reuses the typechecker #47

Closed gavinking closed 11 years ago

gavinking commented 11 years ago

In this issue we came across the fact that it is basically impossible to write a Ceylon module that reuses the typechecker. The problem is likely somehow connected to dependencies in the lib/ dir, but JBoss Modules is not producing very helpful error messages, and so I was not able to arrive at a better understanding of what was going on.

The Ceylon code I want to make work is:

import com.redhat.ceylon.compiler.typechecker.parser { CeylonLexer }
import org.antlr.runtime { ANTLRInputStream }

shared void run() {
    value ceylonLexer = CeylonLexer(ANTLRInputStream());
}
gavinking commented 11 years ago

Actually the solution is pretty straightforward. All we need to do is move ANTLR into the repo and out of lib. Then everything works fine.

quintesse commented 11 years ago

Were you able to make it work?

gavinking commented 11 years ago

Yes, I was, all documented in ceylon/ceylon-ide-eclipse#385.

quintesse commented 11 years ago

@gavinking I see that in the issue you link to you added org.antlr.runtime to the repository while in the lib folder we have antlr-3.4-complete.jar which contains much more than the runtime (it's actually 3-4 JARs that have been put together in one). Do you know if using the antlr runtime would be enough for the compiler?

gavinking commented 11 years ago

I just renamed antlr-3.4-complete.jar to org.antlr.runtime using the Export Java Archive wizard in the IDE. It's the same jar.

quintesse commented 11 years ago

Ok @gavinking , this now works. I actually tested this with the real antlr-runtime and it works perfectly (I'm guessing antlr-complete is only needed for building ceylon-spec) so I added that as a module, which saves us over 2MB on the distribution size (yay!).

You'll need to update ceylon-dist and then do the normal ant update-all clean publish-all jig.

lucaswerkmeister commented 11 years ago

Why is the new module called org.antlr-runtime instead of org.antlr.runtime (notice the hyphen)? That's not a valid identifier...

gavinking commented 11 years ago

I wondered this too.

quintesse commented 11 years ago

It's because the makers of antlr themselves call it that way for Maven and I just copied that name. But today for ceylon/ceylon-dist#32 I made some other decisions because sometimes the Maven name is so different form what we would use. So I'm not sure what the best way is.

Btw, it's perfectly legal for imports to have hyphens, just enclose the name in quotes.

lucaswerkmeister commented 11 years ago

Btw, it's perfectly legal for imports to have hyphens, just enclose the name in quotes.

Alright, that works. FTR, they have to be single quotes; import "org.antlr-runtime" "3.4" gives me this error:

cannot find module source artifact "org.antlr-runtime"-3.4(.src|.car|.jar)

  • dependency tree: source_gen.ceylon.formatter/1.0.0 -> ceylon.formatter/1.0.0 -> "org.antlr-runtime"/3.4

-- it appears that whatever transforms the module name+version into a file name only strips single quotes from the module name.

gavinking commented 11 years ago

FTR, they have to be single quotes

Ooops, thanks, I have fixed this bug in the typechecker and added a test.

On Thu, Oct 17, 2013 at 11:16 AM, Lucas Werkmeister < notifications@github.com> wrote:

Btw, it's perfectly legal for imports to have hyphens, just enclose the name in quotes.

Alright, that works. FTR, they have to be single quotes; import "org.antlr-runtime" "3.4" gives me this error:

cannot find module source artifact "org.antlr-runtime"-3.4(.src|.car|.jar)

  • dependency tree: source_gen.ceylon.formatter/1.0.0 -> ceylon.formatter/1.0.0 -> "org.antlr-runtime"/3.4
    • it appears that whatever transforms the module name+version into a file name only strips single quotes from the module name.

— Reply to this email directly or view it on GitHubhttps://github.com/ceylon/ceylon-runtime/issues/47#issuecomment-26489552 .

Gavin King gavin@ceylon-lang.org http://profiles.google.com/gavin.king http://ceylon-lang.org http://hibernate.org http://seamframework.org

quintesse commented 11 years ago

I could have sworn I had opened an issue for this! But I can't find it anymore so I must have been dreaming.

Btw, shall we get rid of the single quotes? I see all kinds of places that mix them, some use single quotes, others use double quotes. In the rest of the language single quotes are only used for characters so it's not really consistent, right? I'll do the search and replace if you want :)

gavinking commented 11 years ago

Btw, shall we get rid of the single quotes?

They are not an official part of the language, they are left in only for backward compatibility.

quintesse commented 11 years ago

Sure, but that's something we can easily fix now we're still pre-1.0, right? Right now we break things all the time :)

lucaswerkmeister commented 11 years ago

It sounds to me like now would be the best time to get rid of them.

gavinking commented 11 years ago

I mean, it's a just a totally trivial change to the grammar.

quintesse commented 11 years ago

So why not do it? Wouldn't it make the language a tiny bit more regular that way? (sequences or characters use ", single characters use ' )

lucaswerkmeister commented 11 years ago

here's the relevant part of the grammar. It actually appears that we allow single quotes for the version number as well.

gavinking commented 11 years ago

Wouldn't it make the language a tiny bit more regular that way?

Which part of "not an official part of the language" did you not understand? :)

quintesse commented 11 years ago

Sure, but most people are not going to read the spec, trust me ;)

So they'll just look at examples, copy some code and because some of it contains single quotes they'll start doing so as well.Hey the compiler accepts it, so why not? And before you know it you can't change it anymore because it would break a lot of code (and for what?)

gavinking commented 11 years ago

So in @bb97c56 I have changed the typechecker to produce a meaningful error in this case. This will most likely break a bunch of tests in other subprojects, so it is now @quintesse's punishment to go and search for and fix any breakage.

quintesse commented 11 years ago

Hahaha! Oh the joy! ;)

lucaswerkmeister commented 11 years ago

Here's a GitHub search that finds loads of these module descriptors.

gavinking commented 11 years ago

The SDK uses single-quoted versions all over the place.

tombentley commented 11 years ago

You might be able to use the new ceylon version tool to do this really easily.

quintesse commented 11 years ago

Done. Luckily almost no documentation used single quotes in the text so I could mostly just do:

find . -name module.ceylon -exec sed -i -e s/\'/\"/g {} \;