diff --git a/bnf/apyds_bnf/__init__.py b/bnf/apyds_bnf/__init__.py index e801c15..8f832e8 100644 --- a/bnf/apyds_bnf/__init__.py +++ b/bnf/apyds_bnf/__init__.py @@ -57,7 +57,7 @@ def visitRule_pool(self, ctx): def visitRule(self, ctx): result = [self.visit(t) for t in ctx.term()] conclusion = result.pop() - return f'{", ".join(result)} -> {conclusion}' + return f"{', '.join(result)} -> {conclusion}" def visitSymbol(self, ctx): return ctx.SYMBOL().getText() diff --git a/bnf/tests/test_parse_unparse.mjs b/bnf/tests/test_parse_unparse.mjs index a44a27e..b7852b6 100644 --- a/bnf/tests/test_parse_unparse.mjs +++ b/bnf/tests/test_parse_unparse.mjs @@ -4,7 +4,7 @@ test("parse_simple_rule", () => { // Test parsing a simple rule with premises and conclusion const dsp_input = "a, b -> c"; const ds_output = parse(dsp_input); - const expected = "a\nb\n----\nc"; + const expected = "a\nb\n----\nc\n"; expect(ds_output).toBe(expected); }); @@ -20,7 +20,7 @@ test("parse_function", () => { // Test parsing a function call const dsp_input = "f(a, b) -> c"; const ds_output = parse(dsp_input); - const expected = "(function f a b)\n----------------\nc"; + const expected = "(function f a b)\n----------------\nc\n"; expect(ds_output).toBe(expected); }); @@ -28,7 +28,7 @@ test("parse_subscript", () => { // Test parsing subscript notation const dsp_input = "a[i, j] -> b"; const ds_output = parse(dsp_input); - const expected = "(subscript a i j)\n-----------------\nb"; + const expected = "(subscript a i j)\n-----------------\nb\n"; expect(ds_output).toBe(expected); }); @@ -36,7 +36,7 @@ test("parse_binary_operator", () => { // Test parsing binary operators const dsp_input = "(a + b) -> c"; const ds_output = parse(dsp_input); - const expected = "(binary + a b)\n--------------\nc"; + const expected = "(binary + a b)\n--------------\nc\n"; expect(ds_output).toBe(expected); }); @@ -44,7 +44,7 @@ test("parse_unary_operator", () => { // Test parsing unary operators const dsp_input = "~ a -> b"; const ds_output = parse(dsp_input); - const expected = "(unary ~ a)\n-----------\nb"; + const expected = "(unary ~ a)\n-----------\nb\n"; expect(ds_output).toBe(expected); }); @@ -52,7 +52,7 @@ test("parse_multiple_rules", () => { // Test parsing multiple rules const dsp_input = "a -> b\nc -> d"; const ds_output = parse(dsp_input); - const expected = "a\n----\nb\n\nc\n----\nd"; + const expected = "a\n----\nb\n\n\nc\n----\nd\n"; expect(ds_output).toBe(expected); }); @@ -60,13 +60,13 @@ test("parse_complex_expression", () => { // Test parsing complex nested expressions const dsp_input = "(a + b) * c, d[i] -> f(g, h)"; const ds_output = parse(dsp_input); - const expected = "(binary * (binary + a b) c)\n(subscript d i)\n---------------------------\n(function f g h)"; + const expected = "(binary * (binary + a b) c)\n(subscript d i)\n---------------------------\n(function f g h)\n"; expect(ds_output).toBe(expected); }); test("unparse_simple_rule", () => { // Test unparsing a simple rule - const ds_input = "a\nb\n----\nc"; + const ds_input = "a\nb\n----\nc\n"; const dsp_output = unparse(ds_input); const expected = "a, b -> c"; expect(dsp_output).toBe(expected); @@ -82,7 +82,7 @@ test("unparse_no_premises", () => { test("unparse_function", () => { // Test unparsing a function - const ds_input = "(function f a b)\n----\nc"; + const ds_input = "(function f a b)\n----\nc\n"; const dsp_output = unparse(ds_input); const expected = "f(a, b) -> c"; expect(dsp_output).toBe(expected); @@ -90,7 +90,7 @@ test("unparse_function", () => { test("unparse_subscript", () => { // Test unparsing subscript notation - const ds_input = "(subscript a i j)\n----\nb"; + const ds_input = "(subscript a i j)\n----\nb\n"; const dsp_output = unparse(ds_input); const expected = "a[i, j] -> b"; expect(dsp_output).toBe(expected); @@ -98,7 +98,7 @@ test("unparse_subscript", () => { test("unparse_binary_operator", () => { // Test unparsing binary operators - const ds_input = "(binary + a b)\n----\nc"; + const ds_input = "(binary + a b)\n----\nc\n"; const dsp_output = unparse(ds_input); const expected = "(a + b) -> c"; expect(dsp_output).toBe(expected); @@ -106,7 +106,7 @@ test("unparse_binary_operator", () => { test("unparse_unary_operator", () => { // Test unparsing unary operators - const ds_input = "(unary ~ a)\n----\nb"; + const ds_input = "(unary ~ a)\n----\nb\n"; const dsp_output = unparse(ds_input); const expected = "(~ a) -> b"; expect(dsp_output).toBe(expected); @@ -114,7 +114,7 @@ test("unparse_unary_operator", () => { test("unparse_multiple_rules", () => { // Test unparsing multiple rules - const ds_input = "a\n----\nb\n\nc\n----\nd"; + const ds_input = "a\n----\nb\n\n\nc\n----\nd\n"; const dsp_output = unparse(ds_input); const expected = "a -> b\nc -> d"; expect(dsp_output).toBe(expected); @@ -122,7 +122,7 @@ test("unparse_multiple_rules", () => { test("unparse_complex_expression", () => { // Test unparsing complex nested expressions - const ds_input = "(binary * (binary + a b) c)\n(subscript d i)\n----\n(function f g h)"; + const ds_input = "(binary * (binary + a b) c)\n(subscript d i)\n----\n(function f g h)\n"; const dsp_output = unparse(ds_input); const expected = "((a + b) * c), d[i] -> f(g, h)"; expect(dsp_output).toBe(expected); @@ -138,7 +138,7 @@ test("roundtrip_parse_unparse", () => { test("roundtrip_unparse_parse", () => { // Test that unparse followed by parse produces consistent results - const ds_original = "a\nb\n----\nc"; + const ds_original = "a\nb\n----\nc\n"; const dsp_intermediate = unparse(ds_original); const ds_result = parse(dsp_intermediate); expect(ds_result).toBe(ds_original); diff --git a/bnf/tests/test_parse_unparse.py b/bnf/tests/test_parse_unparse.py index eef8d49..b17a1ee 100644 --- a/bnf/tests/test_parse_unparse.py +++ b/bnf/tests/test_parse_unparse.py @@ -6,7 +6,7 @@ def test_parse_simple_rule() -> None: """Test parsing a simple rule with premises and conclusion""" dsp_input = "a, b -> c" ds_output = parse(dsp_input) - expected = "a\nb\n----\nc" + expected = "a\nb\n----\nc\n" assert ds_output == expected @@ -22,7 +22,7 @@ def test_parse_function() -> None: """Test parsing a function call""" dsp_input = "f(a, b) -> c" ds_output = parse(dsp_input) - expected = "(function f a b)\n----------------\nc" + expected = "(function f a b)\n----------------\nc\n" assert ds_output == expected @@ -30,7 +30,7 @@ def test_parse_subscript() -> None: """Test parsing subscript notation""" dsp_input = "a[i, j] -> b" ds_output = parse(dsp_input) - expected = "(subscript a i j)\n-----------------\nb" + expected = "(subscript a i j)\n-----------------\nb\n" assert ds_output == expected @@ -38,7 +38,7 @@ def test_parse_binary_operator() -> None: """Test parsing binary operators""" dsp_input = "(a + b) -> c" ds_output = parse(dsp_input) - expected = "(binary + a b)\n--------------\nc" + expected = "(binary + a b)\n--------------\nc\n" assert ds_output == expected @@ -46,7 +46,7 @@ def test_parse_unary_operator() -> None: """Test parsing unary operators""" dsp_input = "~ a -> b" ds_output = parse(dsp_input) - expected = "(unary ~ a)\n-----------\nb" + expected = "(unary ~ a)\n-----------\nb\n" assert ds_output == expected @@ -54,7 +54,7 @@ def test_parse_multiple_rules() -> None: """Test parsing multiple rules""" dsp_input = "a -> b\nc -> d" ds_output = parse(dsp_input) - expected = "a\n----\nb\n\nc\n----\nd" + expected = "a\n----\nb\n\n\nc\n----\nd\n" assert ds_output == expected @@ -62,13 +62,13 @@ def test_parse_complex_expression() -> None: """Test parsing complex nested expressions""" dsp_input = "(a + b) * c, d[i] -> f(g, h)" ds_output = parse(dsp_input) - expected = "(binary * (binary + a b) c)\n(subscript d i)\n---------------------------\n(function f g h)" + expected = "(binary * (binary + a b) c)\n(subscript d i)\n---------------------------\n(function f g h)\n" assert ds_output == expected def test_unparse_simple_rule() -> None: """Test unparsing a simple rule""" - ds_input = "a\nb\n----\nc" + ds_input = "a\nb\n----\nc\n" dsp_output = unparse(ds_input) expected = "a, b -> c" assert dsp_output == expected @@ -84,7 +84,7 @@ def test_unparse_no_premises() -> None: def test_unparse_function() -> None: """Test unparsing a function""" - ds_input = "(function f a b)\n----\nc" + ds_input = "(function f a b)\n----\nc\n" dsp_output = unparse(ds_input) expected = "f(a, b) -> c" assert dsp_output == expected @@ -92,7 +92,7 @@ def test_unparse_function() -> None: def test_unparse_subscript() -> None: """Test unparsing subscript notation""" - ds_input = "(subscript a i j)\n----\nb" + ds_input = "(subscript a i j)\n----\nb\n" dsp_output = unparse(ds_input) expected = "a[i, j] -> b" assert dsp_output == expected @@ -100,7 +100,7 @@ def test_unparse_subscript() -> None: def test_unparse_binary_operator() -> None: """Test unparsing binary operators""" - ds_input = "(binary + a b)\n----\nc" + ds_input = "(binary + a b)\n----\nc\n" dsp_output = unparse(ds_input) expected = "(a + b) -> c" assert dsp_output == expected @@ -108,7 +108,7 @@ def test_unparse_binary_operator() -> None: def test_unparse_unary_operator() -> None: """Test unparsing unary operators""" - ds_input = "(unary ~ a)\n----\nb" + ds_input = "(unary ~ a)\n----\nb\n" dsp_output = unparse(ds_input) expected = "(~ a) -> b" assert dsp_output == expected @@ -116,7 +116,7 @@ def test_unparse_unary_operator() -> None: def test_unparse_multiple_rules() -> None: """Test unparsing multiple rules""" - ds_input = "a\n----\nb\n\nc\n----\nd" + ds_input = "a\n----\nb\n\n\nc\n----\nd\n" dsp_output = unparse(ds_input) expected = "a -> b\nc -> d" assert dsp_output == expected @@ -124,7 +124,7 @@ def test_unparse_multiple_rules() -> None: def test_unparse_complex_expression() -> None: """Test unparsing complex nested expressions""" - ds_input = "(binary * (binary + a b) c)\n(subscript d i)\n----\n(function f g h)" + ds_input = "(binary * (binary + a b) c)\n(subscript d i)\n----\n(function f g h)\n" dsp_output = unparse(ds_input) expected = "((a + b) * c), d[i] -> f(g, h)" assert dsp_output == expected @@ -140,7 +140,7 @@ def test_roundtrip_parse_unparse() -> None: def test_roundtrip_unparse_parse() -> None: """Test that unparse followed by parse produces consistent results""" - ds_original = "a\nb\n----\nc" + ds_original = "a\nb\n----\nc\n" dsp_intermediate = unparse(ds_original) ds_result = parse(dsp_intermediate) assert ds_result == ds_original