feat(wpcarro/simple-select): Support readline-style KBDs

...and prevent REPL from crashing on parse/compilation errors. Better error
messaging would be quite nice as well.

Change-Id: I47d06fd74ef65bfa3f14f0b57a5516a908321da8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5348
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
This commit is contained in:
William Carroll 2022-03-01 14:56:31 -08:00 committed by clbot
parent 81138b25eb
commit 465ddb07bb

View file

@ -1,11 +1,12 @@
from argparse import ArgumentParser from argparse import ArgumentParser
import csv import csv
from parser import Parser
import sqlite3 import sqlite3
import string import string
from scanner import Scanner from scanner import Scanner
from parser import Parser
import re import re
import readline
################################################################################ ################################################################################
# Predicates # Predicates
@ -243,8 +244,12 @@ def main(csv_path=None, debug=False):
print("AST:\t{}".format(parse(x))) print("AST:\t{}".format(parse(x)))
print("query:\t\"{}\"".format(compile(x, table, columns))) print("query:\t\"{}\"".format(compile(x, table, columns)))
for row in cur.execute(compile(x, table, columns)): try:
print("\t".join(str(cell) for cell in row)) compile(x, table, columns)
for row in cur.execute(compile(x, table, columns)):
print("\t".join(str(cell) for cell in row))
except:
print("Compilation error.")
# TODO(wpcarro): Trap exits and ensure cleanup always runs. # TODO(wpcarro): Trap exits and ensure cleanup always runs.
con.close() con.close()