Search code examples
antlrantlr4sharpdevelopcode-editornrefactory

Code Editor with intellisense for ANTLR4


Looking for sample for building ANTLR4 grammar based Code Editor with intellisense. SharpDevelop provides all Code Editor features, however if we need to provide the intellisense and Code Completion details, then we need to write own parser.

Need sample where ANTLR4, SharpDevelop is used for building the Code Editor for custom language.

Thanks.


Solution

  • I could get the expected Tokens from ANTLR4 using GetExpectedTokensWithinRule API in the Listener and converting them to tokens.

    pseudo code looks like this

    public class MyGrammarListener : MyGrammarBaseListener
    {
           public MyGrammarListener(MyGrammarParser parser)
            {
                 this.Parser = parser;
            }
    
            public override void EnterXXXXX(XXXXX_Context context)
            {
                IntervalSet set = Parser.GetExpectedTokensWithinCurrentRule();
                base.EnterXXXXX(context);
                foreach (int token in set.ToIntegerList())
                {
                   // Returns the expected tokens.
                   string data = Parser.Vocabulary.GetLiteralName(token);
                }
            }
    

    }