Dataset Viewer
Auto-converted to Parquet
base_commit
string
created_at
timestamp[ns]
environment_setup_commit
string
hints_text
string
instance_id
string
meta
dict
patch
string
problem_statement
string
repo
string
test_patch
string
version
string
install_config
dict
FAIL_TO_PASS
sequence
PASS_TO_PASS
sequence
__index_level_0__
int64
04d769ab7da44a7ae80eec49661c0b03fdcd0bac
2025-05-08T11:03:53
04d769ab7da44a7ae80eec49661c0b03fdcd0bac
Aunsiels__pyformlang-32
{ "commit_name": "head_commit", "failed_lite_validators": [], "has_test_patch": true, "is_lite": true, "num_modified_files": 1 }
diff --git a/pyformlang/cfg/cfg.py b/pyformlang/cfg/cfg.py index 4a07efd..867e4f0 100644 --- a/pyformlang/cfg/cfg.py +++ b/pyformlang/cfg/cfg.py @@ -1081,16 +1081,18 @@ class CFG: body_component = body_component[5:-1] else: type_component = "" - if body_component[0] in string.ascii_uppercase or \ - type_component == "VAR": - body_var = Variable(body_component) - variables.add(body_var) - body.append(body_var) - elif body_component not in EPSILON_SYMBOLS or type_component \ - == "TER": + if type_component != "VAR" and (not body_component[0].isupper() or type_component == "TER" or body_component in EPSILON_SYMBOLS): + if body_component in EPSILON_SYMBOLS: + continue body_ter = Terminal(body_component) terminals.add(body_ter) body.append(body_ter) + elif type_component != "TER" and (body_component[0].isupper() or type_component == "VAR"): + body_var = Variable(body_component) + variables.add(body_var) + body.append(body_var) + else: + raise ValueError(f"Invalid rule definition: {body_component}") productions.add(Production(head, body)) def is_normal_form(self):
TER:X notation is not respected for uppercase terminals in CFGs **Describe the bug** Consider the difference between the following two CFGs. According to the `from_text` documentation, they should be equivalent. ``` from pyformlang.cfg import CFG, Production, Terminal, Variable cfg = CFG.from_text('S -> "TER:A"') print(cfg.is_empty()) print(cfg.productions) print("vs") # vs cfg = CFG( variables={"S"}, terminals={"A"}, start_symbol="S", productions={Production(Variable("S"), (Terminal("A"),))}, ) print(cfg.is_empty()) print(cfg.productions) ``` **Expected behavior** Generating the second CFG when parsing the first text.
Aunsiels/pyformlang
diff --git a/pyformlang/cfg/tests/test_cfg.py b/pyformlang/cfg/tests/test_cfg.py index cb6afde..6bbb2dd 100644 --- a/pyformlang/cfg/tests/test_cfg.py +++ b/pyformlang/cfg/tests/test_cfg.py @@ -769,6 +769,16 @@ class TestCFG: assert cfg.contains(["a", "b"]) assert ["a", "b"] in cfg + def test_from_text3(self): + text = """ + S -> "TER:A" "TER:B" "VAR:a" + "VAR:a" -> "TER:A" | $ + """ + cfg = CFG.from_text(text) + assert cfg.contains(["A", "B"]) + assert cfg.contains(["A", "B", "A"]) + + def test_from_text_union(self): text = """ "VAR:S" -> TER:a | b
Aunsiels__pyformlang-32
{ "install": "pip install -e .", "log_parser": "parse_log_pytest", "packages": "requirements.txt", "pre_install": [ "apt-get update", "apt-get install -y gcc" ], "python": "3.9", "reqs_path": [ "requirements.txt" ], "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
[ "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_from_text3" ]
[ "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_creation", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_generating_object", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_reachable_object", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_useless_removal", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_nullable_object", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_remove_epsilon", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_unit_pair", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_cnf", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_substitution", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_union", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_concatenation", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_closure", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_pos_closure", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_reverse", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_emptiness", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_membership", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_to_pda", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_conversions", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_profiling_conversions", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_generation_words", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_generation_words2", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_finite", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_intersection", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_intersection_empty", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_intersection_dfa", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_intersection_with_epsilon", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_intersection_dfa2", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_profiling_intersection", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_pda_object_creator", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_string_variable", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_get_leftmost_derivation", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_get_rightmost_derivation", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_derivation_does_not_exist", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_derivation_empty", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_from_text", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_from_text2", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_from_text_union", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_epsilon", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_epsilon2", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_generate_epsilon", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_change_starting_variable", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_is_not_normal_form", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_is_normal_form", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_to_text", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_to_text_cnf", "pyformlang/cfg/tests/test_cfg.py::TestCFG::test_to_text_epsilon" ]
0
README.md exists but content is empty.
Downloads last month
0