An open API service indexing awesome lists of open source software.

https://github.com/zhirzh/kotlin-parser-antlr


https://github.com/zhirzh/kotlin-parser-antlr

antlr4 kotlin parser

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

          

# Kotlin parser

Kotiln parser that generates a concrete syntax tree using, parser class generated by [ANTLR v4][] and kotlin grammar taken from [kotlinx/ast][].

# Build grammar

Follow these steps to build grammar classes:

1. Download [antlr4 grammar][] for Kotlin
1. Download [ANTLR tool itself][]
1. Install Java 8 JRE or JDK

With everything setup, run the following BASH script to generate classes `KotilnLexer` & `KotlinParser`.

```bash
#! /bin/bash

out_dir=./src/kotlin

# cleanup previous built files
rm -r $out_dir

# build files
java -jar \
-Dlanguage=JavaScript \
-no-listener \
-Xexact-output-dir \
-o $out_dir/ \

# cleanup
rm $out_dir/*.interp
rm $out_dir/*.tokens
```

[antlr v4]: https://github.com/antlr/antlr4#antlr-v4
[kotlinx/ast]: https://github.com/kotlinx/ast#kotlinxast
[antlr4 grammar]: https://github.com/kotlinx/ast/tree/master/grammar-kotlin-parser-common/src/commonAntlr/antlr
[antlr tool itself]: https://www.antlr.org/download/antlr-4.9.2-complete.jar