From 59611751936ecdb0e3b27345bd3e94733fac1b70 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 16 Nov 2023 10:27:06 +0200 Subject: [PATCH] found why regex is not finding ; comment, to fix --- parsers/survex.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/parsers/survex.py b/parsers/survex.py index 070e413..d3db234 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -300,6 +300,9 @@ class LoadingSurvex: rx_commteam = re.compile(r"(?i)\s*(Messteam|Zeichner)\s*[:]?(.*)") rx_quotedtitle = re.compile(r'(?i)^"(.*)"$') + rx_fixline = re.compile(r"(?i)^\s*([\w\d_\.\-]+)\s+(?:reference)?\s*([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)(.*)$") + + # This interprets the survex "*data normal" command which sets out the order of the fields in the data, e.g. # *DATA normal from to length gradient bearing ignore ignore ignore ignore @@ -611,15 +614,19 @@ class LoadingSurvex: def LoadSurvexFix(self, survexblock, line): """*fix is a station geolocation, units depend on a previous *cs setting + NOTE 'line' is not the full line, it is 'arg' and the comments have been stripped ! """ - #fixline = line.strip().replace("\t"," ").split(" ") # unpack tuples idiom in python 3 - fixline = re.match("(?i)\s*([\w\d_\.\-]+)\s+(?:reference)?\s*([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)\s*(;.*)?$", line) + # fixline = re.match("(?i)\s*([\w\d_\.\-]+)\s+(?:reference)?\s*([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)\s*(.*)$", line) + fixline = self.rx_fixline.match(line) if not fixline: message = f'BAD fix regex {line.replace(" ","|")} {survexblock.survexfile.path}:{survexblock}' print(self.insp + message) stash_data_issue(parser="survex", message=message) else: - name, *fixdata = fixline.groups() + fixdata = fixline.groups() + #print(fixline.group(1), fixline.group(5)) + print(f"'{line}'") + name = fixdata[0] if name in self.fixes: message = f"! Duplicate *FIX: id '{line}' ({survexblock}) {survexblock.survexfile.path}" print(self.insp + message) @@ -630,11 +637,14 @@ class LoadingSurvex: try: #_, _, alt, *rest = (fixdata + [None]*4)[:4] - _, _, alt, comment = fixdata - fixid = str(survexblock)+name + name, _, _, alt, comment = fixdata + fixid = str(survexblock.id)+ ":"+ name self.fixes[fixid] = (survexblock, alt, comment) - except: - print(f'BAD fix {name}, {fixdata=}\n{line.replace(" ","|")}\n{survexblock.survexfile.path}:{survexblock}', file=sys.stderr) + message = f"{name}, {fixdata=}, last:{fixline.groups()[-1]}" + print(self.insp + message) + except Exception as e: + print(f'BAD fix comment {e}', file=sys.stderr) + print(f'BAD fix comment {name}, {fixdata=}\n{line.replace(" ","|")}\n{survexblock.survexfile.path}:{survexblock}', file=sys.stderr) def LoadSurvexEntrance(self, survexblock, line): @@ -2402,13 +2412,23 @@ def FindAndLoadSurvex(): for f in svx_load.fixes: # why are we seeing no *fixes from fixedpts/gps18.svx etc. ? They are parsed ! survexblock, altitude, comment = svx_load.fixes[f] + s = survexblock + spath = "" + sprevious = None + while s.parent != sprevious: + spath += str(s.parent) + ":" + spath + sprevious = s + if not s.parent: + break + s = s.parent + if comment: - print(f"{a} {b} {comment}") + print(f"COMMENT {survexblock} {altitude} {comment}") if re.match("(?i)[^s]*srtm[\s\S]*", comment.lower()): - print(f"{f} - {comment}") + print(f"{f} - {spath}::{survexblock} - {comment}") else: - if str(f).startswith("162"): - print(f"{f} - {survexblock.survexfile}:{survexblock} - {altitude=}") + if str(f).startswith("1623"): + print(f"{f} - {spath}::{survexblock} - {altitude=}") svx_load = None