Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bnf/apyds_bnf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 15 additions & 15 deletions bnf/tests/test_parse_unparse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -20,53 +20,53 @@ 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);
});

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

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

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

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

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);
Expand All @@ -82,47 +82,47 @@ 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);
});

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

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

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

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

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);
Expand All @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions bnf/tests/test_parse_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -22,53 +22,53 @@ 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


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


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


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


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


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
Expand All @@ -84,47 +84,47 @@ 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


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


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


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


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


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
Expand All @@ -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
Expand Down