LHNCBC / ucum-lhc

LHC implementation of UCUM validation and conversion services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`g.m2-1` passes as valid in online validator (but should probably not)

dalito opened this issue · comments

For pure UCUM codes I am quite sure that g.m2-1 is invalid. The result in the online validator is g.m2-1 (gram*[meter2]) is a valid unit expression so the parser just drops the -1 part. (related dalito/ucumvert#8)

Or is this a question of the UCUM version? I am wondering because of

g.(m2)-1 (gram*[square meter]) is a valid unit expression.
An exponent (-1) following a parenthesis is invalid as of revision 1.9 of the UCUM Specification. 
Did you mean m2-1?

Thanks for the report. I agree that both g.m2-1 and g.(m2)-1 should be invalid per the current specification which says (in the BNF grammar) that an exponent can only follow a simple unit. I think we are allowing g.(m2)-1 because we started this parser 9 years ago, and I think it might have been loosely derived from some even older code, which might explain the pre 1.9 behavior. It is hard to imagine that g.m2-1 would ever have been allowed in the specification, though. So, we will fix that one. For the other, I am not quite sure what to do about the issue of changes in UCUM versions and things becoming invalid that were previously valid.

Thanks for confirming!

With respect to g.(m2)-1: If it was allowed prior to 1.9 what was the expected result? Is the current (gram*[square meter]) correct or should it be (gram*[square meter]**-2). I could not find change notes covering this. It seems that some information from pre-GitHub times did not make it to GitHub.

The generation of the display strings ((gram*[square meter])") generally has more bugs than the parsing of the actual unit, and I would not look at that as a reliable indicator of what used to be. If "g.(m2)-1" was valid, the I would expect the display string should be something like (gram*[square meter]**-1). That the -1 is lost is a bug in the generation of the display string.

This issue is fixed with latest version. g.m2-1 and g.(m2)-1 are now both invalid on the online validator.