I am implementing an auto code completion functionality and I am using ANTLR parser for my project. I would like to know if there is a definite way of achieving this in ANTLR 4 API. I am happy to provide more detailed specification of my implementation. I have posted a question on SO on this.
Hi Mike,
Your final statement regarding avoiding the use of a parser couldn’t be more wrong. GoWorks exclusively uses the ANTLR 4 parsing infrastructure to gather information necessary for code completion. ANTLRWorks 2 uses this as well, although the result is not quite as interesting because the grammar language is so simple.
That said, it does require heavy modifications of the default behavior to gather this information (at least in my implementation). Among other things, the code uses:
1. The -Xforce-atn option, which forces the parser to use adaptivePredict even for decisions which appear to be statically LL(1). This allows me to “pretend” tokens are tokens of different types and see how it affects parsing. For example, if “object” is a keyword, with this option I can use a custom prediction algorithm to force “object” to be treated as an identifier so I can see what the results would look like if the user were 1 character away from typing “object1”.
2. A class derived from ParserATNSimulator with custom analysis and control hooks.
3. Many listener and visitor implementations.
4. A custom error strategy implementation.
Sam
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Your final statement regarding avoiding the use of a parser couldn’t be more wrong. GoWorks exclusively uses the ANTLR 4 parsing infrastructure to gather information necessary for code completion. ANTLRWorks 2 uses this as well, although the result is not quite as interesting because the grammar language is so simple.That said, it does require heavy modifications of the default behavior to gather this information (at least in my implementation). Among other things, the code uses:1. The -Xforce-atn option, which forces the parser to use adaptivePredict even for decisions which appear to be statically LL(1). This allows me to “pretend” tokens are tokens of different types and see how it affects parsing. For example, if “object” is a keyword, with this option I can use a custom prediction algorithm to force “object” to be treated as an identifier so I can see what the results would look like if the user were 1 character away from typing “object1”.2. A class derived from ParserATNSimulator with custom analysis and control hooks.3. Many listener and visitor implementations.4. A custom error strategy implementation.