You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BinaryOperator.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.sass.internal.expression;
  17. import org.w3c.css.sac.LexicalUnit;
  18. import com.vaadin.sass.internal.parser.LexicalUnitImpl;
  19. public enum BinaryOperator {
  20. ADD(LexicalUnit.SAC_OPERATOR_PLUS, 1) {
  21. @Override
  22. public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
  23. LexicalUnitImpl rightValue) {
  24. return leftValue.add(rightValue);
  25. }
  26. },
  27. MINUS(LexicalUnit.SAC_OPERATOR_MINUS, 1) {
  28. @Override
  29. public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
  30. LexicalUnitImpl rightValue) {
  31. return leftValue.minus(rightValue);
  32. }
  33. },
  34. MUL(LexicalUnit.SAC_OPERATOR_MULTIPLY, 2) {
  35. @Override
  36. public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
  37. LexicalUnitImpl rightValue) {
  38. return leftValue.multiply(rightValue);
  39. }
  40. },
  41. DIV(LexicalUnit.SAC_OPERATOR_SLASH, 2) {
  42. @Override
  43. public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
  44. LexicalUnitImpl rightValue) {
  45. return leftValue.divide(rightValue);
  46. }
  47. },
  48. MOD(LexicalUnit.SAC_OPERATOR_MOD, 2) {
  49. @Override
  50. public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
  51. LexicalUnitImpl rightValue) {
  52. return leftValue.modulo(rightValue);
  53. }
  54. };
  55. public final short type;
  56. public final int precedence;
  57. BinaryOperator(short type, int precedence) {
  58. this.type = type;
  59. this.precedence = precedence;
  60. }
  61. public abstract LexicalUnitImpl eval(LexicalUnitImpl leftValue,
  62. LexicalUnitImpl rightValue);
  63. }