malloy icon indicating copy to clipboard operation
malloy copied to clipboard

`malloynb` parser does not correctly parse empty markdown section

Open christopherswenson opened this issue 1 year ago • 1 comments

What happens?

If a Malloy notebook has an empty markdown section, it will not be parsed correctly.

To Reproduce

Make a .malloynb file with the following contents:

>>>markdown
>>>malloy
run: duckdb.table('../data/flights.parquet') -> { project: * }

Then open the file with the VSCode notebook viewer. It loads the file as one markdown block with contents:

>>>malloy
run: duckdb.table('../data/flights.parquet') -> { project: * }

OS:

macOS

Malloy Client:

VSCode

Malloy Client Version:

v0.3.1691613201

Database Connection:

DuckDB

christopherswenson avatar Aug 17 '23 14:08 christopherswenson

Here is a simple test that demonstrates the current bug (it will succeed with a fix):

diff --git a/packages/malloy-malloy-sql/src/grammar/test/parse.spec.ts b/packages/malloy-malloy-sql/src/grammar/test/parse.spec.ts
index 0cbba712..11137b33 100644
--- a/packages/malloy-malloy-sql/src/grammar/test/parse.spec.ts
+++ b/packages/malloy-malloy-sql/src/grammar/test/parse.spec.ts
@@ -220,6 +220,14 @@ SELECT 1`);
       expect(parse.statements[0].range.end.character).toBe(8);
     });

+    test('Should provide correct output for an empty markdown block', () => {
+      const parse = MalloySQLParser.parse(`\
+>>>markdown
+>>>sql connection:bigquery
+SELECT 1`);
+      expect(parse.statements).toHaveLength(2);
+    });
+

abhillman avatar Aug 29 '23 15:08 abhillman