Repository: lark-parser/lark

Issue:
Incorrect behaviour for maybe_placeholders
**Describe the bug**

When maybe constructs are nested, maybe_placeholders gets confused.

**To Reproduce**
```
from lark import Lark

parser = Lark("""
start: [A [B]]

A: "a"
B: "b"
""", maybe_placeholders=True)

print(parser.parse(""))
print(parser.parse("a"))
print(parser.parse("ab"))
```

produces

```
Tree(start, [None])
Tree(start, [Token(A, 'a'), None])
Tree(start, [Token(A, 'a'), Token(B, 'b')])
```
instead of the expected

```
Tree(start, [None, None])
Tree(start, [Token(A, 'a'), None])
Tree(start, [Token(A, 'a'), Token(B, 'b')])
```

I don't know how the generation works, but I will try to look into it.

Discussion:

Patch:
diff --git a/lark/load_grammar.py b/lark/load_grammar.py
index 309826b..d425c72 100644
--- a/lark/load_grammar.py
+++ b/lark/load_grammar.py
@@ -344,12 +344,11 @@ class EBNF_to_BNF(Transformer_InPlace):
                 return not sym.name.startswith('_')
             if isinstance(sym, Terminal):
                 return keep_all_tokens or not sym.filter_out
-            assert False
+            if sym is _EMPTY:
+                return False
+            assert False, sym
 
-        if any(rule.scan_values(will_not_get_removed)):
-            empty = _EMPTY
-        else:
-            empty = ST('expansion', [])
+        empty = ST('expansion', [_EMPTY] * len(list(rule.scan_values(will_not_get_removed))))
 
         return ST('expansions', [rule, empty])
 


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 9eb7b26..35f1c14 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -2293,6 +2293,15 @@ def _make_parser_test(LEXER, PARSER):
             self.assertEqual(p.parse("abba").children, ['a', None, 'b', 'b', 'a', None])
             self.assertEqual(p.parse("cbbbb").children, [None, 'c', 'b', 'b', 'b', 'b', None, None])
 
+            p = _Lark("""!start: ["a" "b" "c"] """, maybe_placeholders=True)
+            self.assertEqual(p.parse("").children, [None, None, None])
+            self.assertEqual(p.parse("abc").children, ['a', 'b', 'c'])
+
+            p = _Lark("""!start: ["a" ["b" "c"]] """, maybe_placeholders=True)
+            self.assertEqual(p.parse("").children, [None, None, None])
+            self.assertEqual(p.parse("a").children, ['a', None, None])
+            self.assertEqual(p.parse("abc").children, ['a', 'b', 'c'])
+
 
         def test_escaped_string(self):
             "Tests common.ESCAPED_STRING"