about summary refs log tree commit diff
path: root/users/wpcarro/scratch
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-03-01T22·56-0800
committerclbot <clbot@tvl.fyi>2022-03-01T22·59+0000
commit465ddb07bb7cca873fdb0318100c8e07a0742882 (patch)
tree49aa4357a775f05ab3a056fdabaadfd9239a38a0 /users/wpcarro/scratch
parent81138b25eb92440244ee4e1af5779d7e546b7d56 (diff)
feat(wpcarro/simple-select): Support readline-style KBDs r/3890
...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
Diffstat (limited to 'users/wpcarro/scratch')
-rw-r--r--users/wpcarro/scratch/simple-select/main.py11
1 files changed, 8 insertions, 3 deletions
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()