How can I use a hand built lexer for custom language?

Hello,

Currently my hand built lexer batch processes a file in one go and outputs the tokens. For highlighting I understand we want incremental relexing of the input buffer. Regarding this I had two questions:

1. Will my lexer get startoffset or endoffset which is in the middle of a token or a line, and hence should be able to deal with invalid input i.e. mark it as invalid or something similar? What problems can occur if I just reinitialize the lexer and start indexing the modified code snippet as a new code snippet?

2. Can I plugin a lexer to Intellij IDEA anywhere else apart from the standard Lexer interface to enable highlighting, PSI building etc?

I am using Intellij Idea 9.0.3

thanks
Siddharth

1 comment
Comment actions Permalink

Hello Siddharth,

The start offset passed to your lexer should never be in the middle of a
token, but it can definitely be in the middle of a line because the general
lexer interface doesn't know anything about lines. If your lexer is not stateful,
there should be no problems in lexing the modified code snippet as a new one.

If you want your lexer to be used by IDEA, it needs to implement the Lexer
interface. There is no other way.

Currently my hand built lexer batch processes a file in one go and
outputs the tokens. For highlighting I understand we want incremental
relexing of the input buffer. Regarding this I had two questions:

1. Will my lexer get startoffset or endoffset which is in the middle
of a token or a line, and hence should be able to deal with invalid
input i.e. mark it as invalid or something similar? What problems can
occur if I just reinitialize the lexer and start indexing the modified
code snippet as a new code snippet?

2. Can I plugin a lexer to Intellij IDEA anywhere else apart from the
standard Lexer interface to enable highlighting, PSI building etc?

I am using Intellij Idea 9.0.3


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.