How to make a Syntax Highlighting for Java in Haskell?

对着背影说爱祢 提交于 2019-12-01 07:50:08

问题


Soon enough I will be forced to present a project in Haskell that is supposed to make a Java syntax highlighting. I did some research and I found out that Happy could be a solution( since is a yacc-like parser). Also there were mentioned Bison and Parsec. Since I am new in Haskell, I really don't have any ideas how to start this project. Any tips would help a lot.

Thanks!


回答1:


Since I am new in Haskell, I really don't have any ideas how to start this project

Ah, therein lies the true question. To start learning Haskell, I often recommend Learn You a Haskell, which is free to read online. Other good resources that I recommend include Real World Haskell (slightly dated but still good) and the Typeclassopedia.

To deal with the package suggestions, you'll first want to install the Haskell Platform, and then you can install a given package with the command:

cabal install PACKAGE

Beware, though, Haskell is moving at a very fast pace so some packages are incompatible with each other. Cabal should prevent you from doing anything too stupid, but if you end up with messed up dependencies between packages, ask for help on the #haskell irc channel. You can see documentation for a given module by clicking its name on the package overview page. If a package isn't on http://hackage.haskell.org, then contact the owner or ask for help on irc, and they'll help you generate documentation and install it.

I have no idea how syntax highlighting algorithms work, so I'll leave that part for you to research on your own. If you are allowed to reuse existing work, then you'll probably use the language-java package (as suggested by Louis) to parse the raw text into Java's Abstract Syntax Tree, and then it'll be up to you to transform that syntax tree into whatever colorized format you are required to produce.

You should consult whoever is requiring this task of you before you invest serious amounts of time in any one approach, to make sure it is acceptable.




回答2:


An efficient syntax highlighting library in Haskell, using alex-generated lexers - https://github.com/jgm/illuminate




回答3:


How about bindings to libkate?




回答4:


A quick search of Hackage returns language-java. You can probably adapt its pretty-printer somehow.



来源:https://stackoverflow.com/questions/10785171/how-to-make-a-syntax-highlighting-for-java-in-haskell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!