Skip to content

Commit 73e078e

Browse files
authored
Merge pull request #489 from CPJKU/safe-lark-parsing
safe lark parsing
2 parents 054973c + fe3e3c1 commit 73e078e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

partitura/directions.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ def unabbreviate(s):
326326
def regularize_form(children):
327327
return " ".join(unabbreviate(ch.lower()) for ch in children)
328328

329+
def check_tree(tree, col_name = "column"):
330+
meta = getattr(tree, "meta", None)
331+
col = getattr(meta, col_name, None)
332+
return col
329333

330334
def create_directions(tree, string, start=None, end=None):
331335
"""
@@ -334,9 +338,13 @@ def create_directions(tree, string, start=None, end=None):
334338
335339
"""
336340
if start is None:
337-
start = tree.column - 1
341+
col = check_tree(tree, "column")
342+
if col is not None:
343+
start = col - 1
338344
if end is None:
339-
end = tree.end_column - 1
345+
col = check_tree(tree, "end_column")
346+
if col is not None:
347+
end = col - 1
340348

341349
if tree.data == "conj":
342350
return create_directions(tree.children[0], string) + create_directions(

0 commit comments

Comments
 (0)