elm-tooling / tree-sitter-elm

Tree sitter implementation for elm
https://elm-tooling.github.io/tree-sitter-elm/
MIT License
75 stars 14 forks source link

Port scanner code to C? #119

Closed jwoudenberg closed 2 years ago

jwoudenberg commented 2 years ago

Hi there! One thing I've been playing with recently is trying to create statically linked binaries for my little tool elm-pair which pulls in the tree-sitter-elm rust package. I'm running into some errors related to the C++ dependencies required because of the custom scanner.cc code. Linking C and C++ is definitely outside my area of expertise so I could probably invest a bit of time and figure out how to get this to work. However, another approach that occured to me would be to port the scanner.cc code to C. I'd have to try this out, but my understanding of the code is that it's not relying on a ton of C++ specific functionality, and turning the existing methods into functions that pass around scanner state as struct sounds like it should be doable.

Would you be interested in a change like that or do you prefer to keep that code in C++?

razzeee commented 2 years ago

I kinda fear, that my C understanding will be even worse then my current C++.

Maybe the linking problems are something you could ask on the discussions of the https://github.com/tree-sitter/tree-sitter/discussions repo. I would think that there are already people that solved this.

harrysarson commented 2 years ago

I looked at this while ago and came to the conclusion that porting the scanner to c would be a major sacrifice in terms of code quality and maintainability.

The code for instance uses the STL and writing a new std::vector in c would be a mistake I think.

harrysarson commented 2 years ago

They call it c "plus plus" for a reason after all.

I think it should be possible to statically link libstdc++ though. Happy to chat on discord or slack if there are c++ specific questions. :)

jwoudenberg commented 2 years ago

That makes a lot of sense. Thank you both for talking me out of this, and the tips for c++ linking!