on master help sign in
Fill in the remaining DeclDef syntax messages
commit6c98f9923121fe08a9f5b5f48333a20d79d22fb6 authorEvan Czaplicki <evancz@users.noreply.github.com> dateFri 17 May 2019, 15:21 (7 years ago) parent4d4225d
2 files changed+72−11
compiler/src/Parse/Declaration.hs+1−1 compiler/src/Reporting/Error/Syntax.hs+71−10
compiler/src/Parse/Declaration.hs+1−1
@@ -80,7 +80,7 @@ valueDecl maybeDocs start =
8080 do word1 0x3A {-:-} E.DeclDefEquals
8181 Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentType
8282 (tipe, _) <- specialize E.DeclDefType Type.expression
83− Space.checkFreshLine E.DeclDefFreshLineAfterType
83+ Space.checkFreshLine E.DeclDefNameRepeat
8484 defName <- chompMatchingName name
8585 Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentEquals
8686 chompDefArgsAndBody maybeDocs start defName (Just tipe) []
compiler/src/Reporting/Error/Syntax.hs+71−10
@@ -157,8 +157,6 @@ data DeclDef
157157 | DeclDefIndentType Row Col
158158 | DeclDefIndentEquals Row Col
159159 | DeclDefIndentBody Row Col
160− --
161− | DeclDefFreshLineAfterType Row Col
162160
163161
164162data Port
@@ -1516,9 +1514,12 @@ toDeclDefReport source name declDef startRow startCol =
15161514 "I just saw the type annotation for `" ++ Name.toChars name
15171515 ++ "` so I was expecting to see its definition here:"
15181516 ,
1519− D.reflow $
1520− "Type annotations always appear directly above the relevant\
1521− \ definition, without anything else (even doc comments) in between."
1517+ D.stack
1518+ [ D.reflow $
1519+ "Type annotations always appear directly above the relevant\
1520+ \ definition, without anything else (even doc comments) in between."
1521+ , declDefNote
1522+ ]
15221523 )
15231524
15241525 DeclDefNameMatch defName row col ->
@@ -1541,16 +1542,76 @@ toDeclDefReport source name declDef startRow startCol =
15411542 )
15421543
15431544 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+ )
15451561
15461562 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+ )
15481579
15491580 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+ )
15511597
1552− DeclDefFreshLineAfterType row col ->
1553− error "TODO DeclDefFreshLineAfterType" row col
1598+
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+ ]
15541615
15551616
15561617