Skip to content

Commit bf67a47

Browse files
Adds correct parsing of NSSpace in equation constraints (#13)
1 parent 39dbcb9 commit bf67a47

File tree

3 files changed

+206
-2
lines changed

3 files changed

+206
-2
lines changed

Sources/App/Parsing/ConstraintsParser+EquationConstraint.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension ConstraintsParser {
88

99
static let equationConstraint = layoutItemAttribute.thenSkip(wss).then(relation)
1010
.thenSkip(wss).then(preMultiplier).then(optional(layoutItemAttribute))
11-
.thenSkip(wss).then(postMultiplier).then(constant).then(optionalInfo)
11+
.thenSkip(wss).then(postMultiplier).then(anyConstant).then(optionalInfo)
1212
.map {
1313
try AnonymousConstraint(
1414
first: $0.0.0.0.0.0,
@@ -24,7 +24,9 @@ extension ConstraintsParser {
2424
private extension ConstraintsParser {
2525

2626
static let layoutItemAttribute = partialInstance.then(dotAttribute)
27+
static let anyConstant = nsSpaceConstant.otherwise(constant)
2728
static let constant = number.map(Constant.init).otherwise(pure(Constant()))
29+
static let nsSpaceConstant = unbracketedNSSpace.map { Constant($0.1) }
2830
static let preMultiplier = optional(number.thenSkip(string("*")).map(Multiplier.init))
2931
.named("prefixed multiplier")
3032
static let postMultiplier = optional(string("*").skipThen(wss).skipThen(number).map(Multiplier.init))

Sources/App/Parsing/ConstraintsParser+VFLConstraint.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ extension ConstraintsParser {
1313
.map(flatten).map(AnonymousConstraint.init)
1414

1515
static let vflConstraint = vflExtentConstraint.otherwise(vflSpaceConstraint)
16+
17+
static let unbracketedNSSpace = string("NSSpace")
18+
.otherwise(string("NSLayoutAnchorConstraintSpace"))
19+
.skipThen(vflExtent)
20+
21+
static let nsSpacer = character("(").skipThen(unbracketedNSSpace).thenSkip(character(")"))
1622
}
1723

1824
// MARK: - Private
@@ -30,6 +36,5 @@ private extension ConstraintsParser {
3036
static let vflEntity = instance.map({ PartialInstance.instance($0) }).otherwise(vflIdentifier.map({ PartialInstance.identifier($0) }))
3137
static let vflBoundedEntity = character("[").skipThen(vflEntity).thenSkip(character("]")).otherwise(string("|").map({ _ in PartialInstance.superview }))
3238
static let vflDirection = optional(string("(LTR)").otherwise(string("(RTL)")))
33-
static let nsSpacer = character("(").skipThen(string("NSSpace").otherwise(string("NSLayoutAnchorConstraintSpace"))).skipThen(vflExtent).thenSkip(character(")"))
3439
static let spacer = vflExtent.otherwise(nsSpacer)
3540
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
{
2+
"constraints" : [
3+
{
4+
"constant" : {
5+
"value" : "86"
6+
},
7+
"description" : "<code style=\"box-shadow: 0px -1px 0px #16A085 inset; padding-bottom: 1px;\">View<\/code>'s height should equal 86.",
8+
"first" : {
9+
"attribute" : {
10+
"includesMargin" : false,
11+
"name" : "height"
12+
},
13+
"instance" : {
14+
"address" : "0x10f754f20",
15+
"className" : "UIView",
16+
"color" : "rgb(22,160,133)",
17+
"initial" : "V",
18+
"name" : "View",
19+
"suffix" : ""
20+
}
21+
},
22+
"footnote" : {
23+
"marker" : "*",
24+
"text" : "This constraint was translated from an autoresizing mask. If this was not intended, try setting <code>translatesAutoresizingMaskIntoConstraints<\/code> to false on this view."
25+
},
26+
"identity" : {
27+
"address" : "0x283c8f570",
28+
"className" : "NSAutoresizingMaskLayoutConstraint",
29+
"color" : "rgb(26,188,156)",
30+
"initial" : "N",
31+
"name" : "NSAutoresizingMaskLayoutConstraint"
32+
},
33+
"relation" : "=="
34+
},
35+
{
36+
"description" : "<code style=\"box-shadow: 0px -1px 0px #2980B9 inset; padding-bottom: 1px;\">Cancel<\/code>'s top edge should equal <code style=\"box-shadow: 0px -1px 0px #16A085 inset; padding-bottom: 1px;\">View<\/code>'s top edge.",
37+
"first" : {
38+
"attribute" : {
39+
"includesMargin" : false,
40+
"name" : "top"
41+
},
42+
"instance" : {
43+
"address" : "0x10f755100",
44+
"className" : "UIButton",
45+
"color" : "rgb(41,128,185)",
46+
"identifier" : "Cancel",
47+
"initial" : "C",
48+
"name" : "Cancel",
49+
"suffix" : ""
50+
}
51+
},
52+
"identity" : {
53+
"address" : "0x283c8c820",
54+
"className" : "NSLayoutConstraint",
55+
"color" : "rgb(26,188,156)",
56+
"initial" : "N",
57+
"name" : "NSLayoutConstraint"
58+
},
59+
"relation" : "==",
60+
"second" : {
61+
"attribute" : {
62+
"includesMargin" : false,
63+
"name" : "top"
64+
},
65+
"instance" : {
66+
"address" : "0x10f754f20",
67+
"className" : "UIView",
68+
"color" : "rgb(22,160,133)",
69+
"initial" : "V",
70+
"name" : "View",
71+
"suffix" : ""
72+
}
73+
}
74+
},
75+
{
76+
"constant" : {
77+
"value" : "52"
78+
},
79+
"description" : "<code style=\"box-shadow: 0px -1px 0px #2980B9 inset; padding-bottom: 1px;\">Cancel<\/code>'s height should equal 52.",
80+
"first" : {
81+
"attribute" : {
82+
"includesMargin" : false,
83+
"name" : "height"
84+
},
85+
"instance" : {
86+
"address" : "0x10f755100",
87+
"className" : "UIButton",
88+
"color" : "rgb(41,128,185)",
89+
"identifier" : "Cancel",
90+
"initial" : "C",
91+
"name" : "Cancel",
92+
"suffix" : ""
93+
}
94+
},
95+
"identity" : {
96+
"address" : "0x283c8c870",
97+
"className" : "NSLayoutConstraint",
98+
"color" : "rgb(26,188,156)",
99+
"initial" : "N",
100+
"name" : "NSLayoutConstraint"
101+
},
102+
"relation" : "=="
103+
},
104+
{
105+
"description" : "<code style=\"box-shadow: 0px -1px 0px #F39C12 inset; padding-bottom: 1px;\">UIViewLayoutMarginsGuide<\/code>'s bottom edge should equal <code style=\"box-shadow: 0px -1px 0px #2980B9 inset; padding-bottom: 1px;\">Cancel<\/code>'s bottom edge.",
106+
"first" : {
107+
"attribute" : {
108+
"includesMargin" : false,
109+
"name" : "bottom"
110+
},
111+
"instance" : {
112+
"address" : "0x2826f9880",
113+
"className" : "UILayoutGuide",
114+
"color" : "rgb(243,156,18)",
115+
"identifier" : "UIViewLayoutMarginsGuide",
116+
"initial" : "U",
117+
"name" : "UIViewLayoutMarginsGuide",
118+
"suffix" : ""
119+
}
120+
},
121+
"identity" : {
122+
"address" : "0x283c8c8c0",
123+
"className" : "NSLayoutConstraint",
124+
"color" : "rgb(26,188,156)",
125+
"initial" : "N",
126+
"name" : "NSLayoutConstraint"
127+
},
128+
"relation" : "==",
129+
"second" : {
130+
"attribute" : {
131+
"includesMargin" : false,
132+
"name" : "bottom"
133+
},
134+
"instance" : {
135+
"address" : "0x10f755100",
136+
"className" : "UIButton",
137+
"color" : "rgb(41,128,185)",
138+
"identifier" : "Cancel",
139+
"initial" : "C",
140+
"name" : "Cancel",
141+
"suffix" : ""
142+
}
143+
}
144+
},
145+
{
146+
"constant" : {
147+
"prefix" : "+ ",
148+
"value" : "42"
149+
},
150+
"description" : "<code style=\"box-shadow: 0px -1px 0px #16A085 inset; padding-bottom: 1px;\">View<\/code>'s bottom edge should equal <code style=\"box-shadow: 0px -1px 0px #F39C12 inset; padding-bottom: 1px;\">UIViewLayoutMarginsGuide<\/code>'s bottom edge plus 42.",
151+
"first" : {
152+
"attribute" : {
153+
"includesMargin" : false,
154+
"name" : "bottom"
155+
},
156+
"instance" : {
157+
"address" : "0x10f754f20",
158+
"className" : "UIView",
159+
"color" : "rgb(22,160,133)",
160+
"initial" : "V",
161+
"name" : "View",
162+
"suffix" : ""
163+
}
164+
},
165+
"identity" : {
166+
"address" : "0x283c8c730",
167+
"className" : "NSLayoutConstraint",
168+
"color" : "rgb(26,188,156)",
169+
"identifier" : "UIView-bottomMargin-guide-constraint",
170+
"initial" : "U",
171+
"name" : "UIView-bottomMargin-guide-constraint"
172+
},
173+
"relation" : "==",
174+
"second" : {
175+
"attribute" : {
176+
"includesMargin" : false,
177+
"name" : "bottom"
178+
},
179+
"instance" : {
180+
"address" : "0x2826f9880",
181+
"className" : "UILayoutGuide",
182+
"color" : "rgb(243,156,18)",
183+
"identifier" : "UIViewLayoutMarginsGuide",
184+
"initial" : "U",
185+
"name" : "UIViewLayoutMarginsGuide",
186+
"suffix" : ""
187+
}
188+
}
189+
}
190+
],
191+
"footnotes" : [
192+
{
193+
"marker" : "*",
194+
"text" : "This constraint was translated from an autoresizing mask. If this was not intended, try setting <code>translatesAutoresizingMaskIntoConstraints<\/code> to false on this view."
195+
}
196+
]
197+
}

0 commit comments

Comments
 (0)