git » jacl.git » commit ce9ffda

Bring back JS syntax stuff

author Alan Dipert
2020-02-24 03:18:47 UTC
committer Alan Dipert
2020-02-24 03:18:47 UTC
parent 7af4197fb9ed96b066b80c635a9e40dc61f402e3

Bring back JS syntax stuff

jacl.js +29 -0

diff --git a/jacl.js b/jacl.js
index b6add60..2fd1762 100644
--- a/jacl.js
+++ b/jacl.js
@@ -641,6 +641,25 @@ const readString = async stream => {
   }
 };
 
+// TODO make this a real JS string reader
+const readJsString = async stream => {
+  const [clStr] = await readString(stream);
+  return new Values(clStr.toString());
+};
+
+const readGlobalReference = async stream => {
+  const sym = await readMultiEscaped(stream, new Token().sawPipe(), false),
+        parts = sym.name.split('.'),
+        [topic, ...fields] = parts;
+  return new Values(
+    Cons.listOf(
+      JACLPKG.intern('.'),
+      Cons.listOf(JACLPKG.intern('%JS'), topic),
+      ...fields.map(x => new LispSymbol(x, null))
+    )
+  );
+};
+
 READTABLE.value = new ReadTable()
   .setMacro(';', true, async stream => {
     for await(const ch of stream) {
@@ -2038,6 +2057,16 @@ JACLPKG.intern('.')
   };
 JACLPKG.exportSymbol('.');
 
+JACLPKG.intern('ENABLE-JS-SYNTAX').fvalue = () => {
+  READTABLE
+    .val()
+    .makeDispatchMacroChar('@', true)
+    .setDispatchMacroChar('@', '"', readJsString)
+    .setDispatchMacroChar('@', '|', readGlobalReference);
+  return null;
+};
+JACLPKG.exportSymbol('ENABLE-JS-SYNTAX');
+
 JACLPKG.intern('TRUTH').fvalue = x => (x != null && x !== false) || null;
 JACLPKG.exportSymbol('TRUTH');