Skip to content

Commit

Permalink
line parser more verbose debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bosd committed Mar 6, 2023
1 parent a5bdd50 commit 7193958
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/invoice2data/extract/parsers/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def parse_block(template, field, settings, content):
# Validate settings
assert "line" in settings, "Line regex missing"

logger.debug(
"START line block content ========================\n%s", content
)
logger.debug("END line block content ==========================")
lines = []
current_row = {}

Expand Down Expand Up @@ -131,12 +135,13 @@ def parse_by_rule(template, field, rule, content):
while True:
start = re.search(settings["start"], content)
if not start:
logger.debug("Failed to find the lines block start")
break
content = content[start.end():]

end = re.search(settings["end"], content)
if not end:
logger.warning("Failed to find lines block end")
logger.debug("Failed to find lines block end")
break

blocks_count += 1
Expand All @@ -162,7 +167,8 @@ def parse(template, field, settings, content):
rules = [{k: v for k, v in settings.items() if k in keys}]

lines = []
for rule in rules:
for i, rule in enumerate(rules):
logger.debug("Testing Rules set #%s", i)
new_lines = parse_by_rule(template, field, rule, content)
if new_lines is not None:
lines += new_lines
Expand Down

0 comments on commit 7193958

Please sign in to comment.