Alternative to Lexer Hack when implementing Parser with Grammar-Kit

I am developing a plugin for language that has a similar problem as described here: https://en.wikipedia.org/wiki/Lexer_hack

Simply put, I need to distinguish between identifier and type identifier.

As far as I understand PsiBuilder implementation, it performs lexing before we start parsing, so there is no way to implement Lexer Hack (we cannot share Symbol Table as Parser and lexer have different lifetimes).

I am looking for alternative to Lexer Hack and probably resolve problem at parser level.

I wanted to use external rules to implement custom code that checks if current token is known to be a type identifier or not.

Unfortunately, I do not know what can I access to obtain this information.

Ideally, I would like to be able to build Symbol Table every time I discover a declaration, but I do not know if it is possible. Can I run my custom action for specific production rule?

 

0
1 comment

What about the alternatives described on Wikipedia? Could you combine both tokens into one identifier token?

0

Please sign in to leave a comment.