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

Clojure(Script) support #217

Open
emlyn opened this issue Aug 3, 2019 · 13 comments
Open

Clojure(Script) support #217

emlyn opened this issue Aug 3, 2019 · 13 comments
Labels
enhancement New feature or request help wanted Up for grabs language-support Language support in general (e.g. new languages, etc.)

Comments

@emlyn
Copy link

emlyn commented Aug 3, 2019

Any possibility of adding Clojure/ClojureScript support?

@robrix robrix added language-support Language support in general (e.g. new languages, etc.) enhancement New feature or request help wanted Up for grabs labels Aug 3, 2019
@robrix
Copy link
Contributor

robrix commented Aug 3, 2019

Clojure & ClojureScript aren’t at the top of our list right now, but we’re working on making it easier for third parties to add support for new languages to semantic. A good place to start would be by defining a tree-sitter parser for Clojure/ClojureScript; see for example the docs on adding support for new languages and the grammar development guide.

@emlyn
Copy link
Author

emlyn commented Aug 5, 2019

Thanks for the response. I've had a look around and found a couple of implementations here and here. I suppose the next step would be to add one of these to haskell-tree-sitter?

@robrix
Copy link
Contributor

robrix commented Aug 9, 2019

Yep!

@cgay
Copy link

cgay commented Nov 8, 2019

Since Clojure has macros, how will this work? It seems to me that for any language with macros that allow creation of new syntactic constructs (any Lisp dialect, Julia, Rust (?)) it would be far easier to use a client / server architecture (like I believe Kythe has) so that the AST generators that have already been written for those languages can be leveraged, rather than trying to write an incomplete version in Haskell.

Am I wrong here? I'm kind of curious because as a Dylan enthusiast I think it would be awesome to have this feature for our GitHub-hosted code. I decided to piggyback on this bug rather than ask separately for Dylan.

@patrickt
Copy link
Contributor

patrickt commented Nov 9, 2019

@cgay It is as of yet an open question as to how we’ll deal with languages that support truly arbitrary rewritings of their syntax (e.g. C with the preprocessor). Whatever we do, we’ll end up aiming for the happy path—we may not be able to understand every possible macro invocation, but we should at the very least be able to handle most real-world code, especially given that tree-sitter parsers continue parsing even in the presence of syntax errors. Note that many languages with macros don’t require special knowledge in their parser, e.g. tree-sitter-rust.

Our roadmap going forward is not to write Haskell code to parse language grammars, but to generate per-language Haskell AST declarations from tree-sitter grammars. A client-server model a la Kythe is not desirable for architectural and legacy reasons: an approach with tree-sitter as the lingua franca is a lower maintenance burden than trying to corral N different language servers into a common vocabulary. See here and here for more discussion on why we’ve chosen a monolithic architecture.

@cgay
Copy link

cgay commented Nov 9, 2019

For Common Lisp I believe it's literally impossible to do a perfect job finding cross references unless you are the Common Lisp compiler, since arbitrary code can be run to generate new code at macro-expansion time.

Dylan (and I believe Scheme) is a little more amenable since its macro system is just a pattern matcher, but I think for Dylan you'd need to basically re-implement the macro expander [edit: and the module system] in Haskell to figure out what definitions are being referenced in the generated code.

@dijonkitchen
Copy link

Can https://github.com/Engelberg/instaparse help?

@robrix
Copy link
Contributor

robrix commented Dec 6, 2019

For Common Lisp I believe it's literally impossible to do a perfect job finding cross references unless you are the Common Lisp compiler, since arbitrary code can be run to generate new code at macro-expansion time.

Yes, this is (an example of) why semantic does program analysis.

@cgay
Copy link

cgay commented Dec 7, 2019

Yes, this is (an example of) why semantic does program analysis.

?

[edit] To clarify, I don't see how that addresses the problem I'm describing.

@robrix
Copy link
Contributor

robrix commented Dec 9, 2019

We can do the same things as the compiler, including evaluating macros (subject to certain approximations).

@cgay
Copy link

cgay commented Dec 10, 2019

And when the macro uses data that's only available at run-time in order to generate the code, or generates different code for different Common Lisp implementations? :-)

Anyway, hopefully your approach will work for more popular languages like Rust, Clojure, and Julia, which also have robust syntax extension mechanisms.

@robrix
Copy link
Contributor

robrix commented Dec 10, 2019

And when the macro uses data that's only available at run-time in order to generate the code, or generates different code for different Common Lisp implementations? :-)

That’s when the approximations become relevant: we’ll generate a set of results.

@borkdude
Copy link

borkdude commented May 2, 2021

Note that meanwhile a static analyzer for Clojure appeared on the scene:

https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md

This analyzer is used by tools like clojure-lsp to provide navigation and refactoring. This tool is available as a standalone command line utility as well (or can be compiled into a native library if that is useful from Haskell, but you might as well just shell out to it). It's also available as a JVM library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Up for grabs language-support Language support in general (e.g. new languages, etc.)
Projects
None yet
Development

No branches or pull requests

6 participants