27 lines
No EOL
805 B
Kotlin
27 lines
No EOL
805 B
Kotlin
package better_parser
|
|
|
|
import com.github.h0tk3y.betterParse.combinators.times
|
|
import com.github.h0tk3y.betterParse.combinators.unaryMinus
|
|
import com.github.h0tk3y.betterParse.combinators.use
|
|
import com.github.h0tk3y.betterParse.grammar.parseToEnd
|
|
import com.github.h0tk3y.betterParse.parser.Parser
|
|
import prolog.ast.logic.LogicOperand
|
|
import prolog.builtins.Query
|
|
|
|
class SimpleReplParser(val debug: Boolean = false) : SimpleSourceParser() {
|
|
override val rootParser: Parser<Query> by (body * -dot) use { Query(this as LogicOperand) }
|
|
|
|
fun parse(input: String): Query {
|
|
if (debug) {
|
|
println("Parsing input: $input")
|
|
}
|
|
|
|
val query = parseToEnd(input) as Query
|
|
|
|
if (debug) {
|
|
println("Parsed query: $query")
|
|
}
|
|
|
|
return query
|
|
}
|
|
} |