package parser.grammars

import com.github.h0tk3y.betterParse.combinators.*
import com.github.h0tk3y.betterParse.parser.Parser
import prolog.ast.logic.Clause
import prolog.ast.logic.Fact
import prolog.ast.logic.Rule
import prolog.ast.terms.Atom

class LogicGrammar : TermsGrammar() {
    protected val constraint: Parser<Rule> by (-neck * body) use {
        Rule(Atom(""), this)
    }
    protected val rule: Parser<Rule> by (head * -neck * body) use { Rule(t1, t2) }
    protected val fact: Parser<Fact> by head use { Fact(this) }

    protected val clause: Parser<Clause> by ((rule or constraint or fact) * -dot)
    protected val clauses: Parser<List<Clause>> by oneOrMore(clause)

    override val rootParser: Parser<Any> by clauses
}
