Kotlin ANTLR grammar correctness verification by comparing trees created both with ANTLR autogenerated parser and the real parser.
Input | Output |
---|---|
Kotlin language source code | Parsing and comparison report with ability to check out the subtrees in which the difference was found |
- The
KotlinFileContext
object is created using the generated by ANTLR toolKotlinLexer
andKotlinParser
classes. If parsing errors are detected, no further validation occurs - The real AST stored in
KtFile
object is generated using Kootstrap - For future analysis the resulting objects are wrapped into auxiliary wrapper classes
- The comparison is recursive. If a difference in the subtrees is found, the information is stored as an
ComparisonError
object, and verification continues
- There are several ANTLR rules which can be considered as redundant. Redundant rules are created just to simplify the grammar and skipped when verified
- Our goal is to check if the trees are homeomorphic by smoothing out vertices from the ANLTR-generated parse tree