Package com.vaadin.sass.internal.parser

Examples of com.vaadin.sass.internal.parser.LexicalUnitImpl


                hsl.getColumnNumber(), hsl.getPreviousLexicalUnit(),
                builder.toString());
    }

    private static int[] calculateRgb(LexicalUnitImpl hsl) {
        LexicalUnitImpl hslParam = hsl.getParameters();
        LexicalUnitImpl hue = null;
        LexicalUnitImpl saturation = null;
        LexicalUnitImpl lightness = null;
        int i = 0;
        while (i < 5) {
            switch (i) {
            case 0:
                hue = hslParam;
                break;
            case 2:
                saturation = hslParam;
                break;
            case 4:
                lightness = hslParam;
                break;
            case 1:
            case 3:
                break;
            }
            hslParam = hslParam.getNextLexicalUnit();
            i++;
        }
        float h = ((hue.getIntegerValue() % 360) + 360) % 360 / 360f;
        float s = saturation.getFloatValue() / 100;
        float l = lightness.getFloatValue() / 100;
        float m2, m1;
        int[] rgb = new int[3];
        m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
        m1 = l * 2 - m2;
        rgb[0] = Math.round(hueToRgb(m1, m2, h + 1f / 3) * 255);
 
View Full Code Here


        rgb[2] = Math.round(hueToRgb(m1, m2, h - 1f / 3) * 255);
        return rgb;
    }

    public static LexicalUnitImpl rgbToHsl(LexicalUnitImpl rgb) {
        LexicalUnitImpl rgbParam = rgb.getParameters();
        LexicalUnitImpl red = null;
        LexicalUnitImpl green = null;
        LexicalUnitImpl blue = null;
        int i = 0;
        while (i < 5) {
            switch (i) {
            case 0:
                red = rgbParam;
                break;
            case 2:
                green = rgbParam;
                break;
            case 4:
                blue = rgbParam;
                break;
            case 1:
            case 3:
                break;
            }
            rgbParam = rgbParam.getNextLexicalUnit();
            i++;
        }

        int hsl[] = calculateHsl(red.getIntegerValue(),
                green.getIntegerValue(), blue.getIntegerValue());

        rgbParam = rgb.getParameters();

        LexicalUnitImpl hslParams = createHslParameters(hsl[0], hsl[1], hsl[2],
                rgbParam.getLineNumber(), rgbParam.getColumnNumber(),
                rgbParam.getPreviousLexicalUnit());

        return LexicalUnitImpl.createFunction(rgb.getLineNumber(),
                rgb.getColumnNumber(), rgb.getPreviousLexicalUnit(), "hsl",
View Full Code Here

        return hsl;
    }

    public static LexicalUnitImpl hslToRgb(LexicalUnitImpl hsl) {
        int[] rgb = calculateRgb(hsl);
        LexicalUnitImpl hslParam = hsl.getParameters();
        LexicalUnitImpl rgbParams = createRgbParameters(rgb[0], rgb[1], rgb[2],
                hslParam.getLineNumber(), hslParam.getColumnNumber(),
                hslParam.getPreviousLexicalUnit());

        return LexicalUnitImpl.createFunction(hsl.getLineNumber(),
                hsl.getColumnNumber(), hsl.getPreviousLexicalUnit(), "rgb",
View Full Code Here

            }
            checkExtraParameters(mixinNode, remainingNodes.size(),
                    remainingUnits.size());
            for (int i = 0; i < remainingNodes.size()
                    && i < remainingUnits.size(); i++) {
                LexicalUnitImpl unit = remainingUnits.get(i);
                remainingNodes.get(i).setExpr(
                        (LexicalUnitImpl) DeepCopy.copy(unit));
            }
        }
View Full Code Here

        this.operator = operator;
        this.rightOperand = rightOperand;
    }

    public LexicalUnitImpl eval() {
        LexicalUnitImpl leftValue = (leftOperand instanceof BinaryExpression) ? ((BinaryExpression) leftOperand)
                .eval() : (LexicalUnitImpl) leftOperand;
        LexicalUnitImpl rightValue = (rightOperand instanceof BinaryExpression) ? ((BinaryExpression) rightOperand)
                .eval() : (LexicalUnitImpl) rightOperand;
        return operator.eval(leftValue, rightValue);
    }
View Full Code Here

        operands.push(new BinaryExpression(operands.pop(), operator,
                rightOperand));
    }

    public boolean containsArithmeticalOperator(LexicalUnitImpl term) {
        LexicalUnitImpl current = term;
        while (current != null) {
            for (BinaryOperator operator : BinaryOperator.values()) {
                /*
                 * '/' is treated as an arithmetical operator when one of its
                 * operands is Variable, or there is another binary operator.
                 * Otherwise, '/' is treated as a CSS operator.
                 */
                if (current.getLexicalUnitType() == operator.type) {
                    if (current.getLexicalUnitType() != BinaryOperator.DIV.type) {
                        return true;
                    } else {
                        if (current.getPreviousLexicalUnit()
                                .getLexicalUnitType() == SCSS_VARIABLE
                                || current.getNextLexicalUnit()
                                        .getLexicalUnitType() == SCSS_VARIABLE) {
                            return true;
                        }
                    }
                }
            }
            current = current.getNextLexicalUnit();
        }
        return false;
    }
View Full Code Here

        }
        return false;
    }

    private Object createExpression(LexicalUnitImpl term) {
        LexicalUnitImpl current = term;
        boolean afterOperand = false;
        Stack<Object> operands = new Stack<Object>();
        Stack<Object> operators = new Stack<Object>();
        inputTermLoop: while (current != null) {
            if (afterOperand) {
                if (current.getLexicalUnitType() == SCSSLexicalUnit.SCSS_OPERATOR_RIGHT_PAREN) {
                    Object operator = null;
                    while (!operators.isEmpty()
                            && ((operator = operators.pop()) != Parentheses.LEFT)) {
                        createNewOperand((BinaryOperator) operator, operands);
                    }
                    current = current.getNextLexicalUnit();
                    continue;
                }
                afterOperand = false;
                for (BinaryOperator operator : BinaryOperator.values()) {
                    if (current.getLexicalUnitType() == operator.type) {
                        while (!operators.isEmpty()
                                && (operators.peek() != Parentheses.LEFT)
                                && (((BinaryOperator) operators.peek()).precedence >= operator.precedence)) {
                            createNewOperand((BinaryOperator) operators.pop(),
                                    operands);
                        }
                        operators.push(operator);

                        current = current.getNextLexicalUnit();
                        continue inputTermLoop;
                    }
                }
                throw new ArithmeticException();
            }
            if (current.getLexicalUnitType() == SCSSLexicalUnit.SCSS_OPERATOR_LEFT_PAREN) {
                operators.push(Parentheses.LEFT);
                current = current.getNextLexicalUnit();
                continue;
            }
            afterOperand = true;

            operands.push(current);
            current = current.getNextLexicalUnit();
        }

        while (!operators.isEmpty()) {
            Object operator = operators.pop();
            if (operator == Parentheses.LEFT) {
                throw new ArithmeticException("Unexpected \"(\" found");
            }
            createNewOperand((BinaryOperator) operator, operands);
        }
        Object expression = operands.pop();
        if (!operands.isEmpty()) {
            LexicalUnitImpl operand = (LexicalUnitImpl) operands.peek();
            throw new ArithmeticException("Unexpected operand "
                    + operand.toString() + " found");
        }
        return expression;
    }
View Full Code Here

    @Override
    public void replaceVariables(ArrayList<VariableNode> variables) {
        for (final VariableNode var : variables) {
            for (final LexicalUnitImpl arg : new ArrayList<LexicalUnitImpl>(
                    arglist)) {
                LexicalUnitImpl unit = arg;
                // only perform replace in the value if separate argument name
                // and value
                if (unit.getNextLexicalUnit() != null) {
                    unit = unit.getNextLexicalUnit();
                }
                if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
                        && unit.getStringValue().equals(var.getName())) {
                    unit.replaceValue(var.getExpr());
                }
            }

            if (name.startsWith("$")) {
                if (name.equals("$" + var.getName())) {
View Full Code Here

            }
            checkExtraParameters(mixinNode, remainingNodes.size(),
                    remainingUnits.size());
            for (int i = 0; i < remainingNodes.size()
                    && i < remainingUnits.size(); i++) {
                LexicalUnitImpl unit = remainingUnits.get(i);
                remainingNodes.get(i).setExpr(
                        (LexicalUnitImpl) DeepCopy.copy(unit));
            }
        }
View Full Code Here

            if (value.getLexicalUnitType() == LexicalUnitImpl.SAC_FUNCTION) {

                if (value.getParameters() != null) {
                    if (StringUtil.containsVariable(value.getParameters()
                            .toString(), node.getName())) {
                        LexicalUnitImpl param = value.getParameters();
                        while (param != null) {
                            if (param.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
                                    && param.getValue().toString()
                                            .equals(node.getName())) {
                                param.replaceValue(node.getExpr());
                            }
                            param = param.getNextLexicalUnit();
                        }
                    }
                }
            } else if (value.getStringValue() != null
                    && value.getStringValue().contains(interpolation)) {
                LexicalUnitImpl current = value;
                while (current != null) {
                    if (current.getValue().toString().contains(interpolation)) {

                        current.setStringValue(current
                                .getValue()
                                .toString()
                                .replaceAll(Pattern.quote(interpolation),
                                        node.getExpr().toString()));
                    }
                    current = current.getNextLexicalUnit();
                }
            } else {
                LexicalUnitImpl current = value;
                while (current != null) {
                    if (current.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
                            && current.getValue().toString()
                                    .equals(node.getName())) {

                        current.replaceValue(node.getExpr());
                    }
                    current = current.getNextLexicalUnit();
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.vaadin.sass.internal.parser.LexicalUnitImpl

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.