Skip to content

Commit 94c4886

Browse files
author
Brenton Bostick
committed
Integer literals prefixed with - are also integer literals
1 parent c8c1619 commit 94c4886

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

CodeFormatter/Kernel/Indent.wl

+4-1
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ a::b
897897
898898
no spaces around Power:
899899
a^b
900+
10^-9
900901
901902
*)
902903
indentInfixRatorSurroundedByLeafs[Pattern | Optional | PatternTest | MessageName | Power][rator_] :=
@@ -1018,6 +1019,8 @@ $SpecialChained = {
10181019
}
10191020

10201021

1022+
integerPat = LeafNode[Integer, _, _] | PrefixNode[Minus, {_, LeafNode[Integer, _, _]}, _]
1023+
10211024
(*
10221025
10231026
This is the big function for all BinaryNodes, InfixNodes, and TernaryNodes
@@ -1045,7 +1048,7 @@ Module[{aggs, rators, ratorsPat, split,
10451048
];
10461049

10471050
Which[
1048-
MatchQ[type, BinaryNode | InfixNode] && MatchQ[graphs, {LeafNode[Integer, _, _], _LeafNode, LeafNode[Integer, _, _]}],
1051+
MatchQ[type, BinaryNode | InfixNode] && MatchQ[graphs, {integerPat, _LeafNode, integerPat}],
10491052
infixRatorSurroundedBy = Integers;
10501053
,
10511054
MatchQ[type, BinaryNode | InfixNode] && MatchQ[graphs, {_LeafNode, _LeafNode, _LeafNode}],

Tests/CodeFormatter.mt

+26
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,32 @@ Test[
380380
]
381381

382382

383+
Test[
384+
CodeFormat["1/-0"]
385+
,
386+
"1/-0"
387+
,
388+
TestID->"CodeFormatter-20221018-Q2X8M9"
389+
]
390+
391+
Test[
392+
CodeFormat["10^9"]
393+
,
394+
"10^9"
395+
,
396+
TestID->"CodeFormatter-20221018-Z7H7W5"
397+
]
398+
399+
Test[
400+
CodeFormat["10^-9"]
401+
,
402+
"10^-9"
403+
,
404+
TestID->"CodeFormatter-20221018-B5K0S1"
405+
]
406+
407+
408+
383409
Test[
384410
CodeFormat["Test[1/0, ComplexInfinity, {Power::infy}, TestID->\"test\"]"]
385411
,

0 commit comments

Comments
 (0)