1919
2020public enum SymbolInfo {
2121 // Let's say that precedence 0 is for (parens) OR literals - TODO add a class?? but it wouldn't actually be used !
22- POW (PowOperation .class , 1 , GroupingDirection .RightToLeft , "**" , PowOperation ::new ),
23- MUL (MulOperation .class , 2 , GroupingDirection .LeftToRight , "*" , MulOperation ::new ),
24- DIV (DivOperation .class , 2 , GroupingDirection .LeftToRight , "/" , DivOperation ::new ),
22+ POW (PowOperation .class , 1 , GroupingDirection .RightToLeft , "**" , "" , PowOperation ::new ),
2523
26- ADD (AddOperation .class , 3 , GroupingDirection .LeftToRight , "+" , AddOperation ::new ),
27- SUB (SubOperation .class , 3 , GroupingDirection .LeftToRight , "-" , SubOperation ::new ),
24+ MUL (MulOperation .class , 2 , GroupingDirection .LeftToRight , "*" , " " , MulOperation ::new ),
25+ DIV (DivOperation .class , 2 , GroupingDirection .LeftToRight , "/" , " " , DivOperation ::new ),
26+
27+ ADD (AddOperation .class , 3 , GroupingDirection .LeftToRight , "+" , " " , AddOperation ::new ),
28+ SUB (SubOperation .class , 3 , GroupingDirection .LeftToRight , "-" , " " , SubOperation ::new ),
2829 ;
2930
3031 public static final Map <Class <? extends MathSymbol >, SymbolInfo > CLS_TO_INFO_MAP ;
@@ -37,22 +38,25 @@ public enum SymbolInfo {
3738 public final Class <? extends MathSymbol > cls ;
3839 public final GroupingDirection groupingDirection ;
3940 public final String infix ;
41+ public final @ Nullable String spacesAroundInfix ;
4042
4143 @ SuppressWarnings ("unused" ) // useful later
4244 SymbolInfo (Class <? extends MathSymbol > cls , int precedence ,
43- GroupingDirection groupingDirection , @ Nullable String infix ) {
45+ GroupingDirection groupingDirection , @ Nullable String spacesAroundInfix , @ Nullable String infix ) {
4446 this .precedence = precedence ;
45- this .cls = cls ; // TODO: private + getters?
47+ this .cls = cls ;
4648 this .groupingDirection = groupingDirection ;
4749 this .infix = infix ;
50+ this .spacesAroundInfix = spacesAroundInfix ;
4851 }
4952 SymbolInfo (Class <? extends BinaryOperationLeftRight > cls , int precedence ,
50- GroupingDirection groupingDirection , @ Nullable String infix ,
53+ GroupingDirection groupingDirection , @ Nullable String infix , @ Nullable String spacesAroundInfix ,
5154 BinOpBiConstructor biConstructor ) {
5255 this .precedence = precedence ;
5356 this .cls = cls ; // TODO: private + getters?
5457 this .groupingDirection = groupingDirection ;
5558 this .infix = infix ;
59+ this .spacesAroundInfix = spacesAroundInfix ;
5660 this .biConstructorCache = biConstructor ;
5761 }
5862
@@ -70,6 +74,9 @@ public enum SymbolInfo {
7074 public static @ Nullable String infixFromClass (Class <? extends MathSymbol > cls ) {
7175 return Util .chainNulls (fromClass (cls ), x -> x .infix );
7276 }
77+ public static @ Nullable String spacesAroundInfixFromClass (Class <? extends MathSymbol > cls ) {
78+ return Util .chainNulls (fromClass (cls ), s -> s .spacesAroundInfix );
79+ }
7380
7481 private BinOpBiConstructor biConstructorCache = null ;
7582 public @ NotNull BinOpBiConstructor getBiConstructor () {
0 commit comments