import ceylon.ast.core {
    ExistsNonemptyExpression,
    SmallerOperation
}
import com.redhat.ceylon.compiler.typechecker.tree {
    Tree {
        JSmallerOp=SmallerOp
    }
}

"Converts a RedHat AST [[SmallerOp|JSmallerOp]] to a `ceylon.ast` [[SmallerOperation]]."
shared SmallerOperation smallerOperationToCeylon(JSmallerOp smallerOperation) {
    "Check precedence"
    assert (is ExistsNonemptyExpression left = expressionToCeylon(smallerOperation.leftTerm),
        is ExistsNonemptyExpression right = expressionToCeylon(smallerOperation.rightTerm));
    return SmallerOperation(left, right);
}

"Compiles the given [[code]] for a Smaller Operation
 into a [[SmallerOperation]] using the Ceylon compiler
 (more specifically, the rule for a `comparisonExpression`)."
shared SmallerOperation? compileSmallerOperation(String code) {
    if (is JSmallerOp jComparisonExpression = createParser(code).comparisonExpression()) {
        return smallerOperationToCeylon(jComparisonExpression);
    } else {
        return null;
    }
}