Repository: Aunsiels/pyformlang

Issue:
Terminal(X) == Variable(X)
The design of Variables and Terminals as CFGObjects enables comparing them - resulting in "True" if they have the same value. This is highly undesirable (I think?). Terminals and Variables should never be equal...

https://github.com/Aunsiels/pyformlang/blob/04d769ab7da44a7ae80eec49661c0b03fdcd0bac/pyformlang/cfg/variable.py#L22-L24

This breaks i.e. the following (after resolving #32 )
```python
first_lang = rf"""S -> "TER:S" """
second_lang = rf"""S -> a"""
concat = CFG.from_text(first_lang).concatenate(CFG.from_text(second_lang))
assert "Sa" in concat
```

Proposed fix: `CFGObject` -> `Variable`

Discussion:

Fix (patch):
diff --git a/pyformlang/cfg/variable.py b/pyformlang/cfg/variable.py
index 808ebbd..89cd250 100644
--- a/pyformlang/cfg/variable.py
+++ b/pyformlang/cfg/variable.py
@@ -19,7 +19,7 @@ class Variable(CFGObject):  # pylint: disable=too-few-public-methods
         self.index_cfg_converter = None
 
     def __eq__(self, other):
-        if isinstance(other, CFGObject):
+        if isinstance(other, Variable):
             return self._value == other.value
         return self._value == other
 


Test changes:
diff --git a/pyformlang/cfg/tests/test_cfg.py b/pyformlang/cfg/tests/test_cfg.py
index cb6afde..e4145a5 100644
--- a/pyformlang/cfg/tests/test_cfg.py
+++ b/pyformlang/cfg/tests/test_cfg.py
@@ -280,6 +280,12 @@ class TestCFG:
         assert not new_cfg.is_empty()
         assert new_cfg.contains([ter_a, ter_a, ter_b, ter_b, ter_a, ter_b])
 
+    def test_concatenation_variable_names(self):
+        first_lang = CFG({Variable("S")}, {Terminal("S")}, Variable("S"), {Production(Variable("S"), [Terminal("S")])})
+        second_lang = CFG({Variable("S")}, {Terminal("a")}, Variable("S"), {Production(Variable("S"), [Terminal("a")])})
+        concat = first_lang.concatenate(second_lang)
+        assert "Sa" in concat
+
     def test_closure(self):
         """ Tests the closure of a cfg """
         var_s = Variable("S")