antlr4cs | The original , highly-optimized C # Target for ANTLR
kandi X-RAY | antlr4cs Summary
kandi X-RAY | antlr4cs Summary
The original, highly-optimized C# Target for ANTLR 4
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Serialize the ATN .
- Translates a left fact .
- Execute dfa .
- Generates a DOT graph for a given start state
- Show a JDialog as a dialog .
- Inline a set of rules for a rule .
- Returns the epsilon target .
- Removes set transitions from the given grammar .
- Check the dependencies of a recognizer .
- Run a lookahead rule .
antlr4cs Key Features
antlr4cs Examples and Code Snippets
Community Discussions
Trending Discussions on antlr4cs
QUESTION
edit: For those interested/who want to see exactly what I'm doing, the source code of my app can be found here.
I'm building a code editor app with C# that offers syntax highlighting. I'm currently using ANTLR for C# to parse the code in order to highlight it. So far, my app can highlight the code really fast when the user initially opens the file. However, I haven't written any code to re-highlight the text when the user starts editing it.
I want the editor to perform well for large files, so I don't want to re-parse the entire file each time the user types a character. I did a bit of research, and it seems like what I'm looking for is an incremental parser. Unfortunately, it seems like ANTLR v4 can't do incremental parsing, so I'm unsure what to do.
My question is: is there another approach I can take, using ANTLR, to not freeze the app whenever the user types? I'm really hesitant to give up on ANTLR since there are a bunch of free grammars available for it, so it's not much work to add support for a new language. I've looked into TextMate grammars, VSCode uses lots of them, but I don't understand them and there are no C# libraries available to manipulate them.
Thanks for helping!
...ANSWER
Answered 2017-Jul-18 at 00:54I don't parse after every keystroke, but I do parse the entire file. This works great for intermediate-size files in the domain-specific languages I've created. Instead of trying parse only parts of the file, I use a mixed approach, parsing when the first of either of three conditions exists:
- User types n characters
- A timer has said that there's no change in m milliseconds.
- For some grammars, user types line terminator/separator character;
Bottom line is, you might be surprised at how much time people spend pausing and thinking as they're typing in anything that imposes a grammar on them. These pauses can be exploited to do useful work while the user thinks, even for 400 milliseconds. I use #1 and #2 in the DSLs I've created for work due to their syntax.
The "no change" clock gets reset after every keystroke event and the n characters counter of course gets set when parsing occurs after n characters. I've found that a combination approach like this works well in an IDE type environment.
One thing to remember is, if you do this, don't mess with the text control's insertion point upon finding a syntax error, because errors are inescapable as they type. I simply show a message in a label:
QUESTION
I'm trying to implement syntax highlighting in C# on Android, using Xamarin. I'm using the ANTLR v4 library for C# to achieve this. My code, which is currently syntax highlighting Java with this grammar, does not attempt to build a parse tree and use the visitor pattern. Instead, I simply convert the input into a list of tokens:
...ANSWER
Answered 2017-Jun-12 at 04:27It depends on what you are syntax highlighting.
If you use a naive parser, then any syntax error in the text will cause highlighting to fail. That makes it quite a fragile solution since a lot of the texts you might want to syntax highlight are not guaranteed to be correct (particularly user input, which at best will not be correct until it is fully typed). Since syntax highlighting can help make syntax errors visible and is often used for that purpose, failing completely on syntax errors is counter-productive.
Text with errors does not readily fit into a syntax tree. But it does have more structure than a stream of tokens. Probably the most accurate representation would be a forest of subtree fragments, but that is an even more awkward data structure to work with than a tree.
Whatever the solution you choose, you will end up negotiating between conflicting goals: complexity vs. accuracy vs. speed vs. usability. A parser may be part of the solution, but so may ad hoc pattern matching.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install antlr4cs
You can use antlr4cs like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the antlr4cs component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page