Domanda

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!

È stato utile?

Soluzione

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.

Altri suggerimenti

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

How about bindings to libkate?

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top