Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.
/ Pangoro Public archive

A Kotlin parser framework with an easy-to-use DSL

License

Notifications You must be signed in to change notification settings

utybo/Pangoro

Repository files navigation

Heads up!

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.

Previous README

Pangoro Pangoro, the parser with a nice Kotlin DSL

Actions Status JVM Actions Status JS Code Climate coverage Code Climate maintainability Made with Kotlin

Experimental Release Pangoro is under active development.

>>> Documentation <<<

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")
 * )
 */

Getting Pangoro

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

Zoroark

About

A Kotlin parser framework with an easy-to-use DSL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages