From 5fc16e95d41dc5fbd1948e010657657c467f0d2e Mon Sep 17 00:00:00 2001 From: Gregory Tucker Date: Fri, 31 Jan 2025 11:05:47 +0100 Subject: [PATCH 1/3] [Fix] too-restrictive McDisplay instrument line parsing --- tools/Python/mccodelib/instrparser.py | 4 ++-- tools/Python/mccodelib/pipetools.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/Python/mccodelib/instrparser.py b/tools/Python/mccodelib/instrparser.py index 09b56bedc1..fb38d5b2b9 100644 --- a/tools/Python/mccodelib/instrparser.py +++ b/tools/Python/mccodelib/instrparser.py @@ -89,7 +89,7 @@ def t_ANY_NL(self, t): return t def t_ABSPATH(self, t): - r'[/\w\\\:\-]+\.instr' + r'[/\w\\\:\-\.]+(\.instr)?' return t def t_DEC(self, t): @@ -102,7 +102,7 @@ def t_ID(self, t): return t def t_INSTRNAME(self, t): - r'\w[\w\-0-9]*' + r'\w[\w\-0-9\.]*' return t def t_JSON(self, t): diff --git a/tools/Python/mccodelib/pipetools.py b/tools/Python/mccodelib/pipetools.py index 1acbdea002..8a1d4d11a9 100644 --- a/tools/Python/mccodelib/pipetools.py +++ b/tools/Python/mccodelib/pipetools.py @@ -99,9 +99,8 @@ def __init__(self, setcurrent, next, databox, args=None): def add_line(self, line): if self.first and re.match('INSTRUMENT:', line): self.databox.add_instrdef(line) - self.first = False - self.second = True - elif self.second and re.match(r'Instrument \'[\w\-]+\' \([/\w\\\:\-]+.instr\)', line): + self.first, self.second = False, True + elif self.second and re.match(r'Instrument \'[\w\-\.]+\' \([/\w\\\:\-\.]+(\.instr)?\)', line): self.databox.add_instrdef(line) self.second = False elif re.match('COMPONENT:', line): From 022fee6aa44ab281a386af9342226a2f679d8471 Mon Sep 17 00:00:00 2001 From: Gregory Tucker Date: Fri, 31 Jan 2025 12:07:23 +0100 Subject: [PATCH 2/3] [Refactor] McDisplay output parser --- tools/Python/mccodelib/instrparser.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/Python/mccodelib/instrparser.py b/tools/Python/mccodelib/instrparser.py index fb38d5b2b9..9725e79afd 100644 --- a/tools/Python/mccodelib/instrparser.py +++ b/tools/Python/mccodelib/instrparser.py @@ -34,7 +34,7 @@ def __init__(self, data=None, debug=False): 'start' : 'STARTKWLC', 'end' : 'ENDKWLC', 'component' : 'COMPKWLC', - + 'magnify' : 'DRAWCALL', 'line' : 'DRAWCALL', 'dashed_line' : 'DRAWCALL', @@ -56,9 +56,9 @@ def __init__(self, data=None, debug=False): 'MANTID_PIXEL': 'MANTID_PIXEL', 'MANTID_BANANA_DET': 'MANTID_BANANA_DET', 'MANTID_RECTANGULAR_DET': 'MANTID_RECTANGULAR_DET', - + } - + # tokens tokens = [ 'LB', @@ -68,8 +68,7 @@ def __init__(self, data=None, debug=False): 'SQUOTE', 'COMMA', 'NL', - - 'ABSPATH', + 'INSTRPATH', 'DEC', 'ID', 'INSTRNAME', @@ -88,8 +87,8 @@ def t_ANY_NL(self, t): self.lexer.lineno += 1 return t - def t_ABSPATH(self, t): - r'[/\w\\\:\-\.]+(\.instr)?' + def t_INSTRPATH(self, t): + r'[/\w\\\:\-\.]+\.instr?' return t def t_DEC(self, t): @@ -100,7 +99,7 @@ def t_ID(self, t): r'[a-zA-Z_]\w*' t.type = self.reserved.get(t.value, 'ID') return t - + def t_INSTRNAME(self, t): r'\w[\w\-0-9\.]*' return t @@ -132,7 +131,8 @@ def p_document(self, p): instr = None def p_instr_open(self, p): - 'instr_open : INSTRUMENT COLON NL INSTRKW SQUOTE instr_name SQUOTE LB ABSPATH RB NL' + '''instr_open : INSTRUMENT COLON NL INSTRKW SQUOTE instr_name SQUOTE LB INSTRPATH RB NL + | INSTRUMENT COLON NL INSTRKW SQUOTE instr_name SQUOTE LB ID RB NL''' self.instr = Node(type='instrument', children=[p[6], Node(type='abspath', leaf=p[9])]) def p_instr_end(self, p): From e826dfe2e63e59c8e79254b03d3b7d2310e0d14c Mon Sep 17 00:00:00 2001 From: Gregory Tucker Date: Fri, 31 Jan 2025 12:15:20 +0100 Subject: [PATCH 3/3] [Fix] 'r' on end of '.instr' in INSTRPATH token is not optional --- tools/Python/mccodelib/instrparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Python/mccodelib/instrparser.py b/tools/Python/mccodelib/instrparser.py index 9725e79afd..a8df7897da 100644 --- a/tools/Python/mccodelib/instrparser.py +++ b/tools/Python/mccodelib/instrparser.py @@ -88,7 +88,7 @@ def t_ANY_NL(self, t): return t def t_INSTRPATH(self, t): - r'[/\w\\\:\-\.]+\.instr?' + r'[/\w\\\:\-\.]+\.instr' return t def t_DEC(self, t):