REPL checkpoint
This commit is contained in:
parent
69c156024a
commit
1b3280a947
21 changed files with 503 additions and 34 deletions
48
src/better_parser/SimpleSourceParser.kt
Normal file
48
src/better_parser/SimpleSourceParser.kt
Normal file
|
@ -0,0 +1,48 @@
|
|||
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<LogicOperand> by (dummy
|
||||
or compound
|
||||
or atom
|
||||
)
|
||||
protected val logicOperand: Parser<LogicOperand> by (dummy
|
||||
or parser(::operator)
|
||||
or simpleLogicOperand
|
||||
)
|
||||
|
||||
protected val arithmeticOperator: Parser<ArithmeticOperator> by dummy
|
||||
protected val logicOperator: Parser<LogicOperator> by (simpleLogicOperand * comma * logicOperand) use {
|
||||
Conjunction(t1, t3)
|
||||
}
|
||||
|
||||
protected val operator: Parser<Operator> by (arithmeticOperator or logicOperator) use { this as Operator }
|
||||
|
||||
protected val head: Parser<Head> by (dummy
|
||||
or compound
|
||||
or atom
|
||||
)
|
||||
protected val body: Parser<Body> by (dummy
|
||||
or operator
|
||||
or head
|
||||
) use { this as Body }
|
||||
|
||||
// ----
|
||||
|
||||
private val rule: Parser<Rule> by (head * -neck * body) use { Rule(t1, t2) }
|
||||
private val fact: Parser<Fact> by head use { Fact(this) }
|
||||
|
||||
private val clause: Parser<Clause> by ((rule or fact) * -dot)
|
||||
private val clauses: Parser<List<Clause>> by zeroOrMore(clause)
|
||||
|
||||
override val rootParser: Parser<Any> by clauses
|
||||
}
|
Reference in a new issue