malloydata / malloy

Malloy is an experimental language for describing data relationships and transformations.
http://www.malloydata.dev
MIT License
1.93k stars 75 forks source link

`malloynb` parser does not correctly parse empty markdown section #1298

Open christopherswenson opened 11 months ago

christopherswenson commented 11 months ago

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

abhillman commented 11 months ago

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);
+    });
+