简体   繁体   中英

Getting tokens from OCaml lexer

I am currently working on a terminal-based text editor. I want to support a type of syntax highlighting for.ml files I open up in the text editor. I was thinking that if there was a way that I could access the lexer used for OCaml in general, then maybe I could use that lexer to color the text I read from.ml files appropriately.

Is this possible?

It's definitely possible to extract the lexer from the OCaml compiler. I have done it myself for a few different projects. It might even be easier now than when I looked at the problem, because there is a software interface to the compiler internals.

On the other hand, it seems to me that some aspects of syntax highlighting depend on the syntax rather than just on the lexical structure. (Hence the name:-) So you might not get some fancier parts of the feature.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM