Repository: lark-parser/lark

Issue:
Missing ambiguities when using inline rules
**Describe the bug**

With some grammars, Earley parser does not return all ambiguities with `ambiguity='explicit'`. 
However, when removing the inlining underscore, all ambiguities are returned. 

Potentially related to #536. 

**To Reproduce**

```
start: _field+

_field: f1 | f2 | f3

f1: INT
f2: INT "M"?
f3: INT "M"

%ignore WS
%import common.WS
%import common.INT
```

When parsing string `1M 2` with `ambiguity='explicit'`, the result misses ambiguities `f2 f2` and `f3 f1`. 

```
>> t = parser.parse('1M 2')
>> print(t.pretty())

_ambig
  start
    f2	1
    f1	2
  start
    f3	1
    f2	2
```

However, removing `_` from `field` fixes it, at the expense of the additional tree level which I wanted to avoid. 

```
start: field+

field: f1 | f2 | f3

f1: INT
f2: INT "M"?
f3: INT "M"

%ignore WS
%import common.WS
%import common.INT
```

```
>> t = parser.parse('1M 2')
>> print(t.pretty())

start
  _ambig
    field
      f2	1
    field
      f3	1
  _ambig
    field
      f1	2
    field
      f2	2
```

It's great that the workaround works, at least in this case. But with a complex grammar including inlined rules at several levels, it's difficult to spot the issue before realising that some results are missing in production. 

Discussion:

Patch:
diff --git a/lark/parse_tree_builder.py b/lark/parse_tree_builder.py
index a6003a9..bb907a2 100644
--- a/lark/parse_tree_builder.py
+++ b/lark/parse_tree_builder.py
@@ -8,7 +8,7 @@ from .visitors import _vargs_meta, _vargs_meta_inline
 
 ###{standalone
 from functools import partial, wraps
-from itertools import repeat, product
+from itertools import product
 
 
 class ExpandSingleChild:
@@ -186,7 +186,7 @@ def maybe_create_child_filter(expansion, keep_all_tokens, ambiguous, _empty_indi
 class AmbiguousExpander:
     """Deal with the case where we're expanding children ('_rule') into a parent but the children
        are ambiguous. i.e. (parent->_ambig->_expand_this_rule). In this case, make the parent itself
-       ambiguous with as many copies as their are ambiguous children, and then copy the ambiguous children
+       ambiguous with as many copies as there are ambiguous children, and then copy the ambiguous children
        into the right parents in the right places, essentially shifting the ambiguity up the tree."""
     def __init__(self, to_expand, tree_class, node_builder):
         self.node_builder = node_builder
@@ -212,8 +212,8 @@ class AmbiguousExpander:
         if not ambiguous:
             return self.node_builder(children)
 
-        expand = [iter(child.children) if i in ambiguous else repeat(child) for i, child in enumerate(children)]
-        return self.tree_class('_ambig', [self.node_builder(list(f[0])) for f in product(zip(*expand))])
+        expand = [child.children if i in ambiguous else (child,) for i, child in enumerate(children)]
+        return self.tree_class('_ambig', [self.node_builder(list(f)) for f in product(*expand)])
 
 
 def maybe_create_ambiguous_expander(tree_class, expansion, keep_all_tokens):


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index b48ea03..0eeed77 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -526,6 +526,27 @@ def _make_full_earley_test(LEXER):
                 ])
             self.assertEqual(res, expected)
 
+        def test_ambiguous_inlined_rule(self):
+            grammar = """
+            start: _field+
+            _field: f1 | f2 | f3
+            f1: INT
+            f2: INT "M"?
+            f3: INT "M"
+            %import common.INT
+            """
+
+            l = Lark(grammar, parser='earley', ambiguity='explicit', lexer=LEXER)
+            ambig_tree = l.parse("1M2")
+            expected = {
+                Tree('start', [Tree('f2', ['1']), Tree('f1', ['2'])]),
+                Tree('start', [Tree('f2', ['1']), Tree('f2', ['2'])]),
+                Tree('start', [Tree('f3', ['1']), Tree('f1', ['2'])]),
+                Tree('start', [Tree('f3', ['1']), Tree('f2', ['2'])]),
+            }
+            self.assertEqual(ambig_tree.data, '_ambig')
+            self.assertEqual(set(ambig_tree.children), expected)
+
         def test_ambiguous_intermediate_node(self):
             grammar = """
             start: ab bc d?