Browse Source

Fixes to propagate_positions

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.8.0
Erez Sh 5 years ago
parent
commit
dcc9d46eef
3 changed files with 11 additions and 3 deletions
  1. +2
    -2
      lark/parse_tree_builder.py
  2. +1
    -1
      tests/__main__.py
  3. +8
    -0
      tests/test_parser.py

+ 2
- 2
lark/parse_tree_builder.py View File

@@ -29,7 +29,7 @@ class PropagatePositions:

if isinstance(res, Tree):
for c in children:
if isinstance(c, Tree) and c.children and not c.meta.empty:
if isinstance(c, Tree) and not c.meta.empty:
res.meta.line = c.meta.line
res.meta.column = c.meta.column
res.meta.start_pos = c.meta.start_pos
@@ -43,7 +43,7 @@ class PropagatePositions:
break

for c in reversed(children):
if isinstance(c, Tree) and c.children and not c.meta.empty:
if isinstance(c, Tree) and not c.meta.empty:
res.meta.end_line = c.meta.end_line
res.meta.end_column = c.meta.end_column
res.meta.end_pos = c.meta.end_pos


+ 1
- 1
tests/__main__.py View File

@@ -10,7 +10,7 @@ from .test_reconstructor import TestReconstructor
try:
from .test_nearley.test_nearley import TestNearley
except ImportError:
logging.warn("Warning: Skipping tests for Nearley (js2py required)")
logging.warning("Warning: Skipping tests for Nearley grammar imports (js2py required)")

# from .test_selectors import TestSelectors
# from .test_grammars import TestPythonG, TestConfigG


+ 8
- 0
tests/test_parser.py View File

@@ -63,6 +63,14 @@ class TestParsers(unittest.TestCase):
r = g.parse('a')
self.assertEqual( r.children[0].meta.line, 1 )

g = Lark("""start: x
x: a
a: "a"
""", propagate_positions=True)

r = g.parse('a')
self.assertEqual( r.children[0].meta.line, 1 )

def test_expand1(self):

g = Lark("""start: a


Loading…
Cancel
Save