# Catch any double (triple...) \ before they annoy us
# Catch any double (triple...) \ before they annoy us
whiler'\\'indsiString:
whiler'\\'indsiString:
warningMessages.append(_warn(f"Double backslash found in string, treating as one backslash: \"{dsiString}\"",RuntimeWarning))
warningMessages.append(_warn(f"Double backslash found in string, treating as one backslash: >{dsiString}<",RuntimeWarning))
dsiString=dsiString.replace(r'\\','\\')
dsiString=dsiString.replace(r'\\','\\')
ifdsiString=="":
ifdsiString=="":
...
@@ -90,7 +90,7 @@ class dsiParser:
...
@@ -90,7 +90,7 @@ class dsiParser:
ifitems[0]=='':#first item of List should be empty, remove it
ifitems[0]=='':#first item of List should be empty, remove it
items.pop(0)
items.pop(0)
else:
else:
warningMessages.append(_warn(f"string should start with \\, string given was \"{dsiString}\"",RuntimeWarning))
warningMessages.append(_warn(f"string should start with \\, string given was >{dsiString}<",RuntimeWarning))
nodes=[]
nodes=[]
(prefix,unit,exponent)=('','','')
(prefix,unit,exponent)=('','','')
...
@@ -116,7 +116,7 @@ class dsiParser:
...
@@ -116,7 +116,7 @@ class dsiParser:
item=''
item=''
elifre.match(r'tothe\{.*\}',item):
elifre.match(r'tothe\{.*\}',item):
exponent=item.split('{')[1].split('}')[0]
exponent=item.split('{')[1].split('}')[0]
warningMessages.append(_warn(f"The exponent \"{exponent}\" is not a number!",RuntimeWarning))
warningMessages.append(_warn(f"The exponent >{exponent}< is not a number!",RuntimeWarning))
try:
try:
item=items.pop(0)
item=items.pop(0)
exceptIndexError:
exceptIndexError:
...
@@ -127,14 +127,20 @@ class dsiParser:
...
@@ -127,14 +127,20 @@ class dsiParser:
item=items.pop(0)
item=items.pop(0)
exceptIndexError:
exceptIndexError:
item=''
item=''
warningMessages.append(_warn(f"The identifier \"{unit}\" does not match any D-SI units!",RuntimeWarning))
closestMatches=_getClosestStr(unit)
iflen (closestMatches)>0:
closestMatchesStr=', \\'.join(closestMatches)
closestMatchesStr='\\'+closestMatchesStr
warningMessages.append(_warn(fr"The identifier >{unit}< does not match any D-SI units! Did you mean one of these >{closestMatchesStr}< ?",RuntimeWarning))
else:
warningMessages.append(_warn(fr"The identifier >{unit}< does not match any D-SI units!",RuntimeWarning))
elifunit=='':
elifunit=='':
itemStr=""
itemStr=""
ifprefix!="":
ifprefix!="":
itemStr=itemStr+"\\"+prefix
itemStr=itemStr+"\\"+prefix
ifexponent!="":
ifexponent!="":
itemStr=itemStr+r"\tothe{"+exponent+r"}"
itemStr=itemStr+r"\tothe{"+exponent+r"}"
warningMessages.append(_warn(f"This D-SI unit seems to be missing the base unit! \"{itemStr}\"",RuntimeWarning))
warningMessages.append(_warn(f"This D-SI unit seems to be missing the base unit! >{itemStr}<",RuntimeWarning))