on master help sign in
Fill in the remaining DeclDef syntax messages
6c98f99Evan Czaplicki
compiler/src/Parse/Declaration.hs+1−1
@@ -80,7 +80,7 @@ valueDecl maybeDocs start =
80 do word1 0x3A {-:-} E.DeclDefEquals
80 do word1 0x3A {-:-} E.DeclDefEquals
81 Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentType
81 Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentType
82 (tipe, _) <- specialize E.DeclDefType Type.expression
82 (tipe, _) <- specialize E.DeclDefType Type.expression
83− Space.checkFreshLine E.DeclDefFreshLineAfterType
83+ Space.checkFreshLine E.DeclDefNameRepeat
84 defName <- chompMatchingName name
84 defName <- chompMatchingName name
85 Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentEquals
85 Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentEquals
86 chompDefArgsAndBody maybeDocs start defName (Just tipe) []
86 chompDefArgsAndBody maybeDocs start defName (Just tipe) []
compiler/src/Reporting/Error/Syntax.hs+71−10
@@ -157,8 +157,6 @@ data DeclDef
157 | DeclDefIndentType Row Col
157 | DeclDefIndentType Row Col
158 | DeclDefIndentEquals Row Col
158 | DeclDefIndentEquals Row Col
159 | DeclDefIndentBody Row Col
159 | DeclDefIndentBody Row Col
160− --
161− | DeclDefFreshLineAfterType Row Col
162
160
163
161
164data Port
162data Port
@@ -1516,9 +1514,12 @@ toDeclDefReport source name declDef startRow startCol =
1516 "I just saw the type annotation for `" ++ Name.toChars name
1514 "I just saw the type annotation for `" ++ Name.toChars name
1517 ++ "` so I was expecting to see its definition here:"
1515 ++ "` so I was expecting to see its definition here:"
1518 ,
1516 ,
1517+ D.stack
1519− D.reflow $
1518+ [ D.reflow $
1520− "Type annotations always appear directly above the relevant\
1519+ "Type annotations always appear directly above the relevant\
1521− \ definition, without anything else (even doc comments) in between."
1520+ \ definition, without anything else (even doc comments) in between."
1521+ , declDefNote
1522+ ]
1522 )
1523 )
1523
1524
1524 DeclDefNameMatch defName row col ->
1525 DeclDefNameMatch defName row col ->
@@ -1541,16 +1542,76 @@ toDeclDefReport source name declDef startRow startCol =
1541 )
1542 )
1542
1543
1543 DeclDefIndentType row col ->
1544 DeclDefIndentType row col ->
1544− error "TODO DeclDefIndentType" row col
1545+ let
1546+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1547+ region = toRegion row col
1548+ in
1549+ Report.Report "UNFINISHED DEFINITION" region [] $
1550+ Code.toSnippet source surroundings (Just region)
1551+ (
1552+ D.reflow $
1553+ "I got stuck while parsing the `" ++ Name.toChars name ++ "` type annotation:"
1554+ ,
1555+ D.stack
1556+ [ D.reflow $
1557+ "I just saw a colon, so I am expecting to see a type next."
1558+ , declDefNote
1559+ ]
1560+ )
1545
1561
1546 DeclDefIndentEquals row col ->
1562 DeclDefIndentEquals row col ->
1547− error "TODO DeclDefIndentEquals" row col
1563+ let
1564+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1565+ region = toRegion row col
1566+ in
1567+ Report.Report "UNFINISHED DEFINITION" region [] $
1568+ Code.toSnippet source surroundings (Just region)
1569+ (
1570+ D.reflow $
1571+ "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
1572+ ,
1573+ D.stack
1574+ [ D.reflow $
1575+ "I was expecting to see an argument or an equals sign next."
1576+ , declDefNote
1577+ ]
1578+ )
1548
1579
1549 DeclDefIndentBody row col ->
1580 DeclDefIndentBody row col ->
1550− error "TODO DeclDefIndentBody" row col
1581+ let
1582+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1583+ region = toRegion row col
1584+ in
1585+ Report.Report "UNFINISHED DEFINITION" region [] $
1586+ Code.toSnippet source surroundings (Just region)
1587+ (
1588+ D.reflow $
1589+ "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
1590+ ,
1591+ D.stack
1592+ [ D.reflow $
1593+ "I was expecting to see an expression next. What is it equal to?"
1594+ , declDefNote
1595+ ]
1596+ )
1551
1597
1552− DeclDefFreshLineAfterType row col ->
1598+
1553− error "TODO DeclDefFreshLineAfterType" row col
1599+declDefNote :: D.Doc
1600+declDefNote =
1601+ D.stack
1602+ [ D.reflow $
1603+ "Here is a valid definition (with a type annotation) for reference:"
1604+ , D.vcat
1605+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1606+ , D.fillSep [D.green "add","x","y","="]
1607+ , D.fillSep [" ","x","+","y"]
1608+ ]
1609+ , D.reflow $
1610+ "The top line (called a \"type annotation\") is optional. You can leave it off\
1611+ \ if you want. As you get more comfortable with Elm and as your project grows,\
1612+ \ it becomes more and more valuable to add them though! They work great as\
1613+ \ compiler-verified documentation, and they often improve error messages!"
1614+ ]
1554
1615
1555
1616
1556
1617