浏览代码

Fix IndexError (issue #754)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.1
Chanic Panic 3 年前
父节点
当前提交
820e185dca
共有 1 个文件被更改,包括 12 次插入7 次删除
  1. +12
    -7
      lark/parsers/earley_forest.py

+ 12
- 7
lark/parsers/earley_forest.py 查看文件

@@ -459,15 +459,20 @@ class PackedData():
that comes from the left child and the right child.
"""

class _NoData():
pass

NO_DATA = _NoData()

def __init__(self, node, data):
self.left = None
self.right = None
self.left = self.NO_DATA
self.right = self.NO_DATA
if data:
if node.left:
if node.left is not None:
self.left = data[0]
if len(data) > 1 and node.right:
if len(data) > 1:
self.right = data[1]
elif node.right:
else:
self.right = data[0]

class ForestToParseTree(ForestTransformer):
@@ -558,12 +563,12 @@ class ForestToParseTree(ForestTransformer):
children = []
assert len(data) <= 2
data = PackedData(node, data)
if data.left is not None:
if data.left is not PackedData.NO_DATA:
if node.left.is_intermediate and isinstance(data.left, list):
children += data.left
else:
children.append(data.left)
if data.right is not None:
if data.right is not PackedData.NO_DATA:
children.append(data.right)
if node.parent.is_intermediate:
return children


正在加载...
取消
保存