Skip to content

Commit

Permalink
Renamed composed expression to binary expression. #22
Browse files Browse the repository at this point in the history
  • Loading branch information
meri committed Mar 31, 2014
1 parent 6e1ecd7 commit 32a9b65
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/sommeri/less4j/LessFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.github.sommeri.less4j.core.ast.ComposedExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.Expression;
import com.github.sommeri.less4j.core.ast.FunctionExpression;

Expand All @@ -27,7 +27,7 @@ public interface LessFunction {
*
* The <code>evaluatedParameter</code> contains function arguments as parsed into a single abstract
* syntax tree node. A function called with multiple arguments would be sent an instance of
* {@link ComposedExpression} with arguments bundled in as childs.
* {@link BinaryExpression} with arguments bundled in as childs.
*
* The <code>evaluatedParameter</code> contains list of function arguments. It is convenience argument
* and contains <code>evaluatedParameter</code> expression split by commas.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.github.sommeri.less4j.core.ast;

public enum ASTCssNodeType {
UNKNOWN, CSS_CLASS, DECLARATION, STYLE_SHEET, RULE_SET, SELECTOR, SIMPLE_SELECTOR, PSEUDO_CLASS, PSEUDO_ELEMENT, SELECTOR_ATTRIBUTE, ID_SELECTOR, CHARSET_DECLARATION, FONT_FACE, IDENTIFIER_EXPRESSION, COMPOSED_EXPRESSION, STRING_EXPRESSION, NUMBER, COLOR_EXPRESSION, FUNCTION, MEDIA, COMMENT, SELECTOR_OPERATOR, SELECTOR_COMBINATOR, BINARY_EXPRESSION_OPERATOR, NTH, NAMED_EXPRESSION, MEDIA_QUERY, FIXED_MEDIA_EXPRESSION, MEDIUM, MEDIUM_MODIFIER, MEDIUM_TYPE, MEDIUM_EX_FEATURE, VARIABLE_DECLARATION, VARIABLE, INDIRECT_VARIABLE, PARENTHESES_EXPRESSION, SIGNED_EXPRESSION, ARGUMENT_DECLARATION, MIXIN_REFERENCE, GUARD_CONDITION, COMPARISON_EXPRESSION, GUARD, NESTED_SELECTOR_APPENDER, REUSABLE_STRUCTURE, FAULTY_EXPRESSION, ESCAPED_SELECTOR, ESCAPED_VALUE, INTERPOLABLE_NAME, FIXED_NAME_PART, VARIABLE_NAME_PART, KEYFRAMES, KEYFRAMES_NAME, REUSABLE_STRUCTURE_NAME, VIEWPORT, GENERAL_BODY, PAGE, NAME, PAGE_MARGIN_BOX, IMPORT, FAULTY_NODE, ANONYMOUS, EMPTY_EXPRESSION, SYNTAX_ONLY_ELEMENT, UNICODE_RANGE_EXPRESSION, INTERPOLATED_MEDIA_EXPRESSION, DOCUMENT, SUPPORTS, SUPPORTS_QUERY, SUPPORTS_CONDITION_NEGATION, SUPPORTS_CONDITION_PARENTHESES, SUPPORTS_CONDITION_LOGICAL, SUPPORTS_LOGICAL_OPERATOR, EXTEND, INLINE_CONTENT, EMBEDDED_SCRIPT, LIST_EXPRESSION_OPERATOR, LIST_EXPRESSION
UNKNOWN, CSS_CLASS, DECLARATION, STYLE_SHEET, RULE_SET, SELECTOR, SIMPLE_SELECTOR, PSEUDO_CLASS, PSEUDO_ELEMENT, SELECTOR_ATTRIBUTE, ID_SELECTOR, CHARSET_DECLARATION, FONT_FACE, IDENTIFIER_EXPRESSION, BINARY_EXPRESSION, STRING_EXPRESSION, NUMBER, COLOR_EXPRESSION, FUNCTION, MEDIA, COMMENT, SELECTOR_OPERATOR, SELECTOR_COMBINATOR, BINARY_EXPRESSION_OPERATOR, NTH, NAMED_EXPRESSION, MEDIA_QUERY, FIXED_MEDIA_EXPRESSION, MEDIUM, MEDIUM_MODIFIER, MEDIUM_TYPE, MEDIUM_EX_FEATURE, VARIABLE_DECLARATION, VARIABLE, INDIRECT_VARIABLE, PARENTHESES_EXPRESSION, SIGNED_EXPRESSION, ARGUMENT_DECLARATION, MIXIN_REFERENCE, GUARD_CONDITION, COMPARISON_EXPRESSION, GUARD, NESTED_SELECTOR_APPENDER, REUSABLE_STRUCTURE, FAULTY_EXPRESSION, ESCAPED_SELECTOR, ESCAPED_VALUE, INTERPOLABLE_NAME, FIXED_NAME_PART, VARIABLE_NAME_PART, KEYFRAMES, KEYFRAMES_NAME, REUSABLE_STRUCTURE_NAME, VIEWPORT, GENERAL_BODY, PAGE, NAME, PAGE_MARGIN_BOX, IMPORT, FAULTY_NODE, ANONYMOUS, EMPTY_EXPRESSION, SYNTAX_ONLY_ELEMENT, UNICODE_RANGE_EXPRESSION, INTERPOLATED_MEDIA_EXPRESSION, DOCUMENT, SUPPORTS, SUPPORTS_QUERY, SUPPORTS_CONDITION_NEGATION, SUPPORTS_CONDITION_PARENTHESES, SUPPORTS_CONDITION_LOGICAL, SUPPORTS_LOGICAL_OPERATOR, EXTEND, INLINE_CONTENT, EMBEDDED_SCRIPT, LIST_EXPRESSION_OPERATOR, LIST_EXPRESSION
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import com.github.sommeri.less4j.core.parser.HiddenTokenAwareTree;
import com.github.sommeri.less4j.utils.ArraysUtils;

public class ComposedExpression extends Expression {
public class BinaryExpression extends Expression {

private Expression left;
private BinaryExpressionOperator operator;
private Expression right;

public ComposedExpression(HiddenTokenAwareTree token, Expression left, BinaryExpressionOperator operator, Expression right) {
public BinaryExpression(HiddenTokenAwareTree token, Expression left, BinaryExpressionOperator operator, Expression right) {
super(token);
this.left = left;
this.operator = operator;
Expand All @@ -21,7 +21,7 @@ public ComposedExpression(HiddenTokenAwareTree token, Expression left, BinaryExp

@Override
public ASTCssNodeType getType() {
return ASTCssNodeType.COMPOSED_EXPRESSION;
return ASTCssNodeType.BINARY_EXPRESSION;
}

public BinaryExpressionOperator getOperator() {
Expand Down Expand Up @@ -60,8 +60,8 @@ public String toString() {
}

@Override
public ComposedExpression clone() {
ComposedExpression result = (ComposedExpression) super.clone();
public BinaryExpression clone() {
BinaryExpression result = (BinaryExpression) super.clone();
result.left = left==null?null:left.clone();
result.operator = operator==null?null:operator.clone();
result.right = right==null?null:right.clone();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.sommeri.less4j.core.compiler.expressions;

import com.github.sommeri.less4j.core.ast.ASTCssNodeType;
import com.github.sommeri.less4j.core.ast.ComposedExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.Expression;
import com.github.sommeri.less4j.core.ast.BinaryExpressionOperator;
import com.github.sommeri.less4j.core.ast.FaultyExpression;
Expand All @@ -19,7 +19,7 @@ public ArithmeticCalculator(ProblemsHandler problemsHandler) {
this.problemsHandler = problemsHandler;
}

public Expression evalute(ComposedExpression originalExpression, Expression firstNumber, Expression secondNumber) {
public Expression evalute(BinaryExpression originalExpression, Expression firstNumber, Expression secondNumber) {
NumberExpression first = (NumberExpression) firstNumber;
NumberExpression second = (NumberExpression) secondNumber;

Expand All @@ -40,7 +40,7 @@ public Expression evalute(ComposedExpression originalExpression, Expression firs

}

private Expression subtract(NumberExpression first, NumberExpression second, ComposedExpression originalExpression) {
private Expression subtract(NumberExpression first, NumberExpression second, BinaryExpression originalExpression) {
return subtractNumbers(first, second, originalExpression.getUnderlyingStructure());
}

Expand All @@ -52,7 +52,7 @@ private Expression subtractNumbers(NumberExpression first, NumberExpression seco
return createResultNumber(parentToken, resultVal, first, second);
}

private Expression multiply(NumberExpression first, NumberExpression second, ComposedExpression originalExpression) {
private Expression multiply(NumberExpression first, NumberExpression second, BinaryExpression originalExpression) {
return multiplyNumbers(first, second, originalExpression.getUnderlyingStructure());
}

Expand All @@ -64,7 +64,7 @@ private Expression multiplyNumbers(NumberExpression first, NumberExpression seco
return createResultNumber(parentToken, resultVal, first, second);
}

private Expression divide(NumberExpression first, NumberExpression second, ComposedExpression originalExpression) {
private Expression divide(NumberExpression first, NumberExpression second, BinaryExpression originalExpression) {
return divideNumbers(first, second, originalExpression.getUnderlyingStructure());
}

Expand All @@ -76,7 +76,7 @@ private Expression divideNumbers(NumberExpression first, NumberExpression second
return createResultNumber(parentToken, resultVal, first, second);
}

private Expression add(NumberExpression first, NumberExpression second, ComposedExpression originalExpression) {
private Expression add(NumberExpression first, NumberExpression second, BinaryExpression originalExpression) {
return addNumbers(first, second, originalExpression.getUnderlyingStructure());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.github.sommeri.less4j.core.ast.ASTCssNodeType;
import com.github.sommeri.less4j.core.ast.ColorExpression;
import com.github.sommeri.less4j.core.ast.ColorExpression.ColorWithAlphaExpression;
import com.github.sommeri.less4j.core.ast.ComposedExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.Expression;
import com.github.sommeri.less4j.core.ast.BinaryExpressionOperator;
import com.github.sommeri.less4j.core.ast.FaultyExpression;
Expand All @@ -26,7 +26,7 @@ public ColorsCalculator(ProblemsHandler problemsHandler) {
this.problemsHandler = problemsHandler;
}

public Expression evalute(ComposedExpression originalExpression, Expression first, Expression second) {
public Expression evalute(BinaryExpression originalExpression, Expression first, Expression second) {
double red1 = calcRed(first);
double green1 = calcGreen(first);
double blue1 = calcBlue(first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.github.sommeri.less4j.core.ast.BinaryExpressionOperator.Operator;
import com.github.sommeri.less4j.core.ast.ComparisonExpression;
import com.github.sommeri.less4j.core.ast.ComparisonExpressionOperator;
import com.github.sommeri.less4j.core.ast.ComposedExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.CssString;
import com.github.sommeri.less4j.core.ast.EmbeddedScript;
import com.github.sommeri.less4j.core.ast.EscapedValue;
Expand Down Expand Up @@ -183,8 +183,8 @@ public Expression evaluate(Expression input) {
case FUNCTION:
return evaluate((FunctionExpression) input);

case COMPOSED_EXPRESSION:
return evaluate((ComposedExpression) input);
case BINARY_EXPRESSION:
return evaluate((BinaryExpression) input);

case LIST_EXPRESSION:
return evaluate((ListExpression) input);
Expand Down Expand Up @@ -326,7 +326,7 @@ public Expression evaluate(SignedExpression input) {
return new FaultyExpression(input);
}

public Expression evaluate(ComposedExpression input) {
public Expression evaluate(BinaryExpression input) {
Expression leftValue = evaluate(input.getLeft());
Expression rightValue = evaluate(input.getRight());
if (leftValue.isFaulty() || rightValue.isFaulty())
Expand Down Expand Up @@ -393,10 +393,10 @@ private boolean evaluate(GuardCondition guardCondition) {
}

public boolean isRatioExpression(Expression expression) {
if (!(expression instanceof ComposedExpression))
if (!(expression instanceof BinaryExpression))
return false;

ComposedExpression composed = (ComposedExpression) expression;
BinaryExpression composed = (BinaryExpression) expression;
if (composed.getOperator().getOperator() != Operator.SOLIDUS) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.github.sommeri.less4j.core.ast.CharsetDeclaration;
import com.github.sommeri.less4j.core.ast.ComparisonExpression;
import com.github.sommeri.less4j.core.ast.ComparisonExpressionOperator;
import com.github.sommeri.less4j.core.ast.ComposedExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.CssClass;
import com.github.sommeri.less4j.core.ast.Declaration;
import com.github.sommeri.less4j.core.ast.Document;
Expand Down Expand Up @@ -211,10 +211,10 @@ private Expression createBinaryExpression(HiddenTokenAwareTree parent, LinkedLis
while (!members.isEmpty()) {
BinaryExpressionOperator operator = createBinaryOperator(members.removeFirst());
if (members.isEmpty())
return new ComposedExpression(parent, head, operator, null);
return new BinaryExpression(parent, head, operator, null);

Expression next = (Expression) switchOn(members.removeFirst());
head = new ComposedExpression(parent, head, operator, next);
head = new BinaryExpression(parent, head, operator, next);
}
return head;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/sommeri/less4j/utils/CssPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.github.sommeri.less4j.core.ast.CharsetDeclaration;
import com.github.sommeri.less4j.core.ast.ColorExpression;
import com.github.sommeri.less4j.core.ast.Comment;
import com.github.sommeri.less4j.core.ast.ComposedExpression;
import com.github.sommeri.less4j.core.ast.BinaryExpression;
import com.github.sommeri.less4j.core.ast.CssClass;
import com.github.sommeri.less4j.core.ast.CssString;
import com.github.sommeri.less4j.core.ast.Declaration;
Expand Down Expand Up @@ -167,8 +167,8 @@ public boolean switchOnType(ASTCssNode node) {
case NAMED_EXPRESSION:
return appendNamedExpression((NamedExpression) node); // TODOsm: source map

case COMPOSED_EXPRESSION:
return appendComposedExpression((ComposedExpression) node); // TODOsm: source map
case BINARY_EXPRESSION:
return appendComposedExpression((BinaryExpression) node); // TODOsm: source map

case BINARY_EXPRESSION_OPERATOR:
return appendBinaryExpressionOperator((BinaryExpressionOperator) node); // TODOsm: source map
Expand Down Expand Up @@ -773,7 +773,7 @@ public boolean appendNamedExpression(NamedExpression expression) {
return true;
}

public boolean appendComposedExpression(ComposedExpression expression) {
public boolean appendComposedExpression(BinaryExpression expression) {
append(expression.getLeft());
append(expression.getOperator());
append(expression.getRight());
Expand Down

0 comments on commit 32a9b65

Please sign in to comment.