Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] too-restrictive McDisplay instrument line parsing #1834

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions tools/Python/mccodelib/instrparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, data=None, debug=False):
'start' : 'STARTKWLC',
'end' : 'ENDKWLC',
'component' : 'COMPKWLC',

'magnify' : 'DRAWCALL',
'line' : 'DRAWCALL',
'dashed_line' : 'DRAWCALL',
Expand All @@ -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',
Expand All @@ -68,8 +68,7 @@ def __init__(self, data=None, debug=False):
'SQUOTE',
'COMMA',
'NL',

'ABSPATH',
'INSTRPATH',
'DEC',
'ID',
'INSTRNAME',
Expand All @@ -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):
Expand All @@ -100,9 +99,9 @@ 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]*'
r'\w[\w\-0-9\.]*'
return t

def t_JSON(self, t):
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions tools/Python/mccodelib/pipetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down