REPL checkpoint
This commit is contained in:
parent
69c156024a
commit
1b3280a947
21 changed files with 503 additions and 34 deletions
27
src/better_parser/SimpleReplParser.kt
Normal file
27
src/better_parser/SimpleReplParser.kt
Normal file
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
}
|
||||
}
|
Reference in a new issue