From 7a03a3fd43fc3694d8da4218c61db6ec067de941 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 17 Nov 2021 14:49:36 +0100 Subject: [PATCH 1/2] Allows templates without argument --- scripts/datamodel-doc/ALICEO2codeFile.py | 22 +++++++++++++++++-- .../datamodel-doc/ALICEO2dataModelTools.py | 9 ++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/scripts/datamodel-doc/ALICEO2codeFile.py b/scripts/datamodel-doc/ALICEO2codeFile.py index cfbacb7a0189c..e4a731a4c41c2 100644 --- a/scripts/datamodel-doc/ALICEO2codeFile.py +++ b/scripts/datamodel-doc/ALICEO2codeFile.py @@ -99,7 +99,23 @@ def parseContent(self, content): inds = [i for i, x in enumerate(words) if x.txt == 'template'] for ind in inds: line = O2DMT.block(words[ind:]) - tempBlock = O2DMT.lineInBrackets("{","}",line,True) + + # templates can come without {} block! + # find out what comes first '{' or ';' + if ';' in line: + ci = line.index(';') + o1 = ci+1 + if '{' in line: + o1 = line.index('{') + if ci < o1: + tempBlock = line[:ci] + else: + [oi, ci] = O2DMT.findInBrackets("{","}",line) + tempBlock = line[:ci] + else: + [oi, ci] = O2DMT.findInBrackets("{","}",line) + tempBlock = line[:ci] + if len(tempBlock) == 0: continue @@ -108,7 +124,9 @@ def parseContent(self, content): argWords = tempLine.split(',') tempArgs = list() for arg in argWords: - tempArgs.append(arg.split()[-1]) + kvpair = arg.split() + if len(kvpair) == 2: + tempArgs.append(kvpair[-1]) # find struct within tempBlock tempWords = O2DMT.split(tempBlock) diff --git a/scripts/datamodel-doc/ALICEO2dataModelTools.py b/scripts/datamodel-doc/ALICEO2dataModelTools.py index f41076434cf03..458edafb1dbf5 100644 --- a/scripts/datamodel-doc/ALICEO2dataModelTools.py +++ b/scripts/datamodel-doc/ALICEO2dataModelTools.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import sys +import regex as re import numpy as np import nltk @@ -88,7 +89,7 @@ def expandLine(self, line): for ind1 in range(len(self.vars)): for ind2 in range(len(words)): if self.vars[ind1].strip() in words[ind2]: - words[ind2] = vars[ind1].strip() + words[ind2] = re.sub(self.vars[ind1].strip(), vars[ind1].strip(), words[ind2]) expandedLine = block(words) # remove ##, which connects two strings @@ -172,10 +173,10 @@ def countBrackets(obr, cbr, line): # find text in closed brackets # number of closing brackets matches the number of previously opening brackets # obr/cbr: openening/closing brackets -# brackets can include more than on character +# brackets can include more than one character # line: string -# withheader: all textfrom the beginning until closing brackets match -# return modified line and int stat +# withheader: all text from the beginning until closing brackets match +# return begin/end position of brackets def findInBrackets(obr, cbr, line): newline = '' From 0bed987a9973d9ea7efd6fc53da9b7c496a69082 Mon Sep 17 00:00:00 2001 From: Paul Buehler Date: Thu, 18 Nov 2021 18:34:25 +0100 Subject: [PATCH 2/2] Update ALICEO2codeFile.py --- scripts/datamodel-doc/ALICEO2codeFile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/datamodel-doc/ALICEO2codeFile.py b/scripts/datamodel-doc/ALICEO2codeFile.py index e4a731a4c41c2..a5f861280d00b 100644 --- a/scripts/datamodel-doc/ALICEO2codeFile.py +++ b/scripts/datamodel-doc/ALICEO2codeFile.py @@ -151,7 +151,6 @@ def parseContent(self, content): # update restLine eob = nchFullLine - len(line) restLine += fullLine[sob:eob] - [oi, ci] = O2DMT.findInBrackets("{","}",line) sob = eob+ci+1 # update restLine