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

Latest commit

 

History

History
73 lines (57 loc) · 3.16 KB

README.md

File metadata and controls

73 lines (57 loc) · 3.16 KB

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