Package com.github.sommeri.less4j.core.ast

Examples of com.github.sommeri.less4j.core.ast.NumberExpression


    return parsedColor;
  }

  private Expression negate(Expression value, HiddenTokenAwareTree sign) {
    if (value instanceof NumberExpression) {
      NumberExpression number = (NumberExpression) value;
      number.setExpliciteSign(true);

      if (sign.getType() == LessLexer.MINUS) {
        number.negate();
        number.setOriginalString("-" + number.getOriginalString());
      } else if (sign.getType() == LessLexer.PLUS) {
        number.setOriginalString("+" + number.getOriginalString());
      }

      return number;
    }
View Full Code Here


    return new SignedExpression(sign, SignedExpression.Sign.PLUS, value);
  }

  private NumberExpression buildFromNumber(HiddenTokenAwareTree token, HiddenTokenAwareTree actual) {
    NumberExpression result = new NumberExpression(token);
    String valueAsString = actual.getText().trim();
    setDoubleAndType(result, valueAsString);
    result.setOriginalString(valueAsString);
    result.setDimension(toDimension(actual));
    return result;
  }
View Full Code Here

          return new Nth(token, null, null, Form.EVEN);
        } else if ("odd".equals(lowerCaseValue)) {
          return new Nth(token, null, null, Form.ODD);
        } else if ("n".equals(lowerCaseValue) || "-n".equals(lowerCaseValue) || "+n".equals(lowerCaseValue)) {
          boolean expliciteSign = !"n".equals(lowerCaseValue);
          first = new NumberExpression(token.getChild(0), lowerCaseValue, NumberExpression.Dimension.REPEATER, expliciteSign);
        } else
          throw new IllegalStateException("Unexpected identifier value for nth: " + ident.getValue());
      }
    }
View Full Code Here

abstract class AbstractColorAmountFunction extends AbstractColorFunction {

  @Override
  protected Expression evaluate(List<Expression> splitParameters, ProblemsHandler problemsHandler, FunctionExpression functionCall, HiddenTokenAwareTree token) {
    ColorExpression color = (ColorExpression) splitParameters.get(0);
    NumberExpression amount = (NumberExpression) splitParameters.get(1);

    return evaluate(color, amount, token);
  }
View Full Code Here

    return false;
  }

  private boolean equalNumber(NumberExpression pattern, Expression expression) {
    if (expression instanceof NumberExpression) {
      NumberExpression numberExpression = (NumberExpression) expression;
      return numberEqual(pattern, numberExpression);
    }

    return false;
  }
View Full Code Here

  private boolean equalSigned(SignedExpression pattern, Expression expression) {
    if (expression instanceof SignedExpression) {
      return equalNegated(pattern, (SignedExpression) expression);
    }
    if (expression instanceof NumberExpression && pattern.getExpression() instanceof NumberExpression) {
      NumberExpression patternClone = (NumberExpression) pattern.getExpression().clone();

      if (pattern.getSign() == Sign.MINUS)
        patternClone.setValueAsDouble(patternClone.getValueAsDouble() * -1);

      NumberExpression number = (NumberExpression) expression;
      return equalNumber(patternClone, number);
    }

    return false;
  }
View Full Code Here

class Extract extends CatchAllMultiParameterFunction {

  @Override
  protected Expression evaluate(List<Expression> splitParameters, ProblemsHandler problemsHandler, FunctionExpression functionCall, HiddenTokenAwareTree token) {
    List<Expression> values = collect((ListExpression) splitParameters.get(0));
    NumberExpression index = (NumberExpression) splitParameters.get(1);
    return values.get(index.getValueAsDouble().intValue() - 1);
  }
View Full Code Here

class Hue extends AbstractColorOperationFunction {

  @Override
  protected Expression evaluate(ColorExpression color, ProblemsHandler problemsHandler, HiddenTokenAwareTree token) {
    HSLAValue hsla = toHSLA(color);
    return new NumberExpression(token, Double.valueOf(Math.round(hsla.h)), "", null, Dimension.NUMBER);
  }
View Full Code Here

class Saturation extends AbstractColorOperationFunction {

  @Override
  protected Expression evaluate(ColorExpression color, ProblemsHandler problemsHandler, HiddenTokenAwareTree token) {
    HSLAValue hsla = toHSLA(color);
    return new NumberExpression(token, Double.valueOf(Math.round(hsla.s * 100)), "%", null, Dimension.PERCENTAGE);
  }
View Full Code Here

class Lightness extends AbstractColorOperationFunction {

  @Override
  protected Expression evaluate(ColorExpression color, ProblemsHandler problemsHandler, HiddenTokenAwareTree token) {
    HSLAValue hsla = toHSLA(color);
    return new NumberExpression(token, Double.valueOf(Math.round(hsla.l * 100)), "%", null, Dimension.PERCENTAGE);
  }
View Full Code Here

TOP

Related Classes of com.github.sommeri.less4j.core.ast.NumberExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.