Class TermFormatter


  • public class TermFormatter
    extends java.lang.Object
    Produces String representations of Term instances.

    Does take account of operator precedence.

    See Also:
    formatTerm(Term)
    • Field Detail

      • operands

        private final Operands operands
    • Constructor Detail

      • TermFormatter

        public TermFormatter​(Operands operands)
    • Method Detail

      • formatTerm

        public java.lang.String formatTerm​(Term t)
        Returns a string representation of the specified Term.

        This method does take account of current operator declarations - thus an infix operator will be printed out between its arguments. This method represents lists as a comma separated sequence of elements enclosed in square brackets.

        For example:

         Term structure = Structure.createStructure("+", new IntegerNumber(1), new IntegerNumber(2));
         Term list = ListFactory.create(new Term[]{new Atom("a"), Atom("b"), Atom("c")});
         System.out.println("Structure.toString():      "+structure.toString());
         System.out.println("Write.toString(structure): "+write.toString(structure));
         System.out.println("List.toString():           "+list.toString());
         System.out.println("Write.toString(list):      "+write.toString(list));
         
        would print out:
         Structure.toString():      +(1, 2)
         Write.toString(structure): 1 + 2
         List.toString():           .(a, .(b, .(c, [])))
         Write.toString(list):      [a,b,c]
         
        Parameters:
        t - the Term to represent as a string
        Returns:
        a string representation of the specified Term
      • write

        private void write​(Term t,
                           java.lang.StringBuilder sb)
      • writeList

        private void writeList​(Term p,
                               java.lang.StringBuilder sb)
      • getList

        private static Term getList​(Term t)
      • writePredicate

        private void writePredicate​(Term p,
                                    java.lang.StringBuilder sb)
      • isInfixOperator

        private boolean isInfixOperator​(Term t)
      • writeInfixOperator

        private void writeInfixOperator​(Term p,
                                        java.lang.StringBuilder sb)
      • shouldLeftArgumentBeBracketed

        private boolean shouldLeftArgumentBeBracketed​(Term next,
                                                      Term parentInfixTerm,
                                                      int parentInfixPriority)
      • shouldRightArgumentBeBracketed

        private boolean shouldRightArgumentBeBracketed​(Term next,
                                                       Term parentInfixTerm,
                                                       int parentInfixPriority)
      • isPrefixOperator

        private boolean isPrefixOperator​(Term t)
      • writePrefixOperator

        private void writePrefixOperator​(Term p,
                                         java.lang.StringBuilder sb)
      • isPostfixOperator

        private boolean isPostfixOperator​(Term t)
      • writePostfixOperator

        private void writePostfixOperator​(Term p,
                                          java.lang.StringBuilder sb)
      • canBePreceededByEqualPriority

        private boolean canBePreceededByEqualPriority​(Term next)
      • getPriority

        private int getPriority​(Term next)
      • writeNonOperatorPredicate

        private void writeNonOperatorPredicate​(Term p,
                                               java.lang.StringBuilder sb)