protected void checkAndSetUnit(LexicalUnitImpl another) { if (getLexicalUnitType() != SAC_INTEGER && getLexicalUnitType() != SAC_REAL && another.getLexicalUnitType() != SAC_INTEGER && another.getLexicalUnitType() != SAC_REAL && getLexicalUnitType() != another.getLexicalUnitType()) { throw new IncompatibleUnitsException(toString()); } if (another.getLexicalUnitType() != SAC_INTEGER && another.getLexicalUnitType() != SAC_REAL) { setLexicalUnitType(another.getLexicalUnitType()); } setNextLexicalUnit(another.getNextLexicalUnit()); }
@Override public LexicalUnitImpl divide(LexicalUnitImpl denominator) { if (denominator.getLexicalUnitType() != SAC_INTEGER && denominator.getLexicalUnitType() != SAC_REAL && getLexicalUnitType() != denominator.getLexicalUnitType()) { throw new IncompatibleUnitsException(toString()); } setFloatValue(getFloatValue() / denominator.getFloatValue()); if (getLexicalUnitType() == denominator.getLexicalUnitType()) { setLexicalUnitType(SAC_REAL); } setNextLexicalUnit(denominator.getNextLexicalUnit()); return this; }
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; }
private void replaceValues(LexicalUnitImpl unit, VariableNode node) { while (unit != null) { if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && unit.getValue().toString().equals(node.getName())) { LexicalUnitImpl.replaceValues(unit, node.getExpr()); } unit = unit.getNextLexicalUnit(); } }
@Override public void replaceVariables(ArrayList<VariableNode> variables) { if (listVariable != null) { for (final VariableNode var : variables) { if (listVariable.equals(var.getName())) { LexicalUnitImpl current = var.getExpr(); list = new ArrayList<String>(); while (current != null) { if (current.getValue() != null && current.getLexicalUnitType() != LexicalUnitImpl.SAC_OPERATOR_COMMA) { list.add(current.getValue().toString()); } current = current.getNextLexicalUnit(); } listVariable = null; break; } } } }
@Override public LexicalUnitImpl modulo(LexicalUnitImpl another) { if (getLexicalUnitType() != another.getLexicalUnitType()) { throw new IncompatibleUnitsException(toString()); } setIntegerValue(getIntegerValue() % another.getIntegerValue()); setNextLexicalUnit(another.getNextLexicalUnit()); return this; }
inputTermLoop: while (current != null) { if (afterOperand) { if (current.getLexicalUnitType() == SCSSLexicalUnit.SCSS_OPERATOR_RIGHT_PAREN) { Object operator = null; while (!operators.isEmpty() if (current.getLexicalUnitType() == operator.type) { while (!operators.isEmpty() && (operators.peek() != Parentheses.LEFT) term); if (current.getLexicalUnitType() == SCSSLexicalUnit.SCSS_OPERATOR_LEFT_PAREN) { operators.push(Parentheses.LEFT); current = current.getNextLexicalUnit();
if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && unit.getNextLexicalUnit() != null) { for (final VariableNode node : def.getArglist()) {
unit = unit.getNextLexicalUnit(); if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && unit.getStringValue().equals(var.getName())) { unit.replaceValue(var.getExpr());
boolean checkMixinForNonOptionalArguments(VariableNode arg, boolean hasNonOptionalArguments) throws ParseException { boolean currentArgHasArguments = arg.getExpr() != null && arg.getExpr().getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && arg.getExpr().getNextLexicalUnit() != null; if(currentArgHasArguments) { if(hasNonOptionalArguments) { throw new ParseException("Sass Error: Required argument $"+ arg.getName() +" must come before any optional arguments."); } return hasNonOptionalArguments; }else { return true; } }
if (value.getLexicalUnitType() == LexicalUnitImpl.SAC_FUNCTION) { LexicalUnitImpl param = value.getParameters(); while (param != null) { if (param.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && param.getValue().toString() .equals(node.getName())) { LexicalUnitImpl current = value; while (current != null) { if (current.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && current.getValue().toString() .equals(node.getName())) {
private static LexicalUnitImpl adjust(LexicalUnitImpl color, float amountByPercent, ColorOperation op, LexicalUnitImpl pre) { if (color.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION) { LexicalUnit funcParam = color.getParameters(); if ("hsl".equals(color.getFunctionName())) { } else if (color.getLexicalUnitType() == LexicalUnit.SAC_IDENT) { if (color.getStringValue().startsWith("#")) { return hslToHexColor( color.getStringValue().substring(1).length()); } else if (color.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) { LexicalUnitImpl hsl = rgbToHsl(color); LexicalUnitImpl hslAfterDarken = adjust(hsl, amountByPercent, op,
case 2: case 4: if ((l.getLexicalUnitType() != LexicalUnit.SAC_INTEGER) && (l.getLexicalUnitType() != LexicalUnit.SAC_PERCENTAGE)) { loop = false; case 1: case 3: if (l.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { loop = false; case 0: case 2: if (l.getLexicalUnitType() != LexicalUnit.SAC_IDENT) { loop = false; if (l.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { loop = false; case 0: case 4: if (l.getLexicalUnitType() != LexicalUnit.SAC_IDENT) { loop = false; if (l.getLexicalUnitType() != LexicalUnit.SAC_STRING_VALUE) { loop = false; case 1: case 3:
LexicalUnitImpl replaceNullValues(LexicalUnitImpl unit) throws ParseException { if(unit == null){ return null; } if (unit.getNextLexicalUnit() != null) { unit.setNextLexicalUnit(replaceNullValues(unit.getNextLexicalUnit())); } if (unit.getLexicalUnitType() == SCSSLexicalUnit.SAC_IDENT && "null".equals(unit.getStringValue())) { LexicalUnitImpl next = unit.getNextLexicalUnit(); unit = LexicalUnitImpl.createNull(unit.getLineNumber(), unit.getColumnNumber(), unit.getPreviousLexicalUnit()); unit.setNextLexicalUnit(next); } return unit; }
@Override public void replaceVariables(ArrayList<VariableNode> variables) { for (final VariableNode node : variables) { if (!equals(node)) { if (StringUtil .containsVariable(expr.toString(), node.getName())) { if (expr.getParameters() != null && StringUtil.containsVariable(expr.getParameters() .toString(), node.getName())) { replaceValues(expr.getParameters(), node); } else if (expr.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE) { replaceValues(expr, node); } } } } }
public static void traverse(VariableNode node) { VariableNode variable = ScssStylesheet.getVariable(node.getName()); if (!node.isGuarded() || variable == null || variable.getExpr() == null || (variable.getExpr().getLexicalUnitType() == SCSSLexicalUnit.SCSS_NULL && variable .getExpr().getNextLexicalUnit() == null)) { ScssStylesheet.addVariable(node); } node.getParentNode().removeChild(node); } }
public static void replaceValues(LexicalUnitImpl unit, LexicalUnitImpl replaceWith) { unit.setLexicalUnitType(replaceWith.getLexicalUnitType()); unit.setStringValue(replaceWith.getStringValue()); unit.setFloatValue(replaceWith.getFloatValue()); unit.setIntegerValue(replaceWith.getIntegerValue()); unit.setFunctionName(replaceWith.getFunctionName()); if (replaceWith.getParameters() != null) { unit.setParameters(replaceWith.getParameters()); } } }
@Override public String toString() { short type = getLexicalUnitType(); String text = null; switch (type) { if (getNextLexicalUnit().getLexicalUnitType() == SAC_OPERATOR_COMMA) { return text + getNextLexicalUnit();
public void replaceValue(LexicalUnitImpl another) { // shouldn't modify 'another' directly, should only modify its copy. LexicalUnitImpl deepCopyAnother = (LexicalUnitImpl) DeepCopy .copy(another); type = deepCopyAnother.getLexicalUnitType(); i = deepCopyAnother.getIntegerValue(); f = deepCopyAnother.getFloatValue(); s = deepCopyAnother.getStringValue(); fname = deepCopyAnother.getFunctionName(); prev = deepCopyAnother.getPreviousLexicalUnit(); dimension = deepCopyAnother.getDimension(); sdimension = deepCopyAnother.getSdimension(); params = deepCopyAnother.getParameters(); LexicalUnitImpl finalNextInAnother = deepCopyAnother; while (finalNextInAnother.getNextLexicalUnit() != null) { finalNextInAnother = finalNextInAnother.getNextLexicalUnit(); } finalNextInAnother.setNextLexicalUnit(next); next = deepCopyAnother.next; }