Class ExpressionPrinter

java.lang.Object
org.cyclops.integrateddynamics.core.evaluate.expression.tree.ExpressionPrinter

public final class ExpressionPrinter extends Object
Pretty-prints expression trees, such as item => item.size() > 3. Operators are named, and written as methods, as described in OperatorNames. Choices are printed as c ? a : b, operator values as (+) or (reduce).
  • Field Details

  • Method Details

    • print

      public static String print(Expression expression, IntFunction<String> labels, IntFunction<IValueType<?>> refTypes)
      Parameters:
      expression - An expression.
      labels - Resolves the label of a variable id, may return null.
      refTypes - Resolves the type of a variable id, may return null when unknown.
      Returns:
      The pretty-printed expression.
    • print

      public static String print(Expression expression, IntFunction<String> labels)
      Parameters:
      expression - An expression.
      labels - Resolves the label of a variable id, may return null.
      Returns:
      The pretty-printed expression, without known reference types.
    • print

      public static String print(Expression expression)
      Parameters:
      expression - An expression.
      Returns:
      The pretty-printed expression without labels.
    • printExact

      public static String printExact(Expression expression, ValueDeseralizationContext values, IntFunction<String> labels, Function<String, it.unimi.dsi.fastutil.ints.IntList> labelIds, IntFunction<IValueType<?>> refTypes)
      Print the given expression in the text form that ExpressionParser reads back into the same expression. In contrast to print(Expression, IntFunction, IntFunction), values are not shortened, parameters are written with their types, and references only use a label if that label leads back to them.
      Parameters:
      expression - An expression.
      values - For serializing values that are written with their type, such as items.
      labels - Resolves the label of a variable id, may return null.
      labelIds - Resolves the ids of the variables with a label.
      refTypes - Resolves the type of a variable id, may return null when unknown.
      Returns:
      The text.
    • tokenizeExact

      public static List<ExpressionPrinter.Token> tokenizeExact(Expression expression, ValueDeseralizationContext values, IntFunction<String> labels, Function<String, it.unimi.dsi.fastutil.ints.IntList> labelIds, ExpressionTypeChecker.Result types)
      The text of printExact(Expression, ValueDeseralizationContext, IntFunction, Function, IntFunction) as tokens, which tell what node each part of the text belongs to.
      Parameters:
      expression - An expression.
      values - For serializing values that are written with their type, such as items.
      labels - Resolves the label of a variable id, may return null.
      labelIds - Resolves the ids of the variables with a label.
      types - The type checking result of the expression.
      Returns:
      The tokens.
    • printLiteral

      public static String printLiteral(IValue value, ValueDeseralizationContext values)
      Parameters:
      value - A value.
      values - For serializing values that are written with their type.
      Returns:
      The value in the text form, which ExpressionParser reads back into the same value.
    • quote

      public static String quote(String text)
      Parameters:
      text - A text.
      Returns:
      The text between quotes, with quotes, backslashes and characters that pasting drops escaped.
    • printNode

      public static String printNode(Expression expression, int[] path, IntFunction<String> labels, ExpressionTypeChecker.Result types)
      Parameters:
      expression - The expression that contains the node.
      path - The path of a node.
      labels - Resolves the label of a variable id, may return null.
      types - The type checking result of the expression.
      Returns:
      The pretty-printed node, without the parameter list.
    • tokenize

      public static List<ExpressionPrinter.Token> tokenize(Expression expression, IntFunction<String> labels, ExpressionTypeChecker.Result types)
      Pretty-print the given expression as a list of tokens.
      Parameters:
      expression - An expression.
      labels - Resolves the label of a variable id, may return null.
      types - The type checking result of the expression.
      Returns:
      The tokens.
    • printValue

      public static String printValue(IValue value)
      Parameters:
      value - A value.
      Returns:
      A short string representation.
    • printOperatorValue

      public static String printOperatorValue(IOperator operator)
      Parameters:
      operator - An operator that is used as a value.
      Returns:
      Its name, as in map(length, l), or its symbol in brackets, as in (+).
    • printRef

      public static String printRef(int variableId, @Nullable String label)
      Parameters:
      variableId - A variable id.
      label - A label or null.
      Returns:
      The display string of a reference.