package better_parser import com.github.h0tk3y.betterParse.combinators.* import com.github.h0tk3y.betterParse.grammar.parser import com.github.h0tk3y.betterParse.lexer.literalToken import com.github.h0tk3y.betterParse.parser.Parser import prolog.ast.arithmetic.ArithmeticOperator import prolog.ast.logic.* import prolog.ast.terms.* import prolog.builtins.Conjunction import prolog.builtins.Disjunction open class SimpleSourceParser : SimplePrologParser() { protected val simpleLogicOperand: Parser by (dummy or compound or atom ) protected val logicOperand: Parser by (dummy or parser(::operator) or simpleLogicOperand ) protected val arithmeticOperator: Parser by dummy protected val logicOperator: Parser by (simpleLogicOperand * comma * logicOperand) use { Conjunction(t1, t3) } protected val operator: Parser by (arithmeticOperator or logicOperator) use { this as Operator } protected val head: Parser by (dummy or compound or atom ) protected val body: Parser by (dummy or operator or head ) use { this as Body } // ---- private val rule: Parser by (head * -neck * body) use { Rule(t1, t2) } private val fact: Parser by head use { Fact(this) } private val clause: Parser by ((rule or fact) * -dot) private val clauses: Parser> by zeroOrMore(clause) override val rootParser: Parser by clauses }