use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class LocalUnitFormatParser method parseUnit.
public final Unit parseUnit() throws TokenException {
Unit result = CompoundExpr();
consumeToken(0);
{
return result;
}
}
use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class LocalUnitFormatParser method AddExpr.
public final Unit AddExpr() throws TokenException {
Unit result = AbstractUnit.ONE;
Number n1 = null;
Token sign1 = null;
Number n2 = null;
Token sign2 = null;
if (jj_2_1(2147483647)) {
n1 = NumberExpr();
sign1 = Sign();
} else {
}
result = MulExpr();
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case PLUS:
case MINUS:
sign2 = Sign();
n2 = NumberExpr();
break;
default:
laA[1] = genInt;
}
if (n1 != null) {
if (sign1.image.equals("-")) {
result = result.multiply(-1);
}
result = result.shift(n1.doubleValue());
}
if (n2 != null) {
double offset = n2.doubleValue();
if (sign2.image.equals("-")) {
offset = -offset;
}
result = result.shift(offset);
}
{
return result;
}
}
use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class LocalUnitFormatParser method ExponentExpr.
public final Unit ExponentExpr() throws TokenException {
Unit result = AbstractUnit.ONE;
Exponent exponent = null;
Token token = null;
if (jj_2_2(2147483647)) {
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case INTEGER:
token = consumeToken(INTEGER);
break;
case E:
token = consumeToken(E);
break;
default:
laA[5] = genInt;
consumeToken(-1);
throw new TokenException();
}
consumeToken(CARET);
result = AtomicExpr();
double base;
if (token.kind == INTEGER) {
base = Integer.parseInt(token.image);
} else {
base = StrictMath.E;
}
{
return result.transform(new LogConverter(base).inverse());
}
} else {
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case OPEN_PAREN:
case INTEGER:
case FLOATING_POINT:
case UNIT_IDENTIFIER:
result = AtomicExpr();
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case CARET:
case SUPERSCRIPT_INTEGER:
exponent = Exp();
break;
default:
laA[6] = genInt;
}
if (exponent != null) {
if (exponent.pow != 1) {
result = result.pow(exponent.pow);
}
if (exponent.root != 1) {
result = result.root(exponent.root);
}
}
{
return result;
}
case LOG:
case NAT_LOG:
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case LOG:
consumeToken(LOG);
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case INTEGER:
token = consumeToken(INTEGER);
break;
default:
laA[7] = genInt;
}
break;
case NAT_LOG:
token = consumeToken(NAT_LOG);
break;
default:
laA[8] = genInt;
consumeToken(-1);
throw new TokenException();
}
consumeToken(OPEN_PAREN);
result = AddExpr();
consumeToken(CLOSE_PAREN);
double base = 10;
if (token != null) {
if (token.kind == INTEGER) {
base = Integer.parseInt(token.image);
} else if (token.kind == NAT_LOG) {
base = StrictMath.E;
}
}
{
return result.transform(new LogConverter(base));
}
default:
laA[9] = genInt;
consumeToken(-1);
throw new TokenException();
}
}
}
use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class SymbolMapTest method parseWithEBNFUnitFormat.
/**
* Test if parsing 'dag' equals DEKA(GRAM)
*/
@Test
public void parseWithEBNFUnitFormat() {
Unit u2 = EBNFUnitFormat.getInstance().parse("dag");
assertEquals(MetricPrefix.DEKA(Units.GRAM), u2);
}
use of javax.measure.Unit in project uom-se by unitsofmeasurement.
the class LocalUnitFormatParser method MulExpr.
public final Unit MulExpr() throws TokenException {
Unit result = AbstractUnit.ONE;
Unit temp = AbstractUnit.ONE;
result = ExponentExpr();
label_2: while (true) {
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case ASTERISK:
case MIDDLE_DOT:
case SOLIDUS:
break;
default:
laA[2] = genInt;
break label_2;
}
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case ASTERISK:
case MIDDLE_DOT:
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case ASTERISK:
consumeToken(ASTERISK);
break;
case MIDDLE_DOT:
consumeToken(MIDDLE_DOT);
break;
default:
laA[3] = genInt;
consumeToken(-1);
throw new TokenException();
}
temp = ExponentExpr();
result = result.multiply(temp);
break;
case SOLIDUS:
consumeToken(SOLIDUS);
temp = ExponentExpr();
result = result.divide(temp);
break;
default:
laA[4] = genInt;
consumeToken(-1);
throw new TokenException();
}
}
{
return result;
}
}
Aggregations