From 465ddb07bb7cca873fdb0318100c8e07a0742882 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Tue, 1 Mar 2022 14:56:31 -0800 Subject: 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 Autosubmit: wpcarro Tested-by: BuildkiteCI --- users/wpcarro/scratch/simple-select/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'users') diff --git a/users/wpcarro/scratch/simple-select/main.py b/users/wpcarro/scratch/simple-select/main.py index dd7e8215c9ca..3ae6c5d60e08 100644 --- a/users/wpcarro/scratch/simple-select/main.py +++ b/users/wpcarro/scratch/simple-select/main.py @@ -1,11 +1,12 @@ from argparse import ArgumentParser import csv +from parser import Parser import sqlite3 import string from scanner import Scanner -from parser import Parser import re +import readline ################################################################################ # Predicates @@ -243,8 +244,12 @@ def main(csv_path=None, debug=False): print("AST:\t{}".format(parse(x))) print("query:\t\"{}\"".format(compile(x, table, columns))) - for row in cur.execute(compile(x, table, columns)): - print("\t".join(str(cell) for cell in row)) + try: + 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. con.close() -- cgit 1.4.1