on master help sign in
Begin upgrade of Docs code from String to Text

Big chunks do not work though. Need to create a doc comment parser using Parse.Primitives.

commitfe4ad5a0eb8be071807fc83ac6fb453901fbe73c authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 7 Dec 2016, 15:18 (10 years ago) parent5698054
3 files changed+36−36
src/Docs/AST.hs+14−12 src/Docs/Centralize.hs+8−7 src/Docs/Check.hs+14−17
src/Docs/AST.hs+14−12
@@ -1,6 +1,7 @@
11module Docs.AST where
22
33import qualified Data.Map as Map
4+import Data.Text (Text)
45
56import qualified Elm.Compiler.Type as Type
67import qualified Reporting.Annotation as A
@@ -8,11 +9,12 @@ import qualified Reporting.Annotation as A
89
910-- FULL DOCUMENTATION
1011
11−data Docs t = Docs
12− { comment :: String
13− , aliases :: Map.Map String (A.Located Alias)
14− , types :: Map.Map String (A.Located Union)
15− , values :: Map.Map String (A.Located (Value t))
12+data Docs t =
13+ Docs
14+ { comment :: Text
15+ , aliases :: Map.Map Text (A.Located Alias)
16+ , types :: Map.Map Text (A.Located Union)
17+ , values :: Map.Map Text (A.Located (Value t))
1618 }
1719
1820
@@ -24,21 +26,21 @@ type Checked = Docs Type.Type
2426-- VALUE DOCUMENTATION
2527
2628data Alias = Alias
27− { aliasComment :: Maybe String
28− , aliasArgs :: [String]
29+ { aliasComment :: Maybe Text
30+ , aliasArgs :: [Text]
2931 , aliasType :: Type.Type
3032 }
3133
3234
3335data Union = Union
34− { unionComment :: Maybe String
35− , unionArgs :: [String]
36− , unionCases :: [(String, [Type.Type])]
36+ { unionComment :: Maybe Text
37+ , unionArgs :: [Text]
38+ , unionCases :: [(Text, [Type.Type])]
3739 }
3840
3941
4042data Value t = Value
41− { valueComment :: Maybe String
43+ { valueComment :: Maybe Text
4244 , valueType :: t
43− , valueAssocPrec :: Maybe (String,Int)
45+ , valueAssocPrec :: Maybe (Text,Int)
4446 }
src/Docs/Centralize.hs+8−7
@@ -3,6 +3,7 @@ module Docs.Centralize (centralize) where
33import Control.Arrow (second)
44import qualified Data.Map as Map
55import qualified Data.Maybe as Maybe
6+import Data.Text (Text)
67
78import qualified AST.Declaration as D
89import qualified AST.Expression.Canonical as Canonical
@@ -18,7 +19,7 @@ import qualified Reporting.Annotation as A
1819-- CENTRALIZE DOCUMENTATION
1920
2021
21−centralize :: D.Canonical -> String -> Docs.Centralized
22+centralize :: D.Canonical -> Text -> Docs.Centralized
2223centralize (D.Decls defs unions aliases infixes) comment =
2324 let
2425 infixDict =
@@ -36,9 +37,9 @@ centralize (D.Decls defs unions aliases infixes) comment =
3637
3738
3839defToEntry
39− :: Map.Map String (String, Int)
40+ :: Map.Map Text (Text, Int)
4041 -> A.Commented Canonical.Def
41− -> Maybe (String, A.Located (Docs.Value (Maybe Type.Type)))
42+ -> Maybe (Text, A.Located (Docs.Value (Maybe Type.Type)))
4243defToEntry infixDict (A.A (_, maybeComment) (Canonical.Def _ pattern _ maybeType)) =
4344 case pattern of
4445 A.A subregion (Pattern.Var name) ->
@@ -55,7 +56,7 @@ defToEntry infixDict (A.A (_, maybeComment) (Canonical.Def _ pattern _ maybeType
5556 Nothing
5657
5758
58−unionToEntry :: A.Commented (D.Union Type.Canonical) -> (String, A.Located Docs.Union)
59+unionToEntry :: A.Commented (D.Union Type.Canonical) -> (Text, A.Located Docs.Union)
5960unionToEntry (A.A (region, maybeComment) (D.Type name args ctors)) =
6061 let
6162 ctors' =
@@ -64,17 +65,17 @@ unionToEntry (A.A (region, maybeComment) (D.Type name args ctors)) =
6465 (name, A.A region (Docs.Union maybeComment args ctors'))
6566
6667
67−aliasToEntry :: A.Commented (D.Alias Type.Canonical) -> (String, A.Located Docs.Alias)
68+aliasToEntry :: A.Commented (D.Alias Type.Canonical) -> (Text, A.Located Docs.Alias)
6869aliasToEntry (A.A (region, maybeComment) (D.Type name args tipe)) =
6970 ( name
7071 , A.A region (Docs.Alias maybeComment args (Extract.extract tipe))
7172 )
7273
7374
74−infixToEntry :: D.Infix -> (String, (String, Int))
75+infixToEntry :: D.Infix -> (Text, (Text, Int))
7576infixToEntry (D.Infix name assoc precedence) =
7677 let
7778 fixity =
78− (D.assocToString assoc, precedence)
79+ (D.assocToText assoc, precedence)
7980 in
8081 ( name, fixity )
src/Docs/Check.hs+14−17
@@ -1,25 +1,19 @@
11module Docs.Check (Result, check) where
22
3−import qualified Data.List as List
4−import qualified Data.Map as Map
5−import qualified Data.Set as Set
6−import qualified Data.Traversable as T
7−import Text.Parsec ((<|>), choice, many, setPosition, string)
8−import Text.Parsec.Pos (newPos)
3+--import qualified Data.List as List
4+--import qualified Data.Map as Map
5+--import qualified Data.Set as Set
6+--import qualified Data.Traversable as T
97
108import qualified AST.Variable as Var
119import qualified Docs.AST as Docs
12−import qualified Elm.Compiler.Type as Type
13−import Elm.Utils ((|>))
14−import Parse.Binop (infixOp)
15−import Parse.Helpers
16− ( addLocation, anyUntil, commaSep1, parens, parse, simpleNewline
17− , var, whitespace
18− )
10+--import qualified Elm.Compiler.Type as Type
11+--import Elm.Utils ((|>))
12+--import Parse.Helpers
1913import qualified Reporting.Annotation as A
2014import qualified Reporting.Error.Docs as Error
21−import qualified Reporting.Error.Helpers as Error (nearbyNames)
22−import qualified Reporting.Region as R
15+--import qualified Reporting.Error.Helpers as Error (nearbyNames)
16+--import qualified Reporting.Region as R
2317import qualified Reporting.Result as R
2418
2519
@@ -30,8 +24,10 @@ type Result w a =
3024
3125-- CHECK DOCUMENTATION
3226
33−check :: [Var.Value] -> A.Located (Maybe Docs.Centralized) -> Result w Docs.Checked
34−check exports (A.A region maybeDocs) =
27+check :: [Var.Value] -> Maybe (A.Located Docs.Centralized) -> Result w Docs.Checked
28+check exports maybeDocs =
29+ R.ok (error "TODO check docs" exports maybeDocs)
30+{-
3531 case maybeDocs of
3632 Nothing ->
3733 R.throw region Error.NoDocs
@@ -180,3 +176,4 @@ valueName value =
180176 Var.Value name -> name
181177 Var.Alias name -> name
182178 Var.Union name _ -> name
179+-}