git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #978 from mrhania/flexible-row-syntax

Flexible row syntax

commit005eed5f4774f7562aee3efcdcf3ca655738f6ed authorPhil Freeman <paf31@cantab.net> dateWed 18 Mar 2015, 15:08 (12 years ago) parent4b0c53afc2cd01
5 files changed+59−3
examples/failing/RowConstructors1.purs+6 examples/failing/RowConstructors2.purs+6 examples/failing/RowConstructors3.purs+6 examples/passing/RowConstructors.purs+40 src/Language/PureScript/Parser/Types.hs+1−3
examples/failing/RowConstructors1.pursnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+data Foo = Bar
4+type Baz = { | Foo }
5+
6+main = Debug.Trace.trace "Done"
examples/failing/RowConstructors2.pursnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+type Foo r = (x :: Number | r)
4+type Bar = { | Foo }
5+
6+main = Debug.Trace.trace "Done"
examples/failing/RowConstructors3.pursnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+type Foo = { x :: Number }
4+type Bar = { | Foo }
5+
6+main = Debug.Trace.trace "Done"
examples/passing/RowConstructors.pursnew file+40
@@ -0,0 +1,40 @@
1+module Main where
2+
3+type Foo = (x :: Number | (y :: Number | (z :: Number)))
4+type Bar = (x :: Number, y :: Number, z :: Number)
5+type Baz = { w :: Number | Bar }
6+
7+foo :: { | Foo }
8+foo = { x: 0, y: 0, z: 0 }
9+
10+bar :: { | Bar }
11+bar = { x: 0, y: 0, z: 0 }
12+
13+id' :: Object Foo -> Object Bar
14+id' = id
15+
16+foo' :: { | Foo }
17+foo' = id' foo
18+
19+bar' :: { | Bar }
20+bar' = id' bar
21+
22+baz :: Baz
23+baz = { x: 0, y: 0, z: 0, w: 0 }
24+
25+type Quux r = (q :: Number | r)
26+type Norf r = (q' :: Number | Quux r)
27+
28+quux :: { f :: { | Foo } | Quux Bar }
29+quux = { f: foo', x: 0, y: 0, z: 0, q: 0 }
30+
31+quux' :: { | Norf Bar }
32+quux' = { x: 0, y: 0, z: 0, q: 0, q': 0 }
33+
34+wildcard :: { w :: Number | _ } -> Baz
35+wildcard { w: w } = { x: w, y: w, z: w, w: w }
36+
37+wildcard' :: { | Quux _ } -> Number
38+wildcard' { q: q } = q
39+
40+main = Debug.Trace.trace "Done"
src/Language/PureScript/Parser/Types.hs+1−3
@@ -126,9 +126,7 @@ parseNameAndType :: TokenParser t -> TokenParser (String, t)
126126parseNameAndType p = (,) <$> (indented *> (lname <|> stringLiteral) <* indented <* doubleColon) <*> p
127127
128128parseRowEnding :: TokenParser Type
129−parseRowEnding = P.option REmpty $ indented *> pipe *> indented *> P.choice (map P.try
130− [ parseTypeWildcard
131− , TypeVar <$> identifier ])
129+parseRowEnding = P.option REmpty $ indented *> pipe *> indented *> parseType
132130
133131parseRow :: TokenParser Type
134132parseRow = (curry rowFromList <$> commaSep (parseNameAndType parsePolyType) <*> parseRowEnding) P.<?> "row"