Shiv
Shiv

Reputation: 107

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?

Upvotes: 0

Views: 80

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66823

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.

Upvotes: 0

Related Questions