- Parser is busy
- Initial parsing time: µ
- Last modification parsing time: µ
- Lines parsed:
- Characters parsed:
- AST nodes:
Papa Carlo Demo
This little demo application illustrates the idea of incremental compilation in action.
You can type something in the source code panel on the left side. The changes will be applied immediately to the Abstract Syntax Tree visual represenation on the right side.
Also if you click on any AST node, the application highlights fragment of the source code corresponding to that Node.
What's so special about "incremental"?
An incremental compiler is one that can recompile only those portions of a program that have been modified. Ordinary compilers must process entire source code file.
Therefore, when the end user makes small and frequent changes in the source code, the incremental compiler usually indexes them immediately, without any significant time delays. Even if the program consists of thousands lines of code.
More interesting is that this compiler updates resulting Abstract Syntax Tree incrementally too by invalidating only affected parts of the Tree. An incremental compiler should be able to perform these updates even if the source code contains syntax errors.
These properties are very important in development of source code analysis tools.
What are use cases?
Of course, JSON parser is just a conceptual example. However, Papa Carlo framework can be used to build incremental compilers of major programming language such as Java, C#, Objective-C, etc.
For example, these compilers can serve as core components in development of full featured in-browser Web IDE with code analysis and refactoring tools comparable to the class of modern desktop IDEs like Eclipse, Visual Studio or IntelliJ Idea.
Is it hard to implement incremental compiler?
This JSON compiler consists of just a few lines of source code written in Scala. The structure of the compiler code should be familiar to developers who have ever worked with ordinary PEG/CFG parser combinator libraries.
Fortunately, all of the incremental "magic" is hidden inside the Papa Carlo internals. So the developer may leverage these features out of the box.
- An article about client-server incremental compilation architecture: Handy incremental parser.
- Papa Carlo on Github: Eliah-Lakhin/papa-carlo. Support the project, give it a star.
- Project's website, documentation, tutorials: http://lakhin.com/projects/papa-carlo/.
- User support forum: papa-carlo@googlegroups.