Package eu.bandm.tools.format
Class Prior
java.lang.Object
eu.bandm.tools.format.Format
eu.bandm.tools.format.Prior
- All Implemented Interfaces:
Formattable,Serializable,Cloneable
This format is rendered differently, according to its
relative positions to ancestor formats of this class.
It prints it
parens format, if it is (directly or indirectly)
contained in a Prior Format with a higher priority level
(which is a numerically larger priority code).
If not, but contained in a format with the same priority.
a different value of alternative between these formats
also selects the parens format.
So does a negative alternative value.
Otherwise the noparens format is printed.
So one can automatically diferentiate between
a+b*c+d for the expression tree +(a, *(b, c), d)
(a+b)*c*d *(+(a, b), c, d)
a+(b-c)+d +(a, -(b, c), d)
a-(b+c+d) -(a, +(b, c, d))
The priority of the outermost level, when initially calling
FormatPrinter.startPrinting(Format), is set to zero.
In contrast to most other format classes, the preparatory calculations of the format's width requirements are only heuristical and use the respective maximum values, because the final print context is (naturally) not known.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intThe paren version will be printed if this format is contained (maybe indirectly) in another Prior with same priority and different alternative, or if this alternative == -1.final intThe paren version will be printed if this format is contained (maybe indirectly) in another Prior with higher priority.final FormatFormat not framed with parentheses.final FormatFormat framed with parentheses.Fields inherited from class eu.bandm.tools.format.Format
comma, DEFAULT_WIDTH, dot, empty, indent, INDENT_NOT_SET, LENGTH_PREFIX, space -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSets fields of the new instance, but the indentation toFormat.INDENT_NOT_SET.protectedA constructor with some field values explicit, some calculated from the subformats. -
Method Summary
Modifier and TypeMethodDescriptiondebugPrefix(int n) Deliver the concatenation of the text contents, limited by the given number of characters, approximately.protected voidOver-ridden by all sub-classes of Format, for performing the print operations.Return the result of replacing all variables with the bindings in the given context.indent(int i) Returns a clone ofthiswith the new value ofFormat.indent.Methods inherited from class eu.bandm.tools.format.Format
annotated, append, append, apply, apply, apply, apply, applyPartial, applyTo, applyTo, beneath, beneath, beside, beside, block, block, checkValidIndent, comment, comment, comment, comment, format, getIndent, ground, indentIsSet, isAlwaysMultiline, isSpace, line, line, literal, markup, markupLeft, markupRight, maxOfMins, maxWidth, minWidth, of, printFormat, printFormat, printNonFormat, prior, prior, properties, server, showLn, space, subst, subst, subst, tabular, tabular, toObjString, toString, toString, variable, variable
-
Field Details
-
level
public final int levelThe paren version will be printed if this format is contained (maybe indirectly) in another Prior with higher priority. -
alternative
public final int alternativeThe paren version will be printed if this format is contained (maybe indirectly) in another Prior with same priority and different alternative, or if this alternative == -1. -
noparens
Format not framed with parentheses. -
parens
Format framed with parentheses.
-
-
Constructor Details
-
Prior
A constructor with some field values explicit, some calculated from the subformats.- Parameters:
level- the binding power of the format: higher numerical value means higher binding power.alternative- numeric identifier to distinguish between non-equal operators with the same binding power.noparens- the format to print when the priority situation does not require parenthesesparens- the format to print when the priority situation requires parenthesesindent- the indentation value- Throws:
IllegalArgumentException- if ident value not valid, seeFormat.checkValidIndent(int)
-
Prior
Sets fields of the new instance, but the indentation toFormat.INDENT_NOT_SET.- Parameters:
level- the binding power of the format: higher numerical value means higher binding power.alternative- numeric identifier to distinguish between non-equal operators with the same binding power.noparens- the format to print when the priority situation does not require parenthesesparens- the format to print when the priority situation requires parentheses
-
-
Method Details
-
debugPrefix
Description copied from class:FormatDeliver the concatenation of the text contents, limited by the given number of characters, approximately. Useful for debugging purpose.- Specified by:
debugPrefixin classFormat- Parameters:
n- the maximal number of characters which can be generated per tree node.- Returns:
- the concatenated, unformatted text contents.
-
doprint
Description copied from class:FormatOver-ridden by all sub-classes of Format, for performing the print operations. -
indent
Description copied from class:FormatReturns a clone ofthiswith the new value ofFormat.indent. -
eval
Description copied from class:FormatReturn the result of replacing all variables with the bindings in the given context.- Overrides:
evalin classFormat- Parameters:
c- defines the replacement for variables by name and number.partial- decides when a Variable not defined in the context is found: if true the Variable stays aunaltered; if false an IllegalArgumentException is thrown.- Returns:
- a format with all or some variables replaced
-