Pangoro and Lixy have been replaced by Tegal Niwen (GitHub). This evolved version of Pangoro and Lixy feature parser type-safety, more expectations and matchers, an awesome execution debugger and much more! This repository will no longer be updated.
Pangoro is under active development.
Pangoro is a parser intended for use with the Lixy lexer, although it can also work with anything, provided that you convert your tokens into Lixy tokens.
// Types used by the parser (PangoroNode) and lexer (LixyTokenType)
data class Number(val value: String) : PangoroNode {
companion object : PangoroNodeDeclaration<Number> by reflective()
}
data class Sum(val first: Number, val second: Number) : PangoroNode {
companion object : PangoroNodeDeclaration<Addition> by reflective()
}
enum class Tokens : LinkTokenType {
Number, Plus
}
// Lexer (from Lixy)
val lexer = lixy {
state {
matches("\\d+") isToken Tokens.Number
"+" isToken Tokens.Plus
" ".ignore
}
}
// Parser (from Pangoro)
val parser = pangoro {
Number {
expect(Tokens.Number) storeIn "value"
}
Sum root {
expect(Number) storeIn "first"
expect(Tokens.Plus)
expect(Number) storeIn "second"
}
}
val tokens = lexer.tokenize("123 + 4567")
val ast: Sum = parser.parse(tokens)
/*
* ast = Sum(
* first = Number(value = "123"),
second = Number(value = "4567")
* )
*/
You can get the following artifacts from Jitpack:
- Kotlin/JVM:
guru.zoroark.pangoro:pangoro-jvm:version
- Kotlin/JS:
guru.zoroark.pangoro:pangoro-js:version
- Kotlin MPP:
guru.zoroark.pangoro:pangoro:version