on 07712e9 help sign in
.github/CONTRIBUTING.md+20−18
since splitsnapshots
unifiedsplit
@@ -4,15 +4,10 @@ Thanks helping with the development of Elm! This document describes the basic
4standards for opening pull requests and making the review process as smooth as
4standards for opening pull requests and making the review process as smooth as
5possible.
5possible.
6
6
7+## Licensing
7
8
8−## Expectations
9+You need to sign the [contributor agreement](ContributorAgreement.pdf)
9−
10+and send it to <info@elm-lang.org> before opening your pull request.
10−- Pull requests are reviewed in [batches](https://github.com/elm/expectations/blob/master/batching.md), so it can take some time to get a response.
11−- Smaller pull requests are easier to review. To fix nine typos, nine specific issues will always go faster than one big one. Learn why [here](https://github.com/elm/expectations/blob/master/small-pull-requests.md).
12−- Reviewers may not know as much as you about certain situations, so add links to supporting evidence for important claims, especially regarding standards for CSS, HTTP, URI, etc.
13−
14−Finally, please be patient with the core team. They are trying their best with limited resources!
15−
16
11
17## Style Guide
12## Style Guide
18
13
@@ -22,20 +17,27 @@ Finally, please be patient with the core team. They are trying their best with l
22[haskell]: https://gist.github.com/evancz/0a1f3717c92fe71702be
17[haskell]: https://gist.github.com/evancz/0a1f3717c92fe71702be
23[js]: https://google.github.io/styleguide/javascriptguide.xml
18[js]: https://google.github.io/styleguide/javascriptguide.xml
24
19
25−
26## Branches
20## Branches
27
21
28−[The master branch][master] is the home of the next release of the compiler
22+ * [The master branch][master] is the home of the next release of the compiler
29−so new features and improvements get merged there. Most pull requests
23+ so new features and improvements get merged there. Most pull requests
30−should target this branch!
24+ should target this branch!
31−
32−[master]: http://github.com/elm-lang/elm/tree/master
33
25
26+ * [The stable branch][stable] is for tagging releases and critical bug fixes.
27+ This branch is handy for folks who want to build the most recent public
28+ release from source.
34
29
35−## Licensing
30+[master]: http://github.com/elm-lang/elm/tree/master
36−
31+[stable]: http://github.com/elm-lang/elm/tree/stable
37−Nothing extra to do for this. The default on GitHub described [here](https://docs.github.com/en/github/site-policy/github-terms-of-service#6-contributions-under-repository-license) is that:
38
32
39−> Whenever you add Content to a repository containing notice of a license, you license that Content under the same terms, and you agree that you have the right to license that Content under those terms. If you have a separate agreement to license that Content under different terms, such as a contributor license agreement, that agreement will supersede.
33+If you are working on a fairly large feature, we will probably want to merge it
34+in as its own branch and do some testing before bringing it into the master
35+branch. This way we can keep releases of the master branch independent of new
36+features.
40
37
38+Note that the master branch of the compiler should always be in sync with the
39+master branch of the [website][], and the stable branch of the compiler should
40+always be in sync with the stable branch of the [website][]. Make sure that
41+your changes maintain this compatibility.
41
42
43+[website]: https://github.com/elm-lang/elm-lang.org
.github/ISSUE_TEMPLATE.md+9−14
@@ -1,18 +1,13 @@
1+BEFORE DELETING THIS:
1
2
2−**Quick Summary:** ???
3+- Runtime error? https://github.com/elm-lang/elm-compiler/issues/1591
4+- Type annotations? https://github.com/elm-lang/elm-compiler/issues/1214
5+- Core libraries? https://github.com/elm-lang/core/issues
6+- Bad error message? https://github.com/elm-lang/error-message-catalog/issues
7+- Compiler hangs? https://github.com/elm-lang/elm-compiler/issues/1240
8+- Parser / code gen problem? https://github.com/elm-lang/elm-compiler/labels/meta
3
9
4
10
5−## SSCCE
11+If none of that applies, write up a report that satisfies this checklist:
6
12
7−```elm
13+ https://github.com/process-bot/contribution-checklist/blob/master/issues.md
8−
9−```
10−
11−- **Elm:** ???
12−- **Browser:** ???
13−- **Operating System:** ???
14−
15−
16−## Additional Details
17−
18−???
.github/PULL_REQUEST_TEMPLATE.mddeleted−18
@@ -1,18 +0,0 @@
1−
2−**Quick Summary:** ???
3−
4−
5−## SSCCE
6−
7−```elm
8−
9−```
10−
11−- **Elm:** ???
12−- **Browser:** ???
13−- **Operating System:** ???
14−
15−
16−## Additional Details
17−
18−???
.github/workflows/set-issue-expectations.ymldeleted−21
@@ -1,21 +0,0 @@
1−name: Set Issue Expectations
2−on:
3− issues:
4− types: [opened]
5−jobs:
6− comment-on-issue:
7− name: Comment On Issue
8− runs-on: ubuntu-latest
9− steps:
10− - uses: actions/github@v1.0.0
11− env:
12− GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13− with:
14− args: |
15− comment "Thanks for reporting this! To set expectations:
16−
17− - Issues are reviewed in [batches](https://github.com/elm/expectations/blob/master/batching.md), so it can take some time to get a response.
18− - Ask questions in a [community forum](https://elm-lang.org/community). You will get an answer quicker that way!
19− - If you experience something similar, open a new issue. [We like duplicates](https://github.com/elm/expectations/blob/master/duplicates.md).
20−
21− Finally, please be patient with the core team. They are trying their best with limited resources."
.github/workflows/set-pull-expectations.ymldeleted−19
@@ -1,19 +0,0 @@
1−on:
2− pull_request_target:
3− types: [opened]
4−
5−jobs:
6− comment-on-pull:
7− name: Comment On Pull
8− runs-on: ubuntu-latest
9− steps:
10− - uses: actions/github-script@v3
11− with:
12− github-token: ${{secrets.GITHUB_TOKEN}}
13− script: |
14− github.issues.createComment({
15− issue_number: context.issue.number,
16− owner: context.repo.owner,
17− repo: context.repo.repo,
18− body: "Thanks for suggesting these code changes. To set expectations:\n\n- Pull requests are reviewed in [batches](https://github.com/elm/expectations/blob/master/batching.md), so it can take some time to get a response.\n- Smaller pull requests are easier to review. To fix nine typos, nine specific issues will always go faster than one big one. Learn why [here](https://github.com/elm/expectations/blob/master/small-pull-requests.md).\n- Reviewers may not know as much as you about certain situations, so add links to supporting evidence for important claims, especially regarding standards for CSS, HTTP, URI, etc.\n\nFinally, please be patient with the core team. They are trying their best with limited resources."
19− })
.gitignore−1
@@ -5,4 +5,3 @@ cabal-dev
5cabal.sandbox.config
5cabal.sandbox.config
6.DS_Store
6.DS_Store
7*~
7*~
8−travis.log
.gitmodulesnew file

No changes to the content.

.travis.yml+20−23
@@ -1,28 +1,25 @@
1−language: minimal
1+sudo: false
2−services: docker
2+
3+addons:
4+ apt:
5+ sources:
6+ - hvr-ghc
7+ packages:
8+ - ghc-7.10.1
9+ - cabal-install-1.22
10+ - happy
11+ - alex
3
12
4−env:
5− global:
6− - LINUX_ARCHIVE=binary-for-linux-64-bit.gz
7
13
8before_install:
14before_install:
9− - docker build -t elm -f installers/linux/Dockerfile .
15+- export PATH=/opt/ghc/7.10.1/bin:/opt/cabal/1.22/bin:$PATH
10− - docker cp $(docker create elm):/usr/local/bin/elm .
16+
11− - gzip -9 -c elm > $LINUX_ARCHIVE
17+
18+install:
19+ - travis_retry cabal update
20+ - cabal install --only-dependencies --enable-tests
12
21
13−deploy:
14− provider: releases
15− api_key:
16− secure: Yz2Lo4u9rZQ7Ee7ohAsrZpkqsYDUerCSMdSQIH8ryrf7phHhiloPEkTKsM+NupHqU/LEAVsunxbau4QrCEjA2vPavAPVk8cKomRUWK/YjbXHKa24hPkal2c+A2bnMQ6w3qYk/PjL9rW+Goq++/SNLcYZwHBV0Chl2blivMwWCSA=
17− file: $LINUX_ARCHIVE
18− skip_cleanup: true
19− on:
20− branch: master
21− tags: true
22
22
23−notifications:
23+script:
24− email:
24+ - cabal configure --enable-tests
25− recipients:
25+ - cabal test
26− - rlefevre@dmy.fr
27− on_success: change
28− on_failure: change
ContributorAgreement.pdfnew file

Binary file not shown.

How to Request Features.mdnew file+93
@@ -0,0 +1,93 @@
1+# How to make a Feature Request
2+
3+Adding features is hard work and has long term implications for Elm.
4+If you think your particular feature is important, help make it happen
5+by doing some of the background work that goes into actually adding it.
6+
7+### Before making a Request / Formatting:
8+
9+ - Make sure your feature has not already been requested. Look through the
10+ email list to find similar requests.
11+ - Submit feature requests by emailing the list. This allows the broadest
12+ discussion and does not clutter up the GitHub repository with speculative
13+ issues. I'd prefer to use the GitHub issue tracker for bug tracking and
14+ issues with the existing code base.
15+ - Label all feature requests with a subject like "Request: _____". For
16+ example, if you want to be the umpteenth person to request type classes,
17+ you would use the subject "Request: Type Classes".
18+
19+### Body of the Request:
20+
21+Your request should address all of the following issues:
22+
23+**General Problem:** Clearly define the purpose of adding the feature.
24+What general problem do you want to solve? Why is that problem important?
25+Why is it important for a functional GUI language?
26+
27+**Specific Use-Cases:** What are the specific cases when the general problem
28+is actually an issue? How often does this case come up? Why are these cases
29+important to easily designing graphical user interfaces? Why are existing
30+solutions in Elm unsuitable?
31+
32+**Background Materials:** Are there relevant papers on the topic? Are there
33+languages or libraries that already have this feature? Organize this material
34+and provide a concise and helpful overview.
35+
36+**Alternatives:** What are all the ways to address the general problem or a
37+closely related problem? For example, the semantic flexibility of type classes
38+can be largely replicated with a module system in the style of ML.
39+What are the strengths and weakness of each of the alternative solutions?
40+
41+**Suggested Approach:** Outline your specific approach. How does it address
42+the general problem? How does it work? How hard is it going to be to add?
43+What other language features does it depend on that need to be added first?
44+Try to take a look at the relevant code to see if it would require significant
45+changes. If you are suggesting an API or library changes, include an interface
46+(a list of type signatures) for the functions you would like to add (perhaps
47+multiple interfaces if there are many good approaches).
48+
49+**Known Issues:** Search for issues that people have already found. Think of
50+any other possible downside and list them too. For example, one downside of
51+typeclasses is that they are globally defined for each type, so you cannot
52+have multiple `Ord` instances for Strings. This can lead to namespace pollution
53+within a project. In general you can only implement an "interface" once per
54+type, so it is very tricky to get the flexibility of ML's module functors.
55+
56+**Justification:** Why is the added complexity of your feature worth it? Discuss
57+both implementation complexity in the compiler, and conceptual complexity that
58+users must deal with. Why is your feature better than the alternative solutions?
59+Why is it okay to ignore the known issues? Is there any way to overcome the known
60+issues? Will it be difficult or confusing for users coming from JavaScript?
61+
62+### Some final notes:
63+
64+If for some reason you cannot provide details for some of these categories,
65+explain why the category is not applicable.
66+
67+Re-read before posting. Is your request constructive? Is it well organized?
68+Are there any details you forgot? Can anything be clarified or trimmed down?
69+Considering a request takes time, so be considerate about how much work a
70+reader has to do to take it seriously.
71+
72+A feature request is not an opportunity to be sassy or glib. Try to present
73+the information and argument clearly, concisely, thoroughly, and in an unbiased
74+manner.
75+
76+This is likely to be an iterative process. People will have comments and
77+questions. Everyone please be kind. Commenters, if you think you have a
78+concern, raise it as a question: "But what happens when you do blah?" instead
79+of "This will break when you do blah". Assume you have misunderstood their
80+proposal or only have a shallow understanding of it. Seek clarification, not victory.
81+
82+Comments are not a place for flame wars. Discuss specific issues. Vague
83+complaining and unsupported claims should either be forgotten or developed
84+into specific and well-supported concerns.
85+
86+I am always working hard to add cool stuff to Elm, and it is a lot of work.
87+I must prioritize issues to focus on the things that have the highest impact
88+for improving the quality of Elm, addressing the concerns of current users,
89+and making Elm more appealing for new users. I do not have infinite time,
90+so some things must receive more attention than others. I apologize in advance.
91+
92+And to summarize, just be cool! I want Elm to be really fun and easy to use,
93+and I want your projects to be amazing!
LICENSE+25−6
@@ -1,11 +1,30 @@
1−Copyright 2012-present Evan Czaplicki
1+Copyright (c) 2012-present, Evan Czaplicki
2
2
3−Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3+All rights reserved.
4
4
5−1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
6
7
8+ * Redistributions of source code must retain the above copyright
7−2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+ notice, this list of conditions and the following disclaimer.
8
10
9−3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
10
15
11−THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16+ * Neither the name of Evan Czaplicki nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.md+5−10
@@ -1,22 +1,17 @@
1−# Elm
1+# The Elm Compiler [![Build Status](https://travis-ci.org/elm-lang/elm-compiler.svg?branch=master)](https://travis-ci.org/elm-lang/elm-compiler)
2
2
3−A delightful language for reliable webapps.
3+Learn about the Elm programming language at [elm-lang.org](http://elm-lang.org/).
4
4
5−Check out the [Home Page](http://elm-lang.org/), [Try Online](http://elm-lang.org/try), or [The Official Guide](http://guide.elm-lang.org/)
6−
7−
8−<br>
9
5
10## Install
6## Install
11
7
12−✨ [Install](https://guide.elm-lang.org/install/elm.html) ✨
8+Follow [these instructions][installer]!
13
9
14−For multiple versions, previous versions, and uninstallation, see the instructions [here](https://github.com/elm/compiler/blob/master/installers/README.md).
10+ [installer]: https://guide.elm-lang.org/install.html
15
11
16−<br>
17
12
18## Help
13## Help
19
14
20If you are stuck, ask around on [the Elm slack channel][slack]. Folks are friendly and happy to help with questions!
15If you are stuck, ask around on [the Elm slack channel][slack]. Folks are friendly and happy to help with questions!
21
16
22−[slack]: http://elmlang.herokuapp.com/
17+[slack]: http://elmlang.herokuapp.com/
Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
builder/src/BackgroundWriter.hsdeleted−42
@@ -1,42 +0,0 @@
1−{-# LANGUAGE BangPatterns #-}
2−module BackgroundWriter
3− ( Scope
4− , withScope
5− , writeBinary
6− )
7− where
8−
9−
10−import Control.Concurrent (forkIO)
11−import Control.Concurrent.MVar (MVar, newEmptyMVar, newMVar, putMVar, takeMVar)
12−import qualified Data.Binary as Binary
13−import Data.Foldable (traverse_)
14−
15−import qualified File
16−
17−
18−
19−-- BACKGROUND WRITER
20−
21−
22−newtype Scope =
23− Scope (MVar [MVar ()])
24−
25−
26−withScope :: (Scope -> IO a) -> IO a
27−withScope callback =
28− do workList <- newMVar []
29− result <- callback (Scope workList)
30− mvars <- takeMVar workList
31− traverse_ takeMVar mvars
32− return result
33−
34−
35−writeBinary :: (Binary.Binary a) => Scope -> FilePath -> a -> IO ()
36−writeBinary (Scope workList) path value =
37− do mvar <- newEmptyMVar
38− _ <- forkIO (File.writeBinary path value >> putMVar mvar ())
39− oldWork <- takeMVar workList
40− let !newWork = mvar:oldWork
41− putMVar workList newWork
42−
builder/src/Build.hsdeleted−1251
@@ -1,1251 +0,0 @@
1−{-# OPTIONS_GHC -Wno-unused-do-bind #-}
2−{-# LANGUAGE BangPatterns, GADTs, OverloadedStrings #-}
3−module Build
4− ( fromExposed
5− , fromPaths
6− , fromRepl
7− , Artifacts(..)
8− , Root(..)
9− , Module(..)
10− , CachedInterface(..)
11− , ReplArtifacts(..)
12− , DocsGoal(..)
13− , getRootNames
14− )
15− where
16−
17−
18−import Control.Concurrent (forkIO)
19−import Control.Concurrent.MVar
20−import Control.Monad (filterM, mapM_, sequence_)
21−import qualified Data.ByteString as B
22−import qualified Data.Char as Char
23−import qualified Data.Graph as Graph
24−import qualified Data.List as List
25−import qualified Data.Map.Utils as Map
26−import qualified Data.Map.Strict as Map
27−import Data.Map.Strict ((!))
28−import qualified Data.Maybe as Maybe
29−import qualified Data.Name as Name
30−import qualified Data.NonEmptyList as NE
31−import qualified Data.OneOrMore as OneOrMore
32−import qualified Data.Set as Set
33−import qualified System.Directory as Dir
34−import qualified System.FilePath as FP
35−import System.FilePath ((</>), (<.>))
36−
37−import qualified AST.Canonical as Can
38−import qualified AST.Source as Src
39−import qualified AST.Optimized as Opt
40−import qualified Compile
41−import qualified Elm.Details as Details
42−import qualified Elm.Docs as Docs
43−import qualified Elm.Interface as I
44−import qualified Elm.ModuleName as ModuleName
45−import qualified Elm.Outline as Outline
46−import qualified Elm.Package as Pkg
47−import qualified File
48−import qualified Json.Encode as E
49−import qualified Parse.Module as Parse
50−import qualified Reporting
51−import qualified Reporting.Annotation as A
52−import qualified Reporting.Error as Error
53−import qualified Reporting.Error.Docs as EDocs
54−import qualified Reporting.Error.Syntax as Syntax
55−import qualified Reporting.Error.Import as Import
56−import qualified Reporting.Exit as Exit
57−import qualified Reporting.Render.Type.Localizer as L
58−import qualified Stuff
59−
60−
61−
62−-- ENVIRONMENT
63−
64−
65−data Env =
66− Env
67− { _key :: Reporting.BKey
68− , _root :: FilePath
69− , _project :: Parse.ProjectType
70− , _srcDirs :: [AbsoluteSrcDir]
71− , _buildID :: Details.BuildID
72− , _locals :: Map.Map ModuleName.Raw Details.Local
73− , _foreigns :: Map.Map ModuleName.Raw Details.Foreign
74− }
75−
76−
77−makeEnv :: Reporting.BKey -> FilePath -> Details.Details -> IO Env
78−makeEnv key root (Details.Details _ validOutline buildID locals foreigns _) =
79− case validOutline of
80− Details.ValidApp givenSrcDirs ->
81− do srcDirs <- traverse (toAbsoluteSrcDir root) (NE.toList givenSrcDirs)
82− return $ Env key root Parse.Application srcDirs buildID locals foreigns
83−
84− Details.ValidPkg pkg _ _ ->
85− do srcDir <- toAbsoluteSrcDir root (Outline.RelativeSrcDir "src")
86− return $ Env key root (Parse.Package pkg) [srcDir] buildID locals foreigns
87−
88−
89−
90−-- SOURCE DIRECTORY
91−
92−
93−newtype AbsoluteSrcDir =
94− AbsoluteSrcDir FilePath
95−
96−
97−toAbsoluteSrcDir :: FilePath -> Outline.SrcDir -> IO AbsoluteSrcDir
98−toAbsoluteSrcDir root srcDir =
99− AbsoluteSrcDir <$> Dir.canonicalizePath
100− (
101− case srcDir of
102− Outline.AbsoluteSrcDir dir -> dir
103− Outline.RelativeSrcDir dir -> root </> dir
104− )
105−
106−
107−addRelative :: AbsoluteSrcDir -> FilePath -> FilePath
108−addRelative (AbsoluteSrcDir srcDir) path =
109− srcDir </> path
110−
111−
112−
113−-- FORK
114−
115−
116−-- PERF try using IORef semephore on file crawl phase?
117−-- described in Chapter 13 of Parallel and Concurrent Programming in Haskell by Simon Marlow
118−-- https://www.oreilly.com/library/view/parallel-and-concurrent/9781449335939/ch13.html#sec_conc-par-overhead
119−--
120−fork :: IO a -> IO (MVar a)
121−fork work =
122− do mvar <- newEmptyMVar
123− _ <- forkIO $ putMVar mvar =<< work
124− return mvar
125−
126−
127−{-# INLINE forkWithKey #-}
128−forkWithKey :: (k -> a -> IO b) -> Map.Map k a -> IO (Map.Map k (MVar b))
129−forkWithKey func dict =
130− Map.traverseWithKey (\k v -> fork (func k v)) dict
131−
132−
133−
134−-- FROM EXPOSED
135−
136−
137−fromExposed :: Reporting.Style -> FilePath -> Details.Details -> DocsGoal docs -> NE.List ModuleName.Raw -> IO (Either Exit.BuildProblem docs)
138−fromExposed style root details docsGoal exposed@(NE.List e es) =
139− Reporting.trackBuild style $ \key ->
140− do env <- makeEnv key root details
141− dmvar <- Details.loadInterfaces root details
142−
143− -- crawl
144− mvar <- newEmptyMVar
145− let docsNeed = toDocsNeed docsGoal
146− roots <- Map.fromKeysA (fork . crawlModule env mvar docsNeed) (e:es)
147− putMVar mvar roots
148− mapM_ readMVar roots
149− statuses <- traverse readMVar =<< readMVar mvar
150−
151− -- compile
152− midpoint <- checkMidpoint dmvar statuses
153− case midpoint of
154− Left problem ->
155− return (Left (Exit.BuildProjectProblem problem))
156−
157− Right foreigns ->
158− do rmvar <- newEmptyMVar
159− resultMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
160− putMVar rmvar resultMVars
161− results <- traverse readMVar resultMVars
162− writeDetails root details results
163− finalizeExposed root docsGoal exposed results
164−
165−
166−
167−-- FROM PATHS
168−
169−
170−data Artifacts =
171− Artifacts
172− { _name :: Pkg.Name
173− , _deps :: Dependencies
174− , _roots :: NE.List Root
175− , _modules :: [Module]
176− }
177−
178−
179−data Module
180− = Fresh ModuleName.Raw I.Interface Opt.LocalGraph
181− | Cached ModuleName.Raw Bool (MVar CachedInterface)
182−
183−
184−type Dependencies =
185− Map.Map ModuleName.Canonical I.DependencyInterface
186−
187−
188−fromPaths :: Reporting.Style -> FilePath -> Details.Details -> NE.List FilePath -> IO (Either Exit.BuildProblem Artifacts)
189−fromPaths style root details paths =
190− Reporting.trackBuild style $ \key ->
191− do env <- makeEnv key root details
192−
193− elroots <- findRoots env paths
194− case elroots of
195− Left problem ->
196− return (Left (Exit.BuildProjectProblem problem))
197−
198− Right lroots ->
199− do -- crawl
200− dmvar <- Details.loadInterfaces root details
201− smvar <- newMVar Map.empty
202− srootMVars <- traverse (fork . crawlRoot env smvar) lroots
203− sroots <- traverse readMVar srootMVars
204− statuses <- traverse readMVar =<< readMVar smvar
205−
206− midpoint <- checkMidpointAndRoots dmvar statuses sroots
207− case midpoint of
208− Left problem ->
209− return (Left (Exit.BuildProjectProblem problem))
210−
211− Right foreigns ->
212− do -- compile
213− rmvar <- newEmptyMVar
214− resultsMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
215− putMVar rmvar resultsMVars
216− rrootMVars <- traverse (fork . checkRoot env resultsMVars) sroots
217− results <- traverse readMVar resultsMVars
218− writeDetails root details results
219− toArtifacts env foreigns results <$> traverse readMVar rrootMVars
220−
221−
222−
223−-- GET ROOT NAMES
224−
225−
226−getRootNames :: Artifacts -> NE.List ModuleName.Raw
227−getRootNames (Artifacts _ _ roots _) =
228− fmap getRootName roots
229−
230−
231−getRootName :: Root -> ModuleName.Raw
232−getRootName root =
233− case root of
234− Inside name -> name
235− Outside name _ _ -> name
236−
237−
238−
239−-- CRAWL
240−
241−
242−type StatusDict =
243− Map.Map ModuleName.Raw (MVar Status)
244−
245−
246−data Status
247− = SCached Details.Local
248− | SChanged Details.Local B.ByteString Src.Module DocsNeed
249− | SBadImport Import.Problem
250− | SBadSyntax FilePath File.Time B.ByteString Syntax.Error
251− | SForeign Pkg.Name
252− | SKernel
253−
254−
255−crawlDeps :: Env -> MVar StatusDict -> [ModuleName.Raw] -> a -> IO a
256−crawlDeps env mvar deps blockedValue =
257− do statusDict <- takeMVar mvar
258− let depsDict = Map.fromKeys (\_ -> ()) deps
259− let newsDict = Map.difference depsDict statusDict
260− statuses <- Map.traverseWithKey crawlNew newsDict
261− putMVar mvar (Map.union statuses statusDict)
262− mapM_ readMVar statuses
263− return blockedValue
264− where
265− crawlNew name () = fork (crawlModule env mvar (DocsNeed False) name)
266−
267−
268−crawlModule :: Env -> MVar StatusDict -> DocsNeed -> ModuleName.Raw -> IO Status
269−crawlModule env@(Env _ root projectType srcDirs buildID locals foreigns) mvar docsNeed name =
270− do let fileName = ModuleName.toFilePath name <.> "elm"
271−
272− paths <- filterM File.exists (map (`addRelative` fileName) srcDirs)
273−
274− case paths of
275− [path] ->
276− case Map.lookup name foreigns of
277− Just (Details.Foreign dep deps) ->
278− return $ SBadImport $ Import.Ambiguous path [] dep deps
279−
280− Nothing ->
281− do newTime <- File.getTime path
282− case Map.lookup name locals of
283− Nothing ->
284− crawlFile env mvar docsNeed name path newTime buildID
285−
286− Just local@(Details.Local oldPath oldTime deps _ lastChange _) ->
287− if path /= oldPath || oldTime /= newTime || needsDocs docsNeed
288− then crawlFile env mvar docsNeed name path newTime lastChange
289− else crawlDeps env mvar deps (SCached local)
290−
291− p1:p2:ps ->
292− return $ SBadImport $ Import.AmbiguousLocal (FP.makeRelative root p1) (FP.makeRelative root p2) (map (FP.makeRelative root) ps)
293−
294− [] ->
295− case Map.lookup name foreigns of
296− Just (Details.Foreign dep deps) ->
297− case deps of
298− [] ->
299− return $ SForeign dep
300−
301− d:ds ->
302− return $ SBadImport $ Import.AmbiguousForeign dep d ds
303−
304− Nothing ->
305− if Name.isKernel name && Parse.isKernel projectType then
306− do exists <- File.exists ("src" </> ModuleName.toFilePath name <.> "js")
307− return $ if exists then SKernel else SBadImport Import.NotFound
308− else
309− return $ SBadImport Import.NotFound
310−
311−
312−crawlFile :: Env -> MVar StatusDict -> DocsNeed -> ModuleName.Raw -> FilePath -> File.Time -> Details.BuildID -> IO Status
313−crawlFile env@(Env _ root projectType _ buildID _ _) mvar docsNeed expectedName path time lastChange =
314− do source <- File.readUtf8 (root </> path)
315−
316− case Parse.fromByteString projectType source of
317− Left err ->
318− return $ SBadSyntax path time source err
319−
320− Right modul@(Src.Module maybeActualName _ _ imports values _ _ _ _) ->
321− case maybeActualName of
322− Nothing ->
323− return $ SBadSyntax path time source (Syntax.ModuleNameUnspecified expectedName)
324−
325− Just name@(A.At _ actualName) ->
326− if expectedName == actualName then
327− let
328− deps = map Src.getImportName imports
329− local = Details.Local path time deps (any isMain values) lastChange buildID
330− in
331− crawlDeps env mvar deps (SChanged local source modul docsNeed)
332− else
333− return $ SBadSyntax path time source (Syntax.ModuleNameMismatch expectedName name)
334−
335−
336−isMain :: A.Located Src.Value -> Bool
337−isMain (A.At _ (Src.Value (A.At _ name) _ _ _)) =
338− name == Name._main
339−
340−
341−
342−-- CHECK MODULE
343−
344−
345−type ResultDict =
346− Map.Map ModuleName.Raw (MVar Result)
347−
348−
349−data Result
350− = RNew !Details.Local !I.Interface !Opt.LocalGraph !(Maybe Docs.Module)
351− | RSame !Details.Local !I.Interface !Opt.LocalGraph !(Maybe Docs.Module)
352− | RCached Bool Details.BuildID (MVar CachedInterface)
353− | RNotFound Import.Problem
354− | RProblem Error.Module
355− | RBlocked
356− | RForeign I.Interface
357− | RKernel
358−
359−
360−data CachedInterface
361− = Unneeded
362− | Loaded I.Interface
363− | Corrupted
364−
365−
366−checkModule :: Env -> Dependencies -> MVar ResultDict -> ModuleName.Raw -> Status -> IO Result
367−checkModule env@(Env _ root projectType _ _ _ _) foreigns resultsMVar name status =
368− case status of
369− SCached local@(Details.Local path time deps hasMain lastChange lastCompile) ->
370− do results <- readMVar resultsMVar
371− depsStatus <- checkDeps root results deps lastCompile
372− case depsStatus of
373− DepsChange ifaces ->
374− do source <- File.readUtf8 path
375− case Parse.fromByteString projectType source of
376− Right modul -> compile env (DocsNeed False) local source ifaces modul
377− Left err ->
378− return $ RProblem $
379− Error.Module name path time source (Error.BadSyntax err)
380−
381− DepsSame _ _ ->
382− do mvar <- newMVar Unneeded
383− return (RCached hasMain lastChange mvar)
384−
385− DepsBlock ->
386− return RBlocked
387−
388− DepsNotFound problems ->
389− do source <- File.readUtf8 path
390− return $ RProblem $ Error.Module name path time source $
391− case Parse.fromByteString projectType source of
392− Right (Src.Module _ _ _ imports _ _ _ _ _) ->
393− Error.BadImports (toImportErrors env results imports problems)
394−
395− Left err ->
396− Error.BadSyntax err
397−
398− SChanged local@(Details.Local path time deps _ _ lastCompile) source modul@(Src.Module _ _ _ imports _ _ _ _ _) docsNeed ->
399− do results <- readMVar resultsMVar
400− depsStatus <- checkDeps root results deps lastCompile
401− case depsStatus of
402− DepsChange ifaces ->
403− compile env docsNeed local source ifaces modul
404−
405− DepsSame same cached ->
406− do maybeLoaded <- loadInterfaces root same cached
407− case maybeLoaded of
408− Nothing -> return RBlocked
409− Just ifaces -> compile env docsNeed local source ifaces modul
410−
411− DepsBlock ->
412− return RBlocked
413−
414− DepsNotFound problems ->
415− return $ RProblem $ Error.Module name path time source $
416− Error.BadImports (toImportErrors env results imports problems)
417−
418− SBadImport importProblem ->
419− return (RNotFound importProblem)
420−
421− SBadSyntax path time source err ->
422− return $ RProblem $ Error.Module name path time source $
423− Error.BadSyntax err
424−
425− SForeign home ->
426− case foreigns ! ModuleName.Canonical home name of
427− I.Public iface -> return (RForeign iface)
428− I.Private _ _ _ -> error $ "mistakenly seeing private interface for " ++ Pkg.toChars home ++ " " ++ ModuleName.toChars name
429−
430− SKernel ->
431− return RKernel
432−
433−
434−
435−-- CHECK DEPS
436−
437−
438−data DepsStatus
439− = DepsChange (Map.Map ModuleName.Raw I.Interface)
440− | DepsSame [Dep] [CDep]
441− | DepsBlock
442− | DepsNotFound (NE.List (ModuleName.Raw, Import.Problem))
443−
444−
445−checkDeps :: FilePath -> ResultDict -> [ModuleName.Raw] -> Details.BuildID -> IO DepsStatus
446−checkDeps root results deps lastCompile =
447− checkDepsHelp root results deps [] [] [] [] False 0 lastCompile
448−
449−
450−type Dep = (ModuleName.Raw, I.Interface)
451−type CDep = (ModuleName.Raw, MVar CachedInterface)
452−
453−
454−checkDepsHelp :: FilePath -> ResultDict -> [ModuleName.Raw] -> [Dep] -> [Dep] -> [CDep] -> [(ModuleName.Raw,Import.Problem)] -> Bool -> Details.BuildID -> Details.BuildID -> IO DepsStatus
455−checkDepsHelp root results deps new same cached importProblems isBlocked lastDepChange lastCompile =
456− case deps of
457− dep:otherDeps ->
458− do result <- readMVar (results ! dep)
459− case result of
460− RNew (Details.Local _ _ _ _ lastChange _) iface _ _ ->
461− checkDepsHelp root results otherDeps ((dep,iface) : new) same cached importProblems isBlocked (max lastChange lastDepChange) lastCompile
462−
463− RSame (Details.Local _ _ _ _ lastChange _) iface _ _ ->
464− checkDepsHelp root results otherDeps new ((dep,iface) : same) cached importProblems isBlocked (max lastChange lastDepChange) lastCompile
465−
466− RCached _ lastChange mvar ->
467− checkDepsHelp root results otherDeps new same ((dep,mvar) : cached) importProblems isBlocked (max lastChange lastDepChange) lastCompile
468−
469− RNotFound prob ->
470− checkDepsHelp root results otherDeps new same cached ((dep,prob) : importProblems) True lastDepChange lastCompile
471−
472− RProblem _ ->
473− checkDepsHelp root results otherDeps new same cached importProblems True lastDepChange lastCompile
474−
475− RBlocked ->
476− checkDepsHelp root results otherDeps new same cached importProblems True lastDepChange lastCompile
477−
478− RForeign iface ->
479− checkDepsHelp root results otherDeps new ((dep,iface) : same) cached importProblems isBlocked lastDepChange lastCompile
480−
481− RKernel ->
482− checkDepsHelp root results otherDeps new same cached importProblems isBlocked lastDepChange lastCompile
483−
484−
485− [] ->
486− case reverse importProblems of
487− p:ps ->
488− return $ DepsNotFound (NE.List p ps)
489−
490− [] ->
491− if isBlocked then
492− return $ DepsBlock
493−
494− else if null new && lastDepChange <= lastCompile then
495− return $ DepsSame same cached
496−
497− else
498− do maybeLoaded <- loadInterfaces root same cached
499− case maybeLoaded of
500− Nothing -> return DepsBlock
501− Just ifaces -> return $ DepsChange $ Map.union (Map.fromList new) ifaces
502−
503−
504−
505−-- TO IMPORT ERROR
506−
507−
508−toImportErrors :: Env -> ResultDict -> [Src.Import] -> NE.List (ModuleName.Raw, Import.Problem) -> NE.List Import.Error
509−toImportErrors (Env _ _ _ _ _ locals foreigns) results imports problems =
510− let
511− knownModules =
512− Set.unions
513− [ Map.keysSet foreigns
514− , Map.keysSet locals
515− , Map.keysSet results
516− ]
517−
518− unimportedModules =
519− Set.difference knownModules (Set.fromList (map Src.getImportName imports))
520−
521− regionDict =
522− Map.fromList (map (\(Src.Import (A.At region name) _ _) -> (name, region)) imports)
523−
524− toError (name, problem) =
525− Import.Error (regionDict ! name) name unimportedModules problem
526− in
527− fmap toError problems
528−
529−
530−
531−-- LOAD CACHED INTERFACES
532−
533−
534−loadInterfaces :: FilePath -> [Dep] -> [CDep] -> IO (Maybe (Map.Map ModuleName.Raw I.Interface))
535−loadInterfaces root same cached =
536− do loading <- traverse (fork . loadInterface root) cached
537− maybeLoaded <- traverse readMVar loading
538− case sequence maybeLoaded of
539− Nothing ->
540− return Nothing
541−
542− Just loaded ->
543− return $ Just $ Map.union (Map.fromList loaded) (Map.fromList same)
544−
545−
546−loadInterface :: FilePath -> CDep -> IO (Maybe Dep)
547−loadInterface root (name, ciMvar) =
548− do cachedInterface <- takeMVar ciMvar
549− case cachedInterface of
550− Corrupted ->
551− do putMVar ciMvar cachedInterface
552− return Nothing
553−
554− Loaded iface ->
555− do putMVar ciMvar cachedInterface
556− return (Just (name, iface))
557−
558− Unneeded ->
559− do maybeIface <- File.readBinary (Stuff.elmi root name)
560− case maybeIface of
561− Nothing ->
562− do putMVar ciMvar Corrupted
563− return Nothing
564−
565− Just iface ->
566− do putMVar ciMvar (Loaded iface)
567− return (Just (name, iface))
568−
569−
570−
571−-- CHECK PROJECT
572−
573−
574−checkMidpoint :: MVar (Maybe Dependencies) -> Map.Map ModuleName.Raw Status -> IO (Either Exit.BuildProjectProblem Dependencies)
575−checkMidpoint dmvar statuses =
576− case checkForCycles statuses of
577− Nothing ->
578− do maybeForeigns <- readMVar dmvar
579− case maybeForeigns of
580− Nothing -> return (Left Exit.BP_CannotLoadDependencies)
581− Just fs -> return (Right fs)
582−
583− Just (NE.List name names) ->
584− do _ <- readMVar dmvar
585− return (Left (Exit.BP_Cycle name names))
586−
587−
588−checkMidpointAndRoots :: MVar (Maybe Dependencies) -> Map.Map ModuleName.Raw Status -> NE.List RootStatus -> IO (Either Exit.BuildProjectProblem Dependencies)
589−checkMidpointAndRoots dmvar statuses sroots =
590− case checkForCycles statuses of
591− Nothing ->
592− case checkUniqueRoots statuses sroots of
593− Nothing ->
594− do maybeForeigns <- readMVar dmvar
595− case maybeForeigns of
596− Nothing -> return (Left Exit.BP_CannotLoadDependencies)
597− Just fs -> return (Right fs)
598−
599− Just problem ->
600− do _ <- readMVar dmvar
601− return (Left problem)
602−
603− Just (NE.List name names) ->
604− do _ <- readMVar dmvar
605− return (Left (Exit.BP_Cycle name names))
606−
607−
608−
609−-- CHECK FOR CYCLES
610−
611−
612−checkForCycles :: Map.Map ModuleName.Raw Status -> Maybe (NE.List ModuleName.Raw)
613−checkForCycles modules =
614− let
615− !graph = Map.foldrWithKey addToGraph [] modules
616− !sccs = Graph.stronglyConnComp graph
617− in
618− checkForCyclesHelp sccs
619−
620−
621−checkForCyclesHelp :: [Graph.SCC ModuleName.Raw] -> Maybe (NE.List ModuleName.Raw)
622−checkForCyclesHelp sccs =
623− case sccs of
624− [] ->
625− Nothing
626−
627− scc:otherSccs ->
628− case scc of
629− Graph.AcyclicSCC _ -> checkForCyclesHelp otherSccs
630− Graph.CyclicSCC [] -> checkForCyclesHelp otherSccs
631− Graph.CyclicSCC (m:ms) -> Just (NE.List m ms)
632−
633−
634−type Node =
635− ( ModuleName.Raw, ModuleName.Raw, [ModuleName.Raw] )
636−
637−
638−addToGraph :: ModuleName.Raw -> Status -> [Node] -> [Node]
639−addToGraph name status graph =
640− let
641− dependencies =
642− case status of
643− SCached (Details.Local _ _ deps _ _ _) -> deps
644− SChanged (Details.Local _ _ deps _ _ _) _ _ _ -> deps
645− SBadImport _ -> []
646− SBadSyntax _ _ _ _ -> []
647− SForeign _ -> []
648− SKernel -> []
649− in
650− (name, name, dependencies) : graph
651−
652−
653−
654−-- CHECK UNIQUE ROOTS
655−
656−
657−checkUniqueRoots :: Map.Map ModuleName.Raw Status -> NE.List RootStatus -> Maybe Exit.BuildProjectProblem
658−checkUniqueRoots insides sroots =
659− let
660− outsidesDict =
661− Map.fromListWith OneOrMore.more (Maybe.mapMaybe rootStatusToNamePathPair (NE.toList sroots))
662− in
663− case Map.traverseWithKey checkOutside outsidesDict of
664− Left problem ->
665− Just problem
666−
667− Right outsides ->
668− case sequence_ (Map.intersectionWithKey checkInside outsides insides) of
669− Right () -> Nothing
670− Left problem -> Just problem
671−
672−
673−rootStatusToNamePathPair :: RootStatus -> Maybe (ModuleName.Raw, OneOrMore.OneOrMore FilePath)
674−rootStatusToNamePathPair sroot =
675− case sroot of
676− SInside _ -> Nothing
677− SOutsideOk (Details.Local path _ _ _ _ _) _ modul -> Just (Src.getName modul, OneOrMore.one path)
678− SOutsideErr _ -> Nothing
679−
680−
681−checkOutside :: ModuleName.Raw -> OneOrMore.OneOrMore FilePath -> Either Exit.BuildProjectProblem FilePath
682−checkOutside name paths =
683− case OneOrMore.destruct NE.List paths of
684− NE.List p [] -> Right p
685− NE.List p1 (p2:_) -> Left (Exit.BP_RootNameDuplicate name p1 p2)
686−
687−
688−checkInside :: ModuleName.Raw -> FilePath -> Status -> Either Exit.BuildProjectProblem ()
689−checkInside name p1 status =
690− case status of
691− SCached (Details.Local p2 _ _ _ _ _) -> Left (Exit.BP_RootNameDuplicate name p1 p2)
692− SChanged (Details.Local p2 _ _ _ _ _) _ _ _ -> Left (Exit.BP_RootNameDuplicate name p1 p2)
693− SBadImport _ -> Right ()
694− SBadSyntax _ _ _ _ -> Right ()
695− SForeign _ -> Right ()
696− SKernel -> Right ()
697−
698−
699−
700−-- COMPILE MODULE
701−
702−
703−compile :: Env -> DocsNeed -> Details.Local -> B.ByteString -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> IO Result
704−compile (Env key root projectType _ buildID _ _) docsNeed (Details.Local path time deps main lastChange _) source ifaces modul =
705− let
706− pkg = projectTypeToPkg projectType
707− in
708− case Compile.compile pkg ifaces modul of
709− Right (Compile.Artifacts canonical annotations objects) ->
710− case makeDocs docsNeed canonical of
711− Left err ->
712− return $ RProblem $
713− Error.Module (Src.getName modul) path time source (Error.BadDocs err)
714−
715− Right docs ->
716− do let name = Src.getName modul
717− let iface = I.fromModule pkg canonical annotations
718− let elmi = Stuff.elmi root name
719− File.writeBinary (Stuff.elmo root name) objects
720− maybeOldi <- File.readBinary elmi
721− case maybeOldi of
722− Just oldi | oldi == iface ->
723− do -- iface should be fully forced by equality check
724− Reporting.report key Reporting.BDone
725− let local = Details.Local path time deps main lastChange buildID
726− return (RSame local iface objects docs)
727−
728− _ ->
729− do -- iface may be lazy still
730− File.writeBinary elmi iface
731− Reporting.report key Reporting.BDone
732− let local = Details.Local path time deps main buildID buildID
733− return (RNew local iface objects docs)
734−
735− Left err ->
736− return $ RProblem $
737− Error.Module (Src.getName modul) path time source err
738−
739−
740−projectTypeToPkg :: Parse.ProjectType -> Pkg.Name
741−projectTypeToPkg projectType =
742− case projectType of
743− Parse.Package pkg -> pkg
744− Parse.Application -> Pkg.dummyName
745−
746−
747−
748−-- WRITE DETAILS
749−
750−
751−writeDetails :: FilePath -> Details.Details -> Map.Map ModuleName.Raw Result -> IO ()
752−writeDetails root (Details.Details time outline buildID locals foreigns extras) results =
753− File.writeBinary (Stuff.details root) $
754− Details.Details time outline buildID (Map.foldrWithKey addNewLocal locals results) foreigns extras
755−
756−
757−addNewLocal :: ModuleName.Raw -> Result -> Map.Map ModuleName.Raw Details.Local -> Map.Map ModuleName.Raw Details.Local
758−addNewLocal name result locals =
759− case result of
760− RNew local _ _ _ -> Map.insert name local locals
761− RSame local _ _ _ -> Map.insert name local locals
762− RCached _ _ _ -> locals
763− RNotFound _ -> locals
764− RProblem _ -> locals
765− RBlocked -> locals
766− RForeign _ -> locals
767− RKernel -> locals
768−
769−
770−
771−-- FINALIZE EXPOSED
772−
773−
774−finalizeExposed :: FilePath -> DocsGoal docs -> NE.List ModuleName.Raw -> Map.Map ModuleName.Raw Result -> IO (Either Exit.BuildProblem docs)
775−finalizeExposed root docsGoal exposed results =
776− case foldr (addImportProblems results) [] (NE.toList exposed) of
777− p:ps ->
778− return $ Left $ Exit.BuildProjectProblem (Exit.BP_MissingExposed (NE.List p ps))
779−
780− [] ->
781− case Map.foldr addErrors [] results of
782− [] -> Right <$> finalizeDocs docsGoal results
783− e:es -> return $ Left $ Exit.BuildBadModules root e es
784−
785−
786−addErrors :: Result -> [Error.Module] -> [Error.Module]
787−addErrors result errors =
788− case result of
789− RNew _ _ _ _ -> errors
790− RSame _ _ _ _ -> errors
791− RCached _ _ _ -> errors
792− RNotFound _ -> errors
793− RProblem e -> e:errors
794− RBlocked -> errors
795− RForeign _ -> errors
796− RKernel -> errors
797−
798−
799−addImportProblems :: Map.Map ModuleName.Raw Result -> ModuleName.Raw -> [(ModuleName.Raw, Import.Problem)] -> [(ModuleName.Raw, Import.Problem)]
800−addImportProblems results name problems =
801− case results ! name of
802− RNew _ _ _ _ -> problems
803− RSame _ _ _ _ -> problems
804− RCached _ _ _ -> problems
805− RNotFound p -> (name, p) : problems
806− RProblem _ -> problems
807− RBlocked -> problems
808− RForeign _ -> problems
809− RKernel -> problems
810−
811−
812−
813−-- DOCS
814−
815−
816−data DocsGoal a where
817− KeepDocs :: DocsGoal Docs.Documentation
818− WriteDocs :: FilePath -> DocsGoal ()
819− IgnoreDocs :: DocsGoal ()
820−
821−
822−newtype DocsNeed =
823− DocsNeed { needsDocs :: Bool }
824−
825−
826−toDocsNeed :: DocsGoal a -> DocsNeed
827−toDocsNeed goal =
828− case goal of
829− IgnoreDocs -> DocsNeed False
830− WriteDocs _ -> DocsNeed True
831− KeepDocs -> DocsNeed True
832−
833−
834−makeDocs :: DocsNeed -> Can.Module -> Either EDocs.Error (Maybe Docs.Module)
835−makeDocs (DocsNeed isNeeded) modul =
836− if isNeeded then
837− case Docs.fromModule modul of
838− Right docs -> Right (Just docs)
839− Left err -> Left err
840− else
841− Right Nothing
842−
843−
844−finalizeDocs :: DocsGoal docs -> Map.Map ModuleName.Raw Result -> IO docs
845−finalizeDocs goal results =
846− case goal of
847− KeepDocs ->
848− return $ Map.mapMaybe toDocs results
849−
850− WriteDocs path ->
851− E.writeUgly path $ Docs.encode $ Map.mapMaybe toDocs results
852−
853− IgnoreDocs ->
854− return ()
855−
856−
857−toDocs :: Result -> Maybe Docs.Module
858−toDocs result =
859− case result of
860− RNew _ _ _ d -> d
861− RSame _ _ _ d -> d
862− RCached _ _ _ -> Nothing
863− RNotFound _ -> Nothing
864− RProblem _ -> Nothing
865− RBlocked -> Nothing
866− RForeign _ -> Nothing
867− RKernel -> Nothing
868−
869−
870−
871−--------------------------------------------------------------------------------
872−------ NOW FOR SOME REPL STUFF -------------------------------------------------
873−--------------------------------------------------------------------------------
874−
875−
876−-- FROM REPL
877−
878−
879−data ReplArtifacts =
880− ReplArtifacts
881− { _repl_home :: ModuleName.Canonical
882− , _repl_modules :: [Module]
883− , _repl_localizer :: L.Localizer
884− , _repl_annotations :: Map.Map Name.Name Can.Annotation
885− }
886−
887−
888−fromRepl :: FilePath -> Details.Details -> B.ByteString -> IO (Either Exit.Repl ReplArtifacts)
889−fromRepl root details source =
890− do env@(Env _ _ projectType _ _ _ _) <- makeEnv Reporting.ignorer root details
891− case Parse.fromByteString projectType source of
892− Left syntaxError ->
893− return $ Left $ Exit.ReplBadInput source $ Error.BadSyntax syntaxError
894−
895− Right modul@(Src.Module _ _ _ imports _ _ _ _ _) ->
896− do dmvar <- Details.loadInterfaces root details
897−
898− let deps = map Src.getImportName imports
899− mvar <- newMVar Map.empty
900− crawlDeps env mvar deps ()
901−
902− statuses <- traverse readMVar =<< readMVar mvar
903− midpoint <- checkMidpoint dmvar statuses
904−
905− case midpoint of
906− Left problem ->
907− return $ Left $ Exit.ReplProjectProblem problem
908−
909− Right foreigns ->
910− do rmvar <- newEmptyMVar
911− resultMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
912− putMVar rmvar resultMVars
913− results <- traverse readMVar resultMVars
914− writeDetails root details results
915− depsStatus <- checkDeps root resultMVars deps 0
916− finalizeReplArtifacts env source modul depsStatus resultMVars results
917−
918−
919−finalizeReplArtifacts :: Env -> B.ByteString -> Src.Module -> DepsStatus -> ResultDict -> Map.Map ModuleName.Raw Result -> IO (Either Exit.Repl ReplArtifacts)
920−finalizeReplArtifacts env@(Env _ root projectType _ _ _ _) source modul@(Src.Module _ _ _ imports _ _ _ _ _) depsStatus resultMVars results =
921− let
922− pkg =
923− projectTypeToPkg projectType
924−
925− compileInput ifaces =
926− case Compile.compile pkg ifaces modul of
927− Right (Compile.Artifacts canonical annotations objects) ->
928− let
929− h = Can._name canonical
930− m = Fresh (Src.getName modul) (I.fromModule pkg canonical annotations) objects
931− ms = Map.foldrWithKey addInside [] results
932− in
933− return $ Right $ ReplArtifacts h (m:ms) (L.fromModule modul) annotations
934−
935− Left errors ->
936− return $ Left $ Exit.ReplBadInput source errors
937− in
938− case depsStatus of
939− DepsChange ifaces ->
940− compileInput ifaces
941−
942− DepsSame same cached ->
943− do maybeLoaded <- loadInterfaces root same cached
944− case maybeLoaded of
945− Just ifaces -> compileInput ifaces
946− Nothing -> return $ Left $ Exit.ReplBadCache
947−
948− DepsBlock ->
949− case Map.foldr addErrors [] results of
950− [] -> return $ Left $ Exit.ReplBlocked
951− e:es -> return $ Left $ Exit.ReplBadLocalDeps root e es
952−
953− DepsNotFound problems ->
954− return $ Left $ Exit.ReplBadInput source $ Error.BadImports $
955− toImportErrors env resultMVars imports problems
956−
957−
958−
959−--------------------------------------------------------------------------------
960−--------------------------------------------------------------------------------
961−------ AFTER THIS, EVERYTHING IS ABOUT HANDLING MODULES GIVEN BY FILEPATH ------
962−--------------------------------------------------------------------------------
963−--------------------------------------------------------------------------------
964−
965−
966−
967−-- FIND ROOT
968−
969−
970−data RootLocation
971− = LInside ModuleName.Raw
972− | LOutside FilePath
973−
974−
975−findRoots :: Env -> NE.List FilePath -> IO (Either Exit.BuildProjectProblem (NE.List RootLocation))
976−findRoots env paths =
977− do mvars <- traverse (fork . getRootInfo env) paths
978− einfos <- traverse readMVar mvars
979− return $ checkRoots =<< sequence einfos
980−
981−
982−checkRoots :: NE.List RootInfo -> Either Exit.BuildProjectProblem (NE.List RootLocation)
983−checkRoots infos =
984− let
985− toOneOrMore loc@(RootInfo absolute _ _) =
986− (absolute, OneOrMore.one loc)
987−
988− fromOneOrMore loc locs =
989− case locs of
990− [] -> Right ()
991− loc2:_ -> Left (Exit.BP_MainPathDuplicate (_relative loc) (_relative loc2))
992− in
993− fmap (\_ -> fmap _location infos) $
994− traverse (OneOrMore.destruct fromOneOrMore) $
995− Map.fromListWith OneOrMore.more $ map toOneOrMore (NE.toList infos)
996−
997−
998−
999−-- ROOT INFO
1000−
1001−
1002−data RootInfo =
1003− RootInfo
1004− { _absolute :: FilePath
1005− , _relative :: FilePath
1006− , _location :: RootLocation
1007− }
1008−
1009−
1010−getRootInfo :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem RootInfo)
1011−getRootInfo env path =
1012− do exists <- File.exists path
1013− if exists
1014− then getRootInfoHelp env path =<< Dir.canonicalizePath path
1015− else return (Left (Exit.BP_PathUnknown path))
1016−
1017−
1018−getRootInfoHelp :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem RootInfo)
1019−getRootInfoHelp (Env _ _ _ srcDirs _ _ _) path absolutePath =
1020− let
1021− (dirs, file) = FP.splitFileName absolutePath
1022− (final, ext) = FP.splitExtension file
1023− in
1024− if ext /= ".elm"
1025− then
1026− return $ Left $ Exit.BP_WithBadExtension path
1027− else
1028− let
1029− absoluteSegments = FP.splitDirectories dirs ++ [final]
1030− in
1031− case Maybe.mapMaybe (isInsideSrcDirByPath absoluteSegments) srcDirs of
1032− [] ->
1033− return $ Right $ RootInfo absolutePath path (LOutside path)
1034−
1035− [(_, Right names)] ->
1036− do let name = Name.fromChars (List.intercalate "." names)
1037− matchingDirs <- filterM (isInsideSrcDirByName names) srcDirs
1038− case matchingDirs of
1039− d1:d2:_ ->
1040− do let p1 = addRelative d1 (FP.joinPath names <.> "elm")
1041− let p2 = addRelative d2 (FP.joinPath names <.> "elm")
1042− return $ Left $ Exit.BP_RootNameDuplicate name p1 p2
1043−
1044− _ ->
1045− return $ Right $ RootInfo absolutePath path (LInside name)
1046−
1047− [(s, Left names)] ->
1048− return $ Left $ Exit.BP_RootNameInvalid path s names
1049−
1050− (s1,_):(s2,_):_ ->
1051− return $ Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
1052−
1053−
1054−
1055−isInsideSrcDirByName :: [String] -> AbsoluteSrcDir -> IO Bool
1056−isInsideSrcDirByName names srcDir =
1057− File.exists (addRelative srcDir (FP.joinPath names <.> "elm"))
1058−
1059−
1060−isInsideSrcDirByPath :: [String] -> AbsoluteSrcDir -> Maybe (FilePath, Either [String] [String])
1061−isInsideSrcDirByPath segments (AbsoluteSrcDir srcDir) =
1062− case dropPrefix (FP.splitDirectories srcDir) segments of
1063− Nothing ->
1064− Nothing
1065−
1066− Just names ->
1067− if all isGoodName names
1068− then Just (srcDir, Right names)
1069− else Just (srcDir, Left names)
1070−
1071−
1072−isGoodName :: [Char] -> Bool
1073−isGoodName name =
1074− case name of
1075− [] ->
1076− False
1077−
1078− char:chars ->
1079− Char.isUpper char && all (\c -> Char.isAlphaNum c || c == '_') chars
1080−
1081−
1082−-- INVARIANT: Dir.canonicalizePath has been run on both inputs
1083−--
1084−dropPrefix :: [FilePath] -> [FilePath] -> Maybe [FilePath]
1085−dropPrefix roots paths =
1086− case roots of
1087− [] ->
1088− Just paths
1089−
1090− r:rs ->
1091− case paths of
1092− [] -> Nothing
1093− p:ps -> if r == p then dropPrefix rs ps else Nothing
1094−
1095−
1096−
1097−-- CRAWL ROOTS
1098−
1099−
1100−data RootStatus
1101− = SInside ModuleName.Raw
1102− | SOutsideOk Details.Local B.ByteString Src.Module
1103− | SOutsideErr Error.Module
1104−
1105−
1106−crawlRoot :: Env -> MVar StatusDict -> RootLocation -> IO RootStatus
1107−crawlRoot env@(Env _ _ projectType _ buildID _ _) mvar root =
1108− case root of
1109− LInside name ->
1110− do statusMVar <- newEmptyMVar
1111− statusDict <- takeMVar mvar
1112− putMVar mvar (Map.insert name statusMVar statusDict)
1113− putMVar statusMVar =<< crawlModule env mvar (DocsNeed False) name
1114− return (SInside name)
1115−
1116− LOutside path ->
1117− do time <- File.getTime path
1118− source <- File.readUtf8 path
1119− case Parse.fromByteString projectType source of
1120− Right modul@(Src.Module _ _ _ imports values _ _ _ _) ->
1121− do let deps = map Src.getImportName imports
1122− let local = Details.Local path time deps (any isMain values) buildID buildID
1123− crawlDeps env mvar deps (SOutsideOk local source modul)
1124−
1125− Left syntaxError ->
1126− return $ SOutsideErr $
1127− Error.Module "???" path time source (Error.BadSyntax syntaxError)
1128−
1129−
1130−
1131−-- CHECK ROOTS
1132−
1133−
1134−data RootResult
1135− = RInside ModuleName.Raw
1136− | ROutsideOk ModuleName.Raw I.Interface Opt.LocalGraph
1137− | ROutsideErr Error.Module
1138− | ROutsideBlocked
1139−
1140−
1141−checkRoot :: Env -> ResultDict -> RootStatus -> IO RootResult
1142−checkRoot env@(Env _ root _ _ _ _ _) results rootStatus =
1143− case rootStatus of
1144− SInside name ->
1145− return (RInside name)
1146−
1147− SOutsideErr err ->
1148− return (ROutsideErr err)
1149−
1150− SOutsideOk local@(Details.Local path time deps _ _ lastCompile) source modul@(Src.Module _ _ _ imports _ _ _ _ _) ->
1151− do depsStatus <- checkDeps root results deps lastCompile
1152− case depsStatus of
1153− DepsChange ifaces ->
1154− compileOutside env local source ifaces modul
1155−
1156− DepsSame same cached ->
1157− do maybeLoaded <- loadInterfaces root same cached
1158− case maybeLoaded of
1159− Nothing -> return ROutsideBlocked
1160− Just ifaces -> compileOutside env local source ifaces modul
1161−
1162− DepsBlock ->
1163− return ROutsideBlocked
1164−
1165− DepsNotFound problems ->
1166− return $ ROutsideErr $ Error.Module (Src.getName modul) path time source $
1167− Error.BadImports (toImportErrors env results imports problems)
1168−
1169−
1170−compileOutside :: Env -> Details.Local -> B.ByteString -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> IO RootResult
1171−compileOutside (Env key _ projectType _ _ _ _) (Details.Local path time _ _ _ _) source ifaces modul =
1172− let
1173− pkg = projectTypeToPkg projectType
1174− name = Src.getName modul
1175− in
1176− case Compile.compile pkg ifaces modul of
1177− Right (Compile.Artifacts canonical annotations objects) ->
1178− do Reporting.report key Reporting.BDone
1179− return $ ROutsideOk name (I.fromModule pkg canonical annotations) objects
1180−
1181− Left errors ->
1182− return $ ROutsideErr $ Error.Module name path time source errors
1183−
1184−
1185−
1186−-- TO ARTIFACTS
1187−
1188−
1189−data Root
1190− = Inside ModuleName.Raw
1191− | Outside ModuleName.Raw I.Interface Opt.LocalGraph
1192−
1193−
1194−toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List RootResult -> Either Exit.BuildProblem Artifacts
1195−toArtifacts (Env _ root projectType _ _ _ _) foreigns results rootResults =
1196− case gatherProblemsOrMains results rootResults of
1197− Left (NE.List e es) ->
1198− Left (Exit.BuildBadModules root e es)
1199−
1200− Right roots ->
1201− Right $ Artifacts (projectTypeToPkg projectType) foreigns roots $
1202− Map.foldrWithKey addInside (foldr addOutside [] rootResults) results
1203−
1204−
1205−gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List RootResult -> Either (NE.List Error.Module) (NE.List Root)
1206−gatherProblemsOrMains results (NE.List rootResult rootResults) =
1207− let
1208− addResult result (es, roots) =
1209− case result of
1210− RInside n -> ( es, Inside n : roots)
1211− ROutsideOk n i o -> ( es, Outside n i o : roots)
1212− ROutsideErr e -> (e:es, roots)
1213− ROutsideBlocked -> ( es, roots)
1214−
1215− errors = Map.foldr addErrors [] results
1216− in
1217− case (rootResult, foldr addResult (errors, []) rootResults) of
1218− (RInside n , ( [], ms)) -> Right (NE.List (Inside n) ms)
1219− (RInside _ , (e:es, _ )) -> Left (NE.List e es)
1220− (ROutsideOk n i o, ( [], ms)) -> Right (NE.List (Outside n i o) ms)
1221− (ROutsideOk _ _ _, (e:es, _ )) -> Left (NE.List e es)
1222− (ROutsideErr e , ( es, _ )) -> Left (NE.List e es)
1223− (ROutsideBlocked , ( [], _ )) -> error "seems like elm-stuff/ is corrupted"
1224− (ROutsideBlocked , (e:es, _ )) -> Left (NE.List e es)
1225−
1226−
1227−addInside :: ModuleName.Raw -> Result -> [Module] -> [Module]
1228−addInside name result modules =
1229− case result of
1230− RNew _ iface objs _ -> Fresh name iface objs : modules
1231− RSame _ iface objs _ -> Fresh name iface objs : modules
1232− RCached main _ mvar -> Cached name main mvar : modules
1233− RNotFound _ -> error (badInside name)
1234− RProblem _ -> error (badInside name)
1235− RBlocked -> error (badInside name)
1236− RForeign _ -> modules
1237− RKernel -> modules
1238−
1239−
1240−badInside :: ModuleName.Raw -> [Char]
1241−badInside name =
1242− "Error from `" ++ Name.toChars name ++ "` should have been reported already."
1243−
1244−
1245−addOutside :: RootResult -> [Module] -> [Module]
1246−addOutside root modules =
1247− case root of
1248− RInside _ -> modules
1249− ROutsideOk name iface objs -> Fresh name iface objs : modules
1250− ROutsideErr _ -> modules
1251− ROutsideBlocked -> modules
builder/src/Deps/Bump.hsdeleted−37
@@ -1,37 +0,0 @@
1−module Deps.Bump
2− ( getPossibilities
3− )
4− where
5−
6−
7−import qualified Data.List as List
8−
9−import qualified Deps.Registry as Registry
10−import qualified Elm.Magnitude as M
11−import qualified Elm.Version as V
12−
13−
14−
15−-- GET POSSIBILITIES
16−
17−
18−getPossibilities :: Registry.KnownVersions -> [(V.Version, V.Version, M.Magnitude)]
19−getPossibilities (Registry.KnownVersions latest previous) =
20− let
21− allVersions = reverse (latest:previous)
22− minorPoints = map last (List.groupBy sameMajor allVersions)
23− patchPoints = map last (List.groupBy sameMinor allVersions)
24− in
25− (latest, V.bumpMajor latest, M.MAJOR)
26− : map (\v -> (v, V.bumpMinor v, M.MINOR)) minorPoints
27− ++ map (\v -> (v, V.bumpPatch v, M.PATCH)) patchPoints
28−
29−
30−sameMajor :: V.Version -> V.Version -> Bool
31−sameMajor (V.Version major1 _ _) (V.Version major2 _ _) =
32− major1 == major2
33−
34−
35−sameMinor :: V.Version -> V.Version -> Bool
36−sameMinor (V.Version major1 minor1 _) (V.Version major2 minor2 _) =
37− major1 == major2 && minor1 == minor2
builder/src/Deps/Diff.hsdeleted−383
@@ -1,383 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Deps.Diff
3− ( diff
4− , PackageChanges(..)
5− , ModuleChanges(..)
6− , Changes(..)
7− , moduleChangeMagnitude
8− , toMagnitude
9− , bump
10− , getDocs
11− )
12− where
13−
14−
15−import Control.Monad (zipWithM)
16−import Data.Function (on)
17−import qualified Data.List as List
18−import qualified Data.Map as Map
19−import qualified Data.Name as Name
20−import qualified Data.Set as Set
21−import qualified System.Directory as Dir
22−import System.FilePath ((</>))
23−
24−import qualified Deps.Website as Website
25−import qualified Elm.Compiler.Type as Type
26−import qualified Elm.Docs as Docs
27−import qualified Elm.Magnitude as M
28−import qualified Elm.ModuleName as ModuleName
29−import qualified Elm.Package as Pkg
30−import qualified Elm.Version as V
31−import qualified File
32−import qualified Http
33−import qualified Json.Decode as D
34−import qualified Reporting.Exit as Exit
35−import qualified Stuff
36−
37−
38−
39−-- CHANGES
40−
41−
42−data PackageChanges =
43− PackageChanges
44− { _modules_added :: [ModuleName.Raw]
45− , _modules_changed :: Map.Map ModuleName.Raw ModuleChanges
46− , _modules_removed :: [ModuleName.Raw]
47− }
48−
49−
50−data ModuleChanges =
51− ModuleChanges
52− { _unions :: Changes Name.Name Docs.Union
53− , _aliases :: Changes Name.Name Docs.Alias
54− , _values :: Changes Name.Name Docs.Value
55− , _binops :: Changes Name.Name Docs.Binop
56− }
57−
58−
59−data Changes k v =
60− Changes
61− { _added :: Map.Map k v
62− , _changed :: Map.Map k (v,v)
63− , _removed :: Map.Map k v
64− }
65−
66−
67−getChanges :: (Ord k) => (v -> v -> Bool) -> Map.Map k v -> Map.Map k v -> Changes k v
68−getChanges isEquivalent old new =
69− let
70− overlap = Map.intersectionWith (,) old new
71− changed = Map.filter (not . uncurry isEquivalent) overlap
72− in
73− Changes (Map.difference new old) changed (Map.difference old new)
74−
75−
76−
77−-- DIFF
78−
79−
80−diff :: Docs.Documentation -> Docs.Documentation -> PackageChanges
81−diff oldDocs newDocs =
82− let
83− filterOutPatches chngs =
84− Map.filter (\chng -> moduleChangeMagnitude chng /= M.PATCH) chngs
85−
86− (Changes added changed removed) =
87− getChanges (\_ _ -> False) oldDocs newDocs
88− in
89− PackageChanges
90− (Map.keys added)
91− (filterOutPatches (Map.map diffModule changed))
92− (Map.keys removed)
93−
94−
95−
96−diffModule :: (Docs.Module, Docs.Module) -> ModuleChanges
97−diffModule (Docs.Module _ _ u1 a1 v1 b1, Docs.Module _ _ u2 a2 v2 b2) =
98− ModuleChanges
99− (getChanges isEquivalentUnion u1 u2)
100− (getChanges isEquivalentAlias a1 a2)
101− (getChanges isEquivalentValue v1 v2)
102− (getChanges isEquivalentBinop b1 b2)
103−
104−
105−
106−-- EQUIVALENCE
107−
108−
109−isEquivalentUnion :: Docs.Union -> Docs.Union -> Bool
110−isEquivalentUnion (Docs.Union oldComment oldVars oldCtors) (Docs.Union newComment newVars newCtors) =
111− length oldCtors == length newCtors
112− && and (zipWith (==) (map fst oldCtors) (map fst newCtors))
113− && and (Map.elems (Map.intersectionWith equiv (Map.fromList oldCtors) (Map.fromList newCtors)))
114− where
115− equiv :: [Type.Type] -> [Type.Type] -> Bool
116− equiv oldTypes newTypes =
117− let
118− allEquivalent =
119− zipWith
120− isEquivalentAlias
121− (map (Docs.Alias oldComment oldVars) oldTypes)
122− (map (Docs.Alias newComment newVars) newTypes)
123− in
124− length oldTypes == length newTypes
125− && and allEquivalent
126−
127−
128−isEquivalentAlias :: Docs.Alias -> Docs.Alias -> Bool
129−isEquivalentAlias (Docs.Alias _ oldVars oldType) (Docs.Alias _ newVars newType) =
130− case diffType oldType newType of
131− Nothing ->
132− False
133−
134− Just renamings ->
135− length oldVars == length newVars
136− && isEquivalentRenaming (zip oldVars newVars ++ renamings)
137−
138−
139−isEquivalentValue :: Docs.Value -> Docs.Value -> Bool
140−isEquivalentValue (Docs.Value c1 t1) (Docs.Value c2 t2) =
141− isEquivalentAlias (Docs.Alias c1 [] t1) (Docs.Alias c2 [] t2)
142−
143−
144−isEquivalentBinop :: Docs.Binop -> Docs.Binop -> Bool
145−isEquivalentBinop (Docs.Binop c1 t1 a1 p1) (Docs.Binop c2 t2 a2 p2) =
146− isEquivalentAlias (Docs.Alias c1 [] t1) (Docs.Alias c2 [] t2)
147− && a1 == a2
148− && p1 == p2
149−
150−
151−
152−-- DIFF TYPES
153−
154−
155−diffType :: Type.Type -> Type.Type -> Maybe [(Name.Name,Name.Name)]
156−diffType oldType newType =
157− case (oldType, newType) of
158− (Type.Var oldName, Type.Var newName) ->
159− Just [(oldName, newName)]
160−
161− (Type.Lambda a b, Type.Lambda a' b') ->
162− (++)
163− <$> diffType a a'
164− <*> diffType b b'
165−
166− (Type.Type oldName oldArgs, Type.Type newName newArgs) ->
167− if not (isSameName oldName newName) || length oldArgs /= length newArgs then
168− Nothing
169− else
170− concat <$> zipWithM diffType oldArgs newArgs
171−
172− (Type.Record fields maybeExt, Type.Record fields' maybeExt') ->
173− case (maybeExt, maybeExt') of
174− (Nothing, Just _) ->
175− Nothing
176−
177− (Just _, Nothing) ->
178− Nothing
179−
180− (Nothing, Nothing) ->
181− diffFields fields fields'
182−
183− (Just oldExt, Just newExt) ->
184− (:) (oldExt, newExt) <$> diffFields fields fields'
185−
186− (Type.Unit, Type.Unit) ->
187− Just []
188−
189− (Type.Tuple a b cs, Type.Tuple x y zs) ->
190− if length cs /= length zs then
191− Nothing
192− else
193− do aVars <- diffType a x
194− bVars <- diffType b y
195− cVars <- concat <$> zipWithM diffType cs zs
196− return (aVars ++ bVars ++ cVars)
197−
198− (_, _) ->
199− Nothing
200−
201−
202−-- handle very old docs that do not use qualified names
203−isSameName :: Name.Name -> Name.Name -> Bool
204−isSameName oldFullName newFullName =
205− let
206− dedot name =
207− reverse (Name.splitDots name)
208− in
209− case ( dedot oldFullName, dedot newFullName ) of
210− (oldName:[], newName:_) ->
211− oldName == newName
212−
213− (oldName:_, newName:[]) ->
214− oldName == newName
215−
216− _ ->
217− oldFullName == newFullName
218−
219−
220−diffFields :: [(Name.Name, Type.Type)] -> [(Name.Name, Type.Type)] -> Maybe [(Name.Name,Name.Name)]
221−diffFields oldRawFields newRawFields =
222− let
223− sort = List.sortBy (compare `on` fst)
224− oldFields = sort oldRawFields
225− newFields = sort newRawFields
226− in
227− if length oldRawFields /= length newRawFields then
228− Nothing
229−
230− else if or (zipWith ((/=) `on` fst) oldFields newFields) then
231− Nothing
232−
233− else
234− concat <$> zipWithM (diffType `on` snd) oldFields newFields
235−
236−
237−
238−-- TYPE VARIABLES
239−
240−
241−isEquivalentRenaming :: [(Name.Name,Name.Name)] -> Bool
242−isEquivalentRenaming varPairs =
243− let
244− renamings =
245− Map.toList (foldr insert Map.empty varPairs)
246−
247− insert (old,new) dict =
248− Map.insertWith (++) old [new] dict
249−
250− verify (old, news) =
251− case news of
252− [] ->
253− Nothing
254−
255− new : rest ->
256− if all (new ==) rest then
257− Just (old, new)
258− else
259− Nothing
260−
261− allUnique list =
262− length list == Set.size (Set.fromList list)
263− in
264− case mapM verify renamings of
265− Nothing ->
266− False
267−
268− Just verifiedRenamings ->
269− all compatibleVars verifiedRenamings
270− &&
271− allUnique (map snd verifiedRenamings)
272−
273−
274−compatibleVars :: (Name.Name, Name.Name) -> Bool
275−compatibleVars (old, new) =
276− case (categorizeVar old, categorizeVar new) of
277− (CompAppend, CompAppend) -> True
278− (Comparable, Comparable) -> True
279− (Appendable, Appendable) -> True
280− (Number , Number ) -> True
281− (Number , Comparable) -> True
282−
283− (_, Var) -> True
284−
285− (_, _) -> False
286−
287−
288−data TypeVarCategory
289− = CompAppend
290− | Comparable
291− | Appendable
292− | Number
293− | Var
294−
295−
296−categorizeVar :: Name.Name -> TypeVarCategory
297−categorizeVar name
298− | Name.isCompappendType name = CompAppend
299− | Name.isComparableType name = Comparable
300− | Name.isAppendableType name = Appendable
301− | Name.isNumberType name = Number
302− | otherwise = Var
303−
304−
305−
306−-- MAGNITUDE
307−
308−
309−bump :: PackageChanges -> V.Version -> V.Version
310−bump changes version =
311− case toMagnitude changes of
312− M.PATCH ->
313− V.bumpPatch version
314−
315− M.MINOR ->
316− V.bumpMinor version
317−
318− M.MAJOR ->
319− V.bumpMajor version
320−
321−
322−toMagnitude :: PackageChanges -> M.Magnitude
323−toMagnitude (PackageChanges added changed removed) =
324− let
325− addMag = if null added then M.PATCH else M.MINOR
326− removeMag = if null removed then M.PATCH else M.MAJOR
327− changeMags = map moduleChangeMagnitude (Map.elems changed)
328− in
329− maximum (addMag : removeMag : changeMags)
330−
331−
332−moduleChangeMagnitude :: ModuleChanges -> M.Magnitude
333−moduleChangeMagnitude (ModuleChanges unions aliases values binops) =
334− maximum
335− [ changeMagnitude unions
336− , changeMagnitude aliases
337− , changeMagnitude values
338− , changeMagnitude binops
339− ]
340−
341−
342−changeMagnitude :: Changes k v -> M.Magnitude
343−changeMagnitude (Changes added changed removed) =
344− if Map.size removed > 0 || Map.size changed > 0 then
345− M.MAJOR
346−
347− else if Map.size added > 0 then
348− M.MINOR
349−
350− else
351− M.PATCH
352−
353−
354−
355−-- GET DOCS
356−
357−
358−getDocs :: Stuff.PackageCache -> Http.Manager -> Pkg.Name -> V.Version -> IO (Either Exit.DocsProblem Docs.Documentation)
359−getDocs cache manager name version =
360− do let home = Stuff.package cache name version
361− let path = home </> "docs.json"
362− exists <- File.exists path
363− if exists
364− then
365− do bytes <- File.readUtf8 path
366− case D.fromByteString Docs.decoder bytes of
367− Right docs ->
368− return $ Right docs
369−
370− Left _ ->
371− do File.remove path
372− return $ Left Exit.DP_Cache
373− else
374− do let url = Website.metadata name version "docs.json"
375− Http.get manager url [] Exit.DP_Http $ \body ->
376− case D.fromByteString Docs.decoder body of
377− Right docs ->
378− do Dir.createDirectoryIfMissing True home
379− File.writeUtf8 path body
380− return $ Right docs
381−
382− Left _ ->
383− return $ Left $ Exit.DP_Data url body
builder/src/Deps/Registry.hsdeleted−213
@@ -1,213 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
3−module Deps.Registry
4− ( Registry(..)
5− , KnownVersions(..)
6− , read
7− , fetch
8− , update
9− , latest
10− , getVersions
11− , getVersions'
12− )
13− where
14−
15−
16−import Prelude hiding (read)
17−import Control.Monad (liftM2)
18−import Data.Binary (Binary, get, put)
19−import qualified Data.List as List
20−import qualified Data.Map.Strict as Map
21−
22−import qualified Deps.Website as Website
23−import qualified Elm.Package as Pkg
24−import qualified Elm.Version as V
25−import qualified File
26−import qualified Http
27−import qualified Json.Decode as D
28−import qualified Parse.Primitives as P
29−import qualified Reporting.Exit as Exit
30−import qualified Stuff
31−
32−
33−
34−-- REGISTRY
35−
36−
37−data Registry =
38− Registry
39− { _count :: !Int
40− , _versions :: !(Map.Map Pkg.Name KnownVersions)
41− }
42−
43−
44−data KnownVersions =
45− KnownVersions
46− { _newest :: V.Version
47− , _previous :: ![V.Version]
48− }
49−
50−
51−
52−-- READ
53−
54−
55−read :: Stuff.PackageCache -> IO (Maybe Registry)
56−read cache =
57− File.readBinary (Stuff.registry cache)
58−
59−
60−
61−-- FETCH
62−
63−
64−fetch :: Http.Manager -> Stuff.PackageCache -> IO (Either Exit.RegistryProblem Registry)
65−fetch manager cache =
66− post manager "/all-packages" allPkgsDecoder $
67− \versions ->
68− do let size = Map.foldr' addEntry 0 versions
69− let registry = Registry size versions
70− let path = Stuff.registry cache
71− File.writeBinary path registry
72− return registry
73−
74−
75−addEntry :: KnownVersions -> Int -> Int
76−addEntry (KnownVersions _ vs) count =
77− count + 1 + length vs
78−
79−
80−allPkgsDecoder :: D.Decoder () (Map.Map Pkg.Name KnownVersions)
81−allPkgsDecoder =
82− let
83− keyDecoder =
84− Pkg.keyDecoder bail
85−
86− versionsDecoder =
87− D.list (D.mapError (\_ -> ()) V.decoder)
88−
89− toKnownVersions versions =
90− case List.sortBy (flip compare) versions of
91− v:vs -> return (KnownVersions v vs)
92− [] -> D.failure ()
93− in
94− D.dict keyDecoder (toKnownVersions =<< versionsDecoder)
95−
96−
97−
98−-- UPDATE
99−
100−
101−update :: Http.Manager -> Stuff.PackageCache -> Registry -> IO (Either Exit.RegistryProblem Registry)
102−update manager cache oldRegistry@(Registry size packages) =
103− post manager ("/all-packages/since/" ++ show size) (D.list newPkgDecoder) $
104− \news ->
105− case news of
106− [] ->
107− return oldRegistry
108−
109− _:_ ->
110− let
111− newSize = size + length news
112− newPkgs = foldr addNew packages news
113− newRegistry = Registry newSize newPkgs
114− in
115− do File.writeBinary (Stuff.registry cache) newRegistry
116− return newRegistry
117−
118−
119−addNew :: (Pkg.Name, V.Version) -> Map.Map Pkg.Name KnownVersions -> Map.Map Pkg.Name KnownVersions
120−addNew (name, version) versions =
121− let
122− add maybeKnowns =
123− case maybeKnowns of
124− Just (KnownVersions v vs) ->
125− KnownVersions version (v:vs)
126−
127− Nothing ->
128− KnownVersions version []
129− in
130− Map.alter (Just . add) name versions
131−
132−
133−
134−-- NEW PACKAGE DECODER
135−
136−
137−newPkgDecoder :: D.Decoder () (Pkg.Name, V.Version)
138−newPkgDecoder =
139− D.customString newPkgParser bail
140−
141−
142−newPkgParser :: P.Parser () (Pkg.Name, V.Version)
143−newPkgParser =
144− do pkg <- P.specialize (\_ _ _ -> ()) Pkg.parser
145− P.word1 0x40 {-@-} bail
146− vsn <- P.specialize (\_ _ _ -> ()) V.parser
147− return (pkg, vsn)
148−
149−
150−bail :: row -> col -> ()
151−bail _ _ =
152− ()
153−
154−
155−
156−-- LATEST
157−
158−
159−latest :: Http.Manager -> Stuff.PackageCache -> IO (Either Exit.RegistryProblem Registry)
160−latest manager cache =
161− do maybeOldRegistry <- read cache
162− case maybeOldRegistry of
163− Just oldRegistry ->
164− update manager cache oldRegistry
165−
166− Nothing ->
167− fetch manager cache
168−
169−
170−
171−-- GET VERSIONS
172−
173−
174−getVersions :: Pkg.Name -> Registry -> Maybe KnownVersions
175−getVersions name (Registry _ versions) =
176− Map.lookup name versions
177−
178−
179−getVersions' :: Pkg.Name -> Registry -> Either [Pkg.Name] KnownVersions
180−getVersions' name (Registry _ versions) =
181− case Map.lookup name versions of
182− Just kvs -> Right kvs
183− Nothing -> Left $ Pkg.nearbyNames name (Map.keys versions)
184−
185−
186−
187−-- POST
188−
189−
190−post :: Http.Manager -> String -> D.Decoder x a -> (a -> IO b) -> IO (Either Exit.RegistryProblem b)
191−post manager path decoder callback =
192− let
193− url = Website.route path []
194− in
195− Http.post manager url [] Exit.RP_Http $
196− \body ->
197− case D.fromByteString decoder body of
198− Right a -> Right <$> callback a
199− Left _ -> return $ Left $ Exit.RP_Data url body
200−
201−
202−
203−-- BINARY
204−
205−
206−instance Binary Registry where
207− get = liftM2 Registry get get
208− put (Registry a b) = put a >> put b
209−
210−
211−instance Binary KnownVersions where
212− get = liftM2 KnownVersions get get
213− put (KnownVersions a b) = put a >> put b
builder/src/Deps/Solver.hsdeleted−444
@@ -1,444 +0,0 @@
1−{-# LANGUAGE OverloadedStrings, Rank2Types #-}
2−module Deps.Solver
3− ( Solver
4− , Result(..)
5− , Connection(..)
6− --
7− , Details(..)
8− , verify
9− --
10− , AppSolution(..)
11− , addToApp
12− --
13− , Env(..)
14− , initEnv
15− )
16− where
17−
18−
19−import Control.Monad (foldM)
20−import Control.Concurrent (forkIO, newEmptyMVar, putMVar, readMVar)
21−import qualified Data.Map as Map
22−import Data.Map ((!))
23−import qualified System.Directory as Dir
24−import System.FilePath ((</>))
25−
26−import qualified Deps.Registry as Registry
27−import qualified Deps.Website as Website
28−import qualified Elm.Constraint as C
29−import qualified Elm.Package as Pkg
30−import qualified Elm.Outline as Outline
31−import qualified Elm.Version as V
32−import qualified File
33−import qualified Http
34−import qualified Json.Decode as D
35−import qualified Reporting.Exit as Exit
36−import qualified Stuff
37−
38−
39−
40−-- SOLVER
41−
42−
43−newtype Solver a =
44− Solver
45− (
46− forall b.
47− State
48− -> (State -> a -> (State -> IO b) -> IO b)
49− -> (State -> IO b)
50− -> (Exit.Solver -> IO b)
51− -> IO b
52− )
53−
54−
55−data State =
56− State
57− { _cache :: Stuff.PackageCache
58− , _connection :: Connection
59− , _registry :: Registry.Registry
60− , _constraints :: Map.Map (Pkg.Name, V.Version) Constraints
61− }
62−
63−
64−data Constraints =
65− Constraints
66− { _elm :: C.Constraint
67− , _deps :: Map.Map Pkg.Name C.Constraint
68− }
69−
70−
71−data Connection
72− = Online Http.Manager
73− | Offline
74−
75−
76−
77−-- RESULT
78−
79−
80−data Result a
81− = Ok a
82− | NoSolution
83− | NoOfflineSolution
84− | Err Exit.Solver
85−
86−
87−
88−-- VERIFY -- used by Elm.Details
89−
90−
91−data Details =
92− Details V.Version (Map.Map Pkg.Name C.Constraint)
93−
94−
95−verify :: Stuff.PackageCache -> Connection -> Registry.Registry -> Map.Map Pkg.Name C.Constraint -> IO (Result (Map.Map Pkg.Name Details))
96−verify cache connection registry constraints =
97− Stuff.withRegistryLock cache $
98− case try constraints of
99− Solver solver ->
100− solver (State cache connection registry Map.empty)
101− (\s a _ -> return $ Ok (Map.mapWithKey (addDeps s) a))
102− (\_ -> return $ noSolution connection)
103− (\e -> return $ Err e)
104−
105−
106−addDeps :: State -> Pkg.Name -> V.Version -> Details
107−addDeps (State _ _ _ constraints) name vsn =
108− case Map.lookup (name, vsn) constraints of
109− Just (Constraints _ deps) -> Details vsn deps
110− Nothing -> error "compiler bug manifesting in Deps.Solver.addDeps"
111−
112−
113−noSolution :: Connection -> Result a
114−noSolution connection =
115− case connection of
116− Online _ -> NoSolution
117− Offline -> NoOfflineSolution
118−
119−
120−
121−-- ADD TO APP - used in Install
122−
123−
124−data AppSolution =
125− AppSolution
126− { _old :: Map.Map Pkg.Name V.Version
127− , _new :: Map.Map Pkg.Name V.Version
128− , _app :: Outline.AppOutline
129− }
130−
131−
132−addToApp :: Stuff.PackageCache -> Connection -> Registry.Registry -> Pkg.Name -> Outline.AppOutline -> IO (Result AppSolution)
133−addToApp cache connection registry pkg outline@(Outline.AppOutline _ _ direct indirect testDirect testIndirect) =
134− Stuff.withRegistryLock cache $
135− let
136− allIndirects = Map.union indirect testIndirect
137− allDirects = Map.union direct testDirect
138− allDeps = Map.union allDirects allIndirects
139−
140− attempt toConstraint deps =
141− try (Map.insert pkg C.anything (Map.map toConstraint deps))
142− in
143− case
144− oneOf
145− ( attempt C.exactly allDeps )
146− [ attempt C.exactly allDirects
147− , attempt C.untilNextMinor allDirects
148− , attempt C.untilNextMajor allDirects
149− , attempt (\_ -> C.anything) allDirects
150− ]
151− of
152− Solver solver ->
153− solver (State cache connection registry Map.empty)
154− (\s a _ -> return $ Ok (toApp s pkg outline allDeps a))
155− (\_ -> return $ noSolution connection)
156− (\e -> return $ Err e)
157−
158−
159−toApp :: State -> Pkg.Name -> Outline.AppOutline -> Map.Map Pkg.Name V.Version -> Map.Map Pkg.Name V.Version -> AppSolution
160−toApp (State _ _ _ constraints) pkg (Outline.AppOutline elm srcDirs direct _ testDirect _) old new =
161− let
162− d = Map.intersection new (Map.insert pkg V.one direct)
163− i = Map.difference (getTransitive constraints new (Map.toList d) Map.empty) d
164− td = Map.intersection new (Map.delete pkg testDirect)
165− ti = Map.difference new (Map.unions [d,i,td])
166− in
167− AppSolution old new (Outline.AppOutline elm srcDirs d i td ti)
168−
169−
170−getTransitive :: Map.Map (Pkg.Name, V.Version) Constraints -> Map.Map Pkg.Name V.Version -> [(Pkg.Name,V.Version)] -> Map.Map Pkg.Name V.Version -> Map.Map Pkg.Name V.Version
171−getTransitive constraints solution unvisited visited =
172− case unvisited of
173− [] ->
174− visited
175−
176− info@(pkg,vsn) : infos ->
177− if Map.member pkg visited
178− then getTransitive constraints solution infos visited
179− else
180− let
181− newDeps = _deps (constraints ! info)
182− newUnvisited = Map.toList (Map.intersection solution (Map.difference newDeps visited))
183− newVisited = Map.insert pkg vsn visited
184− in
185− getTransitive constraints solution infos $
186− getTransitive constraints solution newUnvisited newVisited
187−
188−
189−
190−-- TRY
191−
192−
193−try :: Map.Map Pkg.Name C.Constraint -> Solver (Map.Map Pkg.Name V.Version)
194−try constraints =
195− exploreGoals (Goals constraints Map.empty)
196−
197−
198−
199−-- EXPLORE GOALS
200−
201−
202−data Goals =
203− Goals
204− { _pending :: Map.Map Pkg.Name C.Constraint
205− , _solved :: Map.Map Pkg.Name V.Version
206− }
207−
208−
209−exploreGoals :: Goals -> Solver (Map.Map Pkg.Name V.Version)
210−exploreGoals (Goals pending solved) =
211− case Map.minViewWithKey pending of
212− Nothing ->
213− return solved
214−
215− Just ((name, constraint), otherPending) ->
216− do let goals1 = Goals otherPending solved
217− let addVsn = addVersion goals1 name
218− (v,vs) <- getRelevantVersions name constraint
219− goals2 <- oneOf (addVsn v) (map addVsn vs)
220− exploreGoals goals2
221−
222−
223−addVersion :: Goals -> Pkg.Name -> V.Version -> Solver Goals
224−addVersion (Goals pending solved) name version =
225− do (Constraints elm deps) <- getConstraints name version
226− if C.goodElm elm
227− then
228− do newPending <- foldM (addConstraint solved) pending (Map.toList deps)
229− return (Goals newPending (Map.insert name version solved))
230− else
231− backtrack
232−
233−
234−addConstraint :: Map.Map Pkg.Name V.Version -> Map.Map Pkg.Name C.Constraint -> (Pkg.Name, C.Constraint) -> Solver (Map.Map Pkg.Name C.Constraint)
235−addConstraint solved unsolved (name, newConstraint) =
236− case Map.lookup name solved of
237− Just version ->
238− if C.satisfies newConstraint version
239− then return unsolved
240− else backtrack
241−
242− Nothing ->
243− case Map.lookup name unsolved of
244− Nothing ->
245− return $ Map.insert name newConstraint unsolved
246−
247− Just oldConstraint ->
248− case C.intersect oldConstraint newConstraint of
249− Nothing ->
250− backtrack
251−
252− Just mergedConstraint ->
253− if oldConstraint == mergedConstraint
254− then return unsolved
255− else return (Map.insert name mergedConstraint unsolved)
256−
257−
258−
259−-- GET RELEVANT VERSIONS
260−
261−
262−getRelevantVersions :: Pkg.Name -> C.Constraint -> Solver (V.Version, [V.Version])
263−getRelevantVersions name constraint =
264− Solver $ \state@(State _ _ registry _) ok back _ ->
265− case Registry.getVersions name registry of
266− Just (Registry.KnownVersions newest previous) ->
267− case filter (C.satisfies constraint) (newest:previous) of
268− [] -> back state
269− v:vs -> ok state (v,vs) back
270−
271− Nothing ->
272− back state
273−
274−
275−
276−-- GET CONSTRAINTS
277−
278−
279−getConstraints :: Pkg.Name -> V.Version -> Solver Constraints
280−getConstraints pkg vsn =
281− Solver $ \state@(State cache connection registry cDict) ok back err ->
282− do let key = (pkg, vsn)
283− case Map.lookup key cDict of
284− Just cs ->
285− ok state cs back
286−
287− Nothing ->
288− do let toNewState cs = State cache connection registry (Map.insert key cs cDict)
289− let home = Stuff.package cache pkg vsn
290− let path = home </> "elm.json"
291− outlineExists <- File.exists path
292− if outlineExists
293− then
294− do bytes <- File.readUtf8 path
295− case D.fromByteString constraintsDecoder bytes of
296− Right cs ->
297− case connection of
298− Online _ ->
299− ok (toNewState cs) cs back
300−
301− Offline ->
302− do srcExists <- Dir.doesDirectoryExist (Stuff.package cache pkg vsn </> "src")
303− if srcExists
304− then ok (toNewState cs) cs back
305− else back state
306−
307− Left _ ->
308− do File.remove path
309− err (Exit.SolverBadCacheData pkg vsn)
310− else
311− case connection of
312− Offline ->
313− back state
314−
315− Online manager ->
316− do let url = Website.metadata pkg vsn "elm.json"
317− result <- Http.get manager url [] id (return . Right)
318− case result of
319− Left httpProblem ->
320− err (Exit.SolverBadHttp pkg vsn httpProblem)
321−
322− Right body ->
323− case D.fromByteString constraintsDecoder body of
324− Right cs ->
325− do Dir.createDirectoryIfMissing True home
326− File.writeUtf8 path body
327− ok (toNewState cs) cs back
328−
329− Left _ ->
330− err (Exit.SolverBadHttpData pkg vsn url)
331−
332−
333−constraintsDecoder :: D.Decoder () Constraints
334−constraintsDecoder =
335− do outline <- D.mapError (const ()) Outline.decoder
336− case outline of
337− Outline.Pkg (Outline.PkgOutline _ _ _ _ _ deps _ elmConstraint) ->
338− return (Constraints elmConstraint deps)
339−
340− Outline.App _ ->
341− D.failure ()
342−
343−
344−
345−-- ENVIRONMENT
346−
347−
348−data Env =
349− Env Stuff.PackageCache Http.Manager Connection Registry.Registry
350−
351−
352−initEnv :: IO (Either Exit.RegistryProblem Env)
353−initEnv =
354− do mvar <- newEmptyMVar
355− _ <- forkIO $ putMVar mvar =<< Http.getManager
356− cache <- Stuff.getPackageCache
357− Stuff.withRegistryLock cache $
358− do maybeRegistry <- Registry.read cache
359− manager <- readMVar mvar
360−
361− case maybeRegistry of
362− Nothing ->
363− do eitherRegistry <- Registry.fetch manager cache
364− case eitherRegistry of
365− Right latestRegistry ->
366− return $ Right $ Env cache manager (Online manager) latestRegistry
367−
368− Left problem ->
369− return $ Left $ problem
370−
371− Just cachedRegistry ->
372− do eitherRegistry <- Registry.update manager cache cachedRegistry
373− case eitherRegistry of
374− Right latestRegistry ->
375− return $ Right $ Env cache manager (Online manager) latestRegistry
376−
377− Left _ ->
378− return $ Right $ Env cache manager Offline cachedRegistry
379−
380−
381−
382−-- INSTANCES
383−
384−
385−instance Functor Solver where
386− fmap func (Solver solver) =
387− Solver $ \state ok back err ->
388− let
389− okA stateA arg backA = ok stateA (func arg) backA
390− in
391− solver state okA back err
392−
393−
394−instance Applicative Solver where
395− pure a =
396− Solver $ \state ok back _ -> ok state a back
397−
398− (<*>) (Solver solverFunc) (Solver solverArg) =
399− Solver $ \state ok back err ->
400− let
401− okF stateF func backF =
402− let
403− okA stateA arg backA = ok stateA (func arg) backA
404− in
405− solverArg stateF okA backF err
406− in
407− solverFunc state okF back err
408−
409−
410−instance Monad Solver where
411− return a =
412− Solver $ \state ok back _ -> ok state a back
413−
414− (>>=) (Solver solverA) callback =
415− Solver $ \state ok back err ->
416− let
417− okA stateA a backA =
418− case callback a of
419− Solver solverB -> solverB stateA ok backA err
420− in
421− solverA state okA back err
422−
423−
424−oneOf :: Solver a -> [Solver a] -> Solver a
425−oneOf solver@(Solver solverHead) solvers =
426− case solvers of
427− [] ->
428− solver
429−
430− s:ss ->
431− Solver $ \state0 ok back err ->
432− let
433− tryTail state1 =
434− let
435− (Solver solverTail) = oneOf s ss
436− in
437− solverTail state1 ok back err
438− in
439− solverHead state0 ok tryTail err
440−
441−
442−backtrack :: Solver a
443−backtrack =
444− Solver $ \state _ back _ -> back state
builder/src/Deps/Website.hsdeleted−26
@@ -1,26 +0,0 @@
1−module Deps.Website
2− ( domain
3− , route
4− , metadata
5− )
6− where
7−
8−
9−import qualified Elm.Package as Pkg
10−import qualified Elm.Version as V
11−import qualified Http
12−
13−
14−domain :: String
15−domain =
16− "https://package.elm-lang.org"
17−
18−
19−route :: String -> [(String,String)] -> String
20−route path params =
21− Http.toUrl (domain ++ path) params
22−
23−
24−metadata :: Pkg.Name -> V.Version -> String -> String
25−metadata name version file =
26− domain ++ "/packages/" ++ Pkg.toUrl name ++ "/" ++ V.toChars version ++ "/" ++ file
builder/src/Elm/Details.hsdeleted−833
@@ -1,833 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
3−module Elm.Details
4− ( Details(..)
5− , BuildID
6− , ValidOutline(..)
7− , Local(..)
8− , Foreign(..)
9− , load
10− , loadObjects
11− , loadInterfaces
12− , verifyInstall
13− )
14− where
15−
16−
17−import Control.Concurrent (forkIO)
18−import Control.Concurrent.MVar (MVar, newEmptyMVar, newMVar, putMVar, readMVar, takeMVar)
19−import Control.Monad (liftM, liftM2, liftM3)
20−import Data.Binary (Binary, get, put, getWord8, putWord8)
21−import qualified Data.Either as Either
22−import qualified Data.Map as Map
23−import qualified Data.Map.Utils as Map
24−import qualified Data.Map.Merge.Strict as Map
25−import qualified Data.Maybe as Maybe
26−import qualified Data.Name as Name
27−import qualified Data.NonEmptyList as NE
28−import qualified Data.OneOrMore as OneOrMore
29−import qualified Data.Set as Set
30−import qualified Data.Utf8 as Utf8
31−import Data.Word (Word64)
32−import qualified System.Directory as Dir
33−import System.FilePath ((</>), (<.>))
34−
35−import qualified AST.Canonical as Can
36−import qualified AST.Source as Src
37−import qualified AST.Optimized as Opt
38−import qualified BackgroundWriter as BW
39−import qualified Compile
40−import qualified Deps.Registry as Registry
41−import qualified Deps.Solver as Solver
42−import qualified Deps.Website as Website
43−import qualified Elm.Constraint as Con
44−import qualified Elm.Docs as Docs
45−import qualified Elm.Interface as I
46−import qualified Elm.Kernel as Kernel
47−import qualified Elm.ModuleName as ModuleName
48−import qualified Elm.Outline as Outline
49−import qualified Elm.Package as Pkg
50−import qualified Elm.Version as V
51−import qualified File
52−import qualified Http
53−import qualified Json.Decode as D
54−import qualified Json.Encode as E
55−import qualified Parse.Module as Parse
56−import qualified Reporting
57−import qualified Reporting.Annotation as A
58−import qualified Reporting.Exit as Exit
59−import qualified Reporting.Task as Task
60−import qualified Stuff
61−
62−
63−
64−-- DETAILS
65−
66−
67−data Details =
68− Details
69− { _outlineTime :: File.Time
70− , _outline :: ValidOutline
71− , _buildID :: BuildID
72− , _locals :: Map.Map ModuleName.Raw Local
73− , _foreigns :: Map.Map ModuleName.Raw Foreign
74− , _extras :: Extras
75− }
76−
77−
78−type BuildID = Word64
79−
80−
81−data ValidOutline
82− = ValidApp (NE.List Outline.SrcDir)
83− | ValidPkg Pkg.Name [ModuleName.Raw] (Map.Map Pkg.Name V.Version {- for docs in reactor -})
84−
85−
86−-- NOTE: we need two ways to detect if a file must be recompiled:
87−--
88−-- (1) _time is the modification time from the last time we compiled the file.
89−-- By checking EQUALITY with the current modification time, we can detect file
90−-- saves and `git checkout` of previous versions. Both need a recompile.
91−--
92−-- (2) _lastChange is the BuildID from the last time a new interface file was
93−-- generated, and _lastCompile is the BuildID from the last time the file was
94−-- compiled. These may be different if a file is recompiled but the interface
95−-- stayed the same. When the _lastCompile is LESS THAN the _lastChange of any
96−-- imports, we need to recompile. This can happen when a project has multiple
97−-- entrypoints and some modules are compiled less often than their imports.
98−--
99−data Local =
100− Local
101− { _path :: FilePath
102− , _time :: File.Time
103− , _deps :: [ModuleName.Raw]
104− , _main :: Bool
105− , _lastChange :: BuildID
106− , _lastCompile :: BuildID
107− }
108−
109−
110−data Foreign =
111− Foreign Pkg.Name [Pkg.Name]
112−
113−
114−data Extras
115− = ArtifactsCached
116− | ArtifactsFresh Interfaces Opt.GlobalGraph
117−
118−
119−type Interfaces =
120− Map.Map ModuleName.Canonical I.DependencyInterface
121−
122−
123−
124−-- LOAD ARTIFACTS
125−
126−
127−loadObjects :: FilePath -> Details -> IO (MVar (Maybe Opt.GlobalGraph))
128−loadObjects root (Details _ _ _ _ _ extras) =
129− case extras of
130− ArtifactsFresh _ o -> newMVar (Just o)
131− ArtifactsCached -> fork (File.readBinary (Stuff.objects root))
132−
133−
134−loadInterfaces :: FilePath -> Details -> IO (MVar (Maybe Interfaces))
135−loadInterfaces root (Details _ _ _ _ _ extras) =
136− case extras of
137− ArtifactsFresh i _ -> newMVar (Just i)
138− ArtifactsCached -> fork (File.readBinary (Stuff.interfaces root))
139−
140−
141−
142−-- VERIFY INSTALL -- used by Install
143−
144−
145−verifyInstall :: BW.Scope -> FilePath -> Solver.Env -> Outline.Outline -> IO (Either Exit.Details ())
146−verifyInstall scope root (Solver.Env cache manager connection registry) outline =
147− do time <- File.getTime (root </> "elm.json")
148− let key = Reporting.ignorer
149− let env = Env key scope root cache manager connection registry
150− case outline of
151− Outline.Pkg pkg -> Task.run (verifyPkg env time pkg >> return ())
152− Outline.App app -> Task.run (verifyApp env time app >> return ())
153−
154−
155−
156−-- LOAD -- used by Make, Repl, Reactor
157−
158−
159−load :: Reporting.Style -> BW.Scope -> FilePath -> IO (Either Exit.Details Details)
160−load style scope root =
161− do newTime <- File.getTime (root </> "elm.json")
162− maybeDetails <- File.readBinary (Stuff.details root)
163− case maybeDetails of
164− Nothing ->
165− generate style scope root newTime
166−
167− Just details@(Details oldTime _ buildID _ _ _) ->
168− if oldTime == newTime
169− then return (Right details { _buildID = buildID + 1 })
170− else generate style scope root newTime
171−
172−
173−
174−-- GENERATE
175−
176−
177−generate :: Reporting.Style -> BW.Scope -> FilePath -> File.Time -> IO (Either Exit.Details Details)
178−generate style scope root time =
179− Reporting.trackDetails style $ \key ->
180− do result <- initEnv key scope root
181− case result of
182− Left exit ->
183− return (Left exit)
184−
185− Right (env, outline) ->
186− case outline of
187− Outline.Pkg pkg -> Task.run (verifyPkg env time pkg)
188− Outline.App app -> Task.run (verifyApp env time app)
189−
190−
191−
192−-- ENV
193−
194−
195−data Env =
196− Env
197− { _key :: Reporting.DKey
198− , _scope :: BW.Scope
199− , _root :: FilePath
200− , _cache :: Stuff.PackageCache
201− , _manager :: Http.Manager
202− , _connection :: Solver.Connection
203− , _registry :: Registry.Registry
204− }
205−
206−
207−initEnv :: Reporting.DKey -> BW.Scope -> FilePath -> IO (Either Exit.Details (Env, Outline.Outline))
208−initEnv key scope root =
209− do mvar <- fork Solver.initEnv
210− eitherOutline <- Outline.read root
211− case eitherOutline of
212− Left problem ->
213− return $ Left $ Exit.DetailsBadOutline problem
214−
215− Right outline ->
216− do maybeEnv <- readMVar mvar
217− case maybeEnv of
218− Left problem ->
219− return $ Left $ Exit.DetailsCannotGetRegistry problem
220−
221− Right (Solver.Env cache manager connection registry) ->
222− return $ Right (Env key scope root cache manager connection registry, outline)
223−
224−
225−
226−-- VERIFY PROJECT
227−
228−
229−type Task a = Task.Task Exit.Details a
230−
231−
232−verifyPkg :: Env -> File.Time -> Outline.PkgOutline -> Task Details
233−verifyPkg env time (Outline.PkgOutline pkg _ _ _ exposed direct testDirect elm) =
234− if Con.goodElm elm
235− then
236− do solution <- verifyConstraints env =<< union noDups direct testDirect
237− let exposedList = Outline.flattenExposed exposed
238− let exactDeps = Map.map (\(Solver.Details v _) -> v) solution -- for pkg docs in reactor
239− verifyDependencies env time (ValidPkg pkg exposedList exactDeps) solution direct
240− else
241− Task.throw $ Exit.DetailsBadElmInPkg elm
242−
243−
244−verifyApp :: Env -> File.Time -> Outline.AppOutline -> Task Details
245−verifyApp env time outline@(Outline.AppOutline elmVersion srcDirs direct _ _ _) =
246− if elmVersion == V.compiler
247− then
248− do stated <- checkAppDeps outline
249− actual <- verifyConstraints env (Map.map Con.exactly stated)
250− if Map.size stated == Map.size actual
251− then verifyDependencies env time (ValidApp srcDirs) actual direct
252− else Task.throw $ Exit.DetailsHandEditedDependencies
253− else
254− Task.throw $ Exit.DetailsBadElmInAppOutline elmVersion
255−
256−
257−checkAppDeps :: Outline.AppOutline -> Task (Map.Map Pkg.Name V.Version)
258−checkAppDeps (Outline.AppOutline _ _ direct indirect testDirect testIndirect) =
259− do x <- union allowEqualDups indirect testDirect
260− y <- union noDups direct testIndirect
261− union noDups x y
262−
263−
264−
265−-- VERIFY CONSTRAINTS
266−
267−
268−verifyConstraints :: Env -> Map.Map Pkg.Name Con.Constraint -> Task (Map.Map Pkg.Name Solver.Details)
269−verifyConstraints (Env _ _ _ cache _ connection registry) constraints =
270− do result <- Task.io $ Solver.verify cache connection registry constraints
271− case result of
272− Solver.Ok details -> return details
273− Solver.NoSolution -> Task.throw $ Exit.DetailsNoSolution
274− Solver.NoOfflineSolution -> Task.throw $ Exit.DetailsNoOfflineSolution
275− Solver.Err exit -> Task.throw $ Exit.DetailsSolverProblem exit
276−
277−
278−
279−-- UNION
280−
281−
282−union :: (Ord k) => (k -> v -> v -> Task v) -> Map.Map k v -> Map.Map k v -> Task (Map.Map k v)
283−union tieBreaker deps1 deps2 =
284− Map.mergeA Map.preserveMissing Map.preserveMissing (Map.zipWithAMatched tieBreaker) deps1 deps2
285−
286−
287−noDups :: k -> v -> v -> Task v
288−noDups _ _ _ =
289− Task.throw Exit.DetailsHandEditedDependencies
290−
291−
292−allowEqualDups :: (Eq v) => k -> v -> v -> Task v
293−allowEqualDups _ v1 v2 =
294− if v1 == v2
295− then return v1
296− else Task.throw Exit.DetailsHandEditedDependencies
297−
298−
299−
300−-- FORK
301−
302−
303−fork :: IO a -> IO (MVar a)
304−fork work =
305− do mvar <- newEmptyMVar
306− _ <- forkIO $ putMVar mvar =<< work
307− return mvar
308−
309−
310−
311−-- VERIFY DEPENDENCIES
312−
313−
314−verifyDependencies :: Env -> File.Time -> ValidOutline -> Map.Map Pkg.Name Solver.Details -> Map.Map Pkg.Name a -> Task Details
315−verifyDependencies env@(Env key scope root cache _ _ _) time outline solution directDeps =
316− Task.eio id $
317− do Reporting.report key (Reporting.DStart (Map.size solution))
318− mvar <- newEmptyMVar
319− mvars <- Stuff.withRegistryLock cache $
320− Map.traverseWithKey (\k v -> fork (verifyDep env mvar solution k v)) solution
321− putMVar mvar mvars
322− deps <- traverse readMVar mvars
323− case sequence deps of
324− Left _ ->
325− do home <- Stuff.getElmHome
326− return $ Left $ Exit.DetailsBadDeps home $
327− Maybe.catMaybes $ Either.lefts $ Map.elems deps
328−
329− Right artifacts ->
330− let
331− objs = Map.foldr addObjects Opt.empty artifacts
332− ifaces = Map.foldrWithKey (addInterfaces directDeps) Map.empty artifacts
333− foreigns = Map.map (OneOrMore.destruct Foreign) $ Map.foldrWithKey gatherForeigns Map.empty $ Map.intersection artifacts directDeps
334− details = Details time outline 0 Map.empty foreigns (ArtifactsFresh ifaces objs)
335− in
336− do BW.writeBinary scope (Stuff.objects root) objs
337− BW.writeBinary scope (Stuff.interfaces root) ifaces
338− BW.writeBinary scope (Stuff.details root) details
339− return (Right details)
340−
341−
342−addObjects :: Artifacts -> Opt.GlobalGraph -> Opt.GlobalGraph
343−addObjects (Artifacts _ objs) graph =
344− Opt.addGlobalGraph objs graph
345−
346−
347−addInterfaces :: Map.Map Pkg.Name a -> Pkg.Name -> Artifacts -> Interfaces -> Interfaces
348−addInterfaces directDeps pkg (Artifacts ifaces _) dependencyInterfaces =
349− Map.union dependencyInterfaces $ Map.mapKeysMonotonic (ModuleName.Canonical pkg) $
350− if Map.member pkg directDeps
351− then ifaces
352− else Map.map I.privatize ifaces
353−
354−
355−gatherForeigns :: Pkg.Name -> Artifacts -> Map.Map ModuleName.Raw (OneOrMore.OneOrMore Pkg.Name) -> Map.Map ModuleName.Raw (OneOrMore.OneOrMore Pkg.Name)
356−gatherForeigns pkg (Artifacts ifaces _) foreigns =
357− let
358− isPublic di =
359− case di of
360− I.Public _ -> Just (OneOrMore.one pkg)
361− I.Private _ _ _ -> Nothing
362− in
363− Map.unionWith OneOrMore.more foreigns (Map.mapMaybe isPublic ifaces)
364−
365−
366−
367−-- VERIFY DEPENDENCY
368−
369−
370−data Artifacts =
371− Artifacts
372− { _ifaces :: Map.Map ModuleName.Raw I.DependencyInterface
373− , _objects :: Opt.GlobalGraph
374− }
375−
376−
377−type Dep =
378− Either (Maybe Exit.DetailsBadDep) Artifacts
379−
380−
381−verifyDep :: Env -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Map.Map Pkg.Name Solver.Details -> Pkg.Name -> Solver.Details -> IO Dep
382−verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.Details vsn directDeps) =
383− do let fingerprint = Map.intersectionWith (\(Solver.Details v _) _ -> v) solution directDeps
384− exists <- Dir.doesDirectoryExist (Stuff.package cache pkg vsn </> "src")
385− if exists
386− then
387− do Reporting.report key Reporting.DCached
388− maybeCache <- File.readBinary (Stuff.package cache pkg vsn </> "artifacts.dat")
389− case maybeCache of
390− Nothing ->
391− build key cache depsMVar pkg details fingerprint Set.empty
392−
393− Just (ArtifactCache fingerprints artifacts) ->
394− if Set.member fingerprint fingerprints
395− then Reporting.report key Reporting.DBuilt >> return (Right artifacts)
396− else build key cache depsMVar pkg details fingerprint fingerprints
397− else
398− do Reporting.report key Reporting.DRequested
399− result <- downloadPackage cache manager pkg vsn
400− case result of
401− Left problem ->
402− do Reporting.report key (Reporting.DFailed pkg vsn)
403− return $ Left $ Just $ Exit.BD_BadDownload pkg vsn problem
404−
405− Right () ->
406− do Reporting.report key (Reporting.DReceived pkg vsn)
407− build key cache depsMVar pkg details fingerprint Set.empty
408−
409−
410−
411−-- ARTIFACT CACHE
412−
413−
414−data ArtifactCache =
415− ArtifactCache
416− { _fingerprints :: Set.Set Fingerprint
417− , _artifacts :: Artifacts
418− }
419−
420−
421−type Fingerprint =
422− Map.Map Pkg.Name V.Version
423−
424−
425−
426−-- BUILD
427−
428−
429−build :: Reporting.DKey -> Stuff.PackageCache -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Pkg.Name -> Solver.Details -> Fingerprint -> Set.Set Fingerprint -> IO Dep
430−build key cache depsMVar pkg (Solver.Details vsn _) f fs =
431− do eitherOutline <- Outline.read (Stuff.package cache pkg vsn)
432− case eitherOutline of
433− Left _ ->
434− do Reporting.report key Reporting.DBroken
435− return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
436−
437− Right (Outline.App _) ->
438− do Reporting.report key Reporting.DBroken
439− return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
440−
441− Right (Outline.Pkg (Outline.PkgOutline _ _ _ _ exposed deps _ _)) ->
442− do allDeps <- readMVar depsMVar
443− directDeps <- traverse readMVar (Map.intersection allDeps deps)
444− case sequence directDeps of
445− Left _ ->
446− do Reporting.report key Reporting.DBroken
447− return $ Left $ Nothing
448−
449− Right directArtifacts ->
450− do let src = Stuff.package cache pkg vsn </> "src"
451− let foreignDeps = gatherForeignInterfaces directArtifacts
452− let exposedDict = Map.fromKeys (\_ -> ()) (Outline.flattenExposed exposed)
453− docsStatus <- getDocsStatus cache pkg vsn
454− mvar <- newEmptyMVar
455− mvars <- Map.traverseWithKey (const . fork . crawlModule foreignDeps mvar pkg src docsStatus) exposedDict
456− putMVar mvar mvars
457− mapM_ readMVar mvars
458− maybeStatuses <- traverse readMVar =<< readMVar mvar
459− case sequence maybeStatuses of
460− Nothing ->
461− do Reporting.report key Reporting.DBroken
462− return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
463−
464− Just statuses ->
465− do rmvar <- newEmptyMVar
466− rmvars <- traverse (fork . compile pkg rmvar) statuses
467− putMVar rmvar rmvars
468− maybeResults <- traverse readMVar rmvars
469− case sequence maybeResults of
470− Nothing ->
471− do Reporting.report key Reporting.DBroken
472− return $ Left $ Just $ Exit.BD_BadBuild pkg vsn f
473−
474− Just results ->
475− let
476− path = Stuff.package cache pkg vsn </> "artifacts.dat"
477− ifaces = gatherInterfaces exposedDict results
478− objects = gatherObjects results
479− artifacts = Artifacts ifaces objects
480− fingerprints = Set.insert f fs
481− in
482− do writeDocs cache pkg vsn docsStatus results
483− File.writeBinary path (ArtifactCache fingerprints artifacts)
484− Reporting.report key Reporting.DBuilt
485− return (Right artifacts)
486−
487−
488−
489−-- GATHER
490−
491−
492−gatherObjects :: Map.Map ModuleName.Raw Result -> Opt.GlobalGraph
493−gatherObjects results =
494− Map.foldrWithKey addLocalGraph Opt.empty results
495−
496−
497−addLocalGraph :: ModuleName.Raw -> Result -> Opt.GlobalGraph -> Opt.GlobalGraph
498−addLocalGraph name status graph =
499− case status of
500− RLocal _ objs _ -> Opt.addLocalGraph objs graph
501− RForeign _ -> graph
502− RKernelLocal cs -> Opt.addKernel (Name.getKernel name) cs graph
503− RKernelForeign -> graph
504−
505−
506−gatherInterfaces :: Map.Map ModuleName.Raw () -> Map.Map ModuleName.Raw Result -> Map.Map ModuleName.Raw I.DependencyInterface
507−gatherInterfaces exposed artifacts =
508− let
509− onLeft = Map.mapMissing (error "compiler bug manifesting in Elm.Details.gatherInterfaces")
510− onRight = Map.mapMaybeMissing (\_ iface -> toLocalInterface I.private iface)
511− onBoth = Map.zipWithMaybeMatched (\_ () iface -> toLocalInterface I.public iface)
512− in
513− Map.merge onLeft onRight onBoth exposed artifacts
514−
515−
516−toLocalInterface :: (I.Interface -> a) -> Result -> Maybe a
517−toLocalInterface func result =
518− case result of
519− RLocal iface _ _ -> Just (func iface)
520− RForeign _ -> Nothing
521− RKernelLocal _ -> Nothing
522− RKernelForeign -> Nothing
523−
524−
525−
526−-- GATHER FOREIGN INTERFACES
527−
528−
529−data ForeignInterface
530− = ForeignAmbiguous
531− | ForeignSpecific I.Interface
532−
533−
534−gatherForeignInterfaces :: Map.Map Pkg.Name Artifacts -> Map.Map ModuleName.Raw ForeignInterface
535−gatherForeignInterfaces directArtifacts =
536− Map.map (OneOrMore.destruct finalize) $
537− Map.foldrWithKey gather Map.empty directArtifacts
538− where
539− finalize :: I.Interface -> [I.Interface] -> ForeignInterface
540− finalize i is =
541− case is of
542− [] -> ForeignSpecific i
543− _:_ -> ForeignAmbiguous
544−
545− gather :: Pkg.Name -> Artifacts -> Map.Map ModuleName.Raw (OneOrMore.OneOrMore I.Interface) -> Map.Map ModuleName.Raw (OneOrMore.OneOrMore I.Interface)
546− gather _ (Artifacts ifaces _) buckets =
547− Map.unionWith OneOrMore.more buckets (Map.mapMaybe isPublic ifaces)
548−
549− isPublic :: I.DependencyInterface -> Maybe (OneOrMore.OneOrMore I.Interface)
550− isPublic di =
551− case di of
552− I.Public iface -> Just (OneOrMore.one iface)
553− I.Private _ _ _ -> Nothing
554−
555−
556−
557−-- CRAWL
558−
559−
560−type StatusDict =
561− Map.Map ModuleName.Raw (MVar (Maybe Status))
562−
563−
564−data Status
565− = SLocal DocsStatus (Map.Map ModuleName.Raw ()) Src.Module
566− | SForeign I.Interface
567− | SKernelLocal [Kernel.Chunk]
568− | SKernelForeign
569−
570−
571−crawlModule :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> DocsStatus -> ModuleName.Raw -> IO (Maybe Status)
572−crawlModule foreignDeps mvar pkg src docsStatus name =
573− do let path = src </> ModuleName.toFilePath name <.> "elm"
574− exists <- File.exists path
575− case Map.lookup name foreignDeps of
576− Just ForeignAmbiguous ->
577− return Nothing
578−
579− Just (ForeignSpecific iface) ->
580− if exists
581− then return Nothing
582− else return (Just (SForeign iface))
583−
584− Nothing ->
585− if exists then
586− crawlFile foreignDeps mvar pkg src docsStatus name path
587−
588− else if Pkg.isKernel pkg && Name.isKernel name then
589− crawlKernel foreignDeps mvar pkg src name
590−
591− else
592− return Nothing
593−
594−
595−crawlFile :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> DocsStatus -> ModuleName.Raw -> FilePath -> IO (Maybe Status)
596−crawlFile foreignDeps mvar pkg src docsStatus expectedName path =
597− do bytes <- File.readUtf8 path
598− case Parse.fromByteString (Parse.Package pkg) bytes of
599− Right modul@(Src.Module (Just (A.At _ actualName)) _ _ imports _ _ _ _ _) | expectedName == actualName ->
600− do deps <- crawlImports foreignDeps mvar pkg src imports
601− return (Just (SLocal docsStatus deps modul))
602−
603− _ ->
604− return Nothing
605−
606−
607−crawlImports :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> [Src.Import] -> IO (Map.Map ModuleName.Raw ())
608−crawlImports foreignDeps mvar pkg src imports =
609− do statusDict <- takeMVar mvar
610− let deps = Map.fromList (map (\i -> (Src.getImportName i, ())) imports)
611− let news = Map.difference deps statusDict
612− mvars <- Map.traverseWithKey (const . fork . crawlModule foreignDeps mvar pkg src DocsNotNeeded) news
613− putMVar mvar (Map.union mvars statusDict)
614− mapM_ readMVar mvars
615− return deps
616−
617−
618−crawlKernel :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> ModuleName.Raw -> IO (Maybe Status)
619−crawlKernel foreignDeps mvar pkg src name =
620− do let path = src </> ModuleName.toFilePath name <.> "js"
621− exists <- File.exists path
622− if exists
623− then
624− do bytes <- File.readUtf8 path
625− case Kernel.fromByteString pkg (Map.mapMaybe getDepHome foreignDeps) bytes of
626− Nothing ->
627− return Nothing
628−
629− Just (Kernel.Content imports chunks) ->
630− do _ <- crawlImports foreignDeps mvar pkg src imports
631− return (Just (SKernelLocal chunks))
632− else
633− return (Just SKernelForeign)
634−
635−
636−getDepHome :: ForeignInterface -> Maybe Pkg.Name
637−getDepHome fi =
638− case fi of
639− ForeignSpecific (I.Interface pkg _ _ _ _) -> Just pkg
640− ForeignAmbiguous -> Nothing
641−
642−
643−
644−-- COMPILE
645−
646−
647−data Result
648− = RLocal !I.Interface !Opt.LocalGraph (Maybe Docs.Module)
649− | RForeign I.Interface
650− | RKernelLocal [Kernel.Chunk]
651− | RKernelForeign
652−
653−
654−compile :: Pkg.Name -> MVar (Map.Map ModuleName.Raw (MVar (Maybe Result))) -> Status -> IO (Maybe Result)
655−compile pkg mvar status =
656− case status of
657− SLocal docsStatus deps modul ->
658− do resultsDict <- readMVar mvar
659− maybeResults <- traverse readMVar (Map.intersection resultsDict deps)
660− case sequence maybeResults of
661− Nothing ->
662− return Nothing
663−
664− Just results ->
665− case Compile.compile pkg (Map.mapMaybe getInterface results) modul of
666− Left _ ->
667− return Nothing
668−
669− Right (Compile.Artifacts canonical annotations objects) ->
670− let
671− ifaces = I.fromModule pkg canonical annotations
672− docs = makeDocs docsStatus canonical
673− in
674− return (Just (RLocal ifaces objects docs))
675−
676− SForeign iface ->
677− return (Just (RForeign iface))
678−
679− SKernelLocal chunks ->
680− return (Just (RKernelLocal chunks))
681−
682− SKernelForeign ->
683− return (Just RKernelForeign)
684−
685−
686−getInterface :: Result -> Maybe I.Interface
687−getInterface result =
688− case result of
689− RLocal iface _ _ -> Just iface
690− RForeign iface -> Just iface
691− RKernelLocal _ -> Nothing
692− RKernelForeign -> Nothing
693−
694−
695−
696−-- MAKE DOCS
697−
698−
699−data DocsStatus
700− = DocsNeeded
701− | DocsNotNeeded
702−
703−
704−getDocsStatus :: Stuff.PackageCache -> Pkg.Name -> V.Version -> IO DocsStatus
705−getDocsStatus cache pkg vsn =
706− do exists <- File.exists (Stuff.package cache pkg vsn </> "docs.json")
707− if exists
708− then return DocsNotNeeded
709− else return DocsNeeded
710−
711−
712−makeDocs :: DocsStatus -> Can.Module -> Maybe Docs.Module
713−makeDocs status modul =
714− case status of
715− DocsNeeded ->
716− case Docs.fromModule modul of
717− Right docs -> Just docs
718− Left _ -> Nothing
719−
720− DocsNotNeeded ->
721− Nothing
722−
723−
724−writeDocs :: Stuff.PackageCache -> Pkg.Name -> V.Version -> DocsStatus -> Map.Map ModuleName.Raw Result -> IO ()
725−writeDocs cache pkg vsn status results =
726− case status of
727− DocsNeeded ->
728− E.writeUgly (Stuff.package cache pkg vsn </> "docs.json") $
729− Docs.encode $ Map.mapMaybe toDocs results
730−
731− DocsNotNeeded ->
732− return ()
733−
734−
735−toDocs :: Result -> Maybe Docs.Module
736−toDocs result =
737− case result of
738− RLocal _ _ docs -> docs
739− RForeign _ -> Nothing
740− RKernelLocal _ -> Nothing
741− RKernelForeign -> Nothing
742−
743−
744−
745−-- DOWNLOAD PACKAGE
746−
747−
748−downloadPackage :: Stuff.PackageCache -> Http.Manager -> Pkg.Name -> V.Version -> IO (Either Exit.PackageProblem ())
749−downloadPackage cache manager pkg vsn =
750− let
751− url = Website.metadata pkg vsn "endpoint.json"
752− in
753− do eitherByteString <-
754− Http.get manager url [] id (return . Right)
755−
756− case eitherByteString of
757− Left err ->
758− return $ Left $ Exit.PP_BadEndpointRequest err
759−
760− Right byteString ->
761− case D.fromByteString endpointDecoder byteString of
762− Left _ ->
763− return $ Left $ Exit.PP_BadEndpointContent url
764−
765− Right (endpoint, expectedHash) ->
766− Http.getArchive manager endpoint Exit.PP_BadArchiveRequest (Exit.PP_BadArchiveContent endpoint) $
767− \(sha, archive) ->
768− if expectedHash == Http.shaToChars sha
769− then Right <$> File.writePackage (Stuff.package cache pkg vsn) archive
770− else return $ Left $ Exit.PP_BadArchiveHash endpoint expectedHash (Http.shaToChars sha)
771−
772−
773−endpointDecoder :: D.Decoder e (String, String)
774−endpointDecoder =
775− do url <- D.field "url" D.string
776− hash <- D.field "hash" D.string
777− return (Utf8.toChars url, Utf8.toChars hash)
778−
779−
780−
781−-- BINARY
782−
783−
784−instance Binary Details where
785− put (Details a b c d e _) = put a >> put b >> put c >> put d >> put e
786− get =
787− do a <- get
788− b <- get
789− c <- get
790− d <- get
791− e <- get
792− return (Details a b c d e ArtifactsCached)
793−
794−
795−instance Binary ValidOutline where
796− put outline =
797− case outline of
798− ValidApp a -> putWord8 0 >> put a
799− ValidPkg a b c -> putWord8 1 >> put a >> put b >> put c
800−
801− get =
802− do n <- getWord8
803− case n of
804− 0 -> liftM ValidApp get
805− 1 -> liftM3 ValidPkg get get get
806− _ -> fail "binary encoding of ValidOutline was corrupted"
807−
808−
809−instance Binary Local where
810− put (Local a b c d e f) = put a >> put b >> put c >> put d >> put e >> put f
811− get =
812− do a <- get
813− b <- get
814− c <- get
815− d <- get
816− e <- get
817− f <- get
818− return (Local a b c d e f)
819−
820−
821−instance Binary Foreign where
822− get = liftM2 Foreign get get
823− put (Foreign a b) = put a >> put b
824−
825−
826−instance Binary Artifacts where
827− get = liftM2 Artifacts get get
828− put (Artifacts a b) = put a >> put b
829−
830−
831−instance Binary ArtifactCache where
832− get = liftM2 ArtifactCache get get
833− put (ArtifactCache a b) = put a >> put b
builder/src/Elm/Outline.hsdeleted−407
@@ -1,407 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE MultiWayIf, OverloadedStrings #-}
3−module Elm.Outline
4− ( Outline(..)
5− , AppOutline(..)
6− , PkgOutline(..)
7− , Exposed(..)
8− , SrcDir(..)
9− , read
10− , write
11− , encode
12− , decoder
13− , defaultSummary
14− , flattenExposed
15− )
16− where
17−
18−
19−import Prelude hiding (read)
20−import Control.Monad (filterM, liftM)
21−import Data.Binary (Binary, get, put, getWord8, putWord8)
22−import qualified Data.Map as Map
23−import qualified Data.NonEmptyList as NE
24−import qualified Data.OneOrMore as OneOrMore
25−import Foreign.Ptr (minusPtr)
26−import qualified System.Directory as Dir
27−import qualified System.FilePath as FP
28−import System.FilePath ((</>))
29−
30−import qualified Elm.Constraint as Con
31−import qualified Elm.Licenses as Licenses
32−import qualified Elm.ModuleName as ModuleName
33−import qualified Elm.Package as Pkg
34−import qualified Elm.Version as V
35−import qualified File
36−import qualified Json.Decode as D
37−import qualified Json.Encode as E
38−import Json.Encode ((==>))
39−import qualified Json.String as Json
40−import qualified Parse.Primitives as P
41−import qualified Reporting.Exit as Exit
42−
43−
44−
45−-- OUTLINE
46−
47−
48−data Outline
49− = App AppOutline
50− | Pkg PkgOutline
51−
52−
53−data AppOutline =
54− AppOutline
55− { _app_elm_version :: V.Version
56− , _app_source_dirs :: NE.List SrcDir
57− , _app_deps_direct :: Map.Map Pkg.Name V.Version
58− , _app_deps_indirect :: Map.Map Pkg.Name V.Version
59− , _app_test_direct :: Map.Map Pkg.Name V.Version
60− , _app_test_indirect :: Map.Map Pkg.Name V.Version
61− }
62−
63−
64−data PkgOutline =
65− PkgOutline
66− { _pkg_name :: Pkg.Name
67− , _pkg_summary :: Json.String
68− , _pkg_license :: Licenses.License
69− , _pkg_version :: V.Version
70− , _pkg_exposed :: Exposed
71− , _pkg_deps :: Map.Map Pkg.Name Con.Constraint
72− , _pkg_test_deps :: Map.Map Pkg.Name Con.Constraint
73− , _pkg_elm_version :: Con.Constraint
74− }
75−
76−
77−data Exposed
78− = ExposedList [ModuleName.Raw]
79− | ExposedDict [(Json.String, [ModuleName.Raw])]
80−
81−
82−data SrcDir
83− = AbsoluteSrcDir FilePath
84− | RelativeSrcDir FilePath
85−
86−
87−
88−-- DEFAULTS
89−
90−
91−defaultSummary :: Json.String
92−defaultSummary =
93− Json.fromChars "helpful summary of your project, less than 80 characters"
94−
95−
96−
97−-- HELPERS
98−
99−
100−flattenExposed :: Exposed -> [ModuleName.Raw]
101−flattenExposed exposed =
102− case exposed of
103− ExposedList names ->
104− names
105−
106− ExposedDict sections ->
107− concatMap snd sections
108−
109−
110−
111−-- WRITE
112−
113−
114−write :: FilePath -> Outline -> IO ()
115−write root outline =
116− E.write (root </> "elm.json") (encode outline)
117−
118−
119−
120−-- JSON ENCODE
121−
122−
123−encode :: Outline -> E.Value
124−encode outline =
125− case outline of
126− App (AppOutline elm srcDirs depsDirect depsTrans testDirect testTrans) ->
127− E.object
128− [ "type" ==> E.chars "application"
129− , "source-directories" ==> E.list encodeSrcDir (NE.toList srcDirs)
130− , "elm-version" ==> V.encode elm
131− , "dependencies" ==>
132− E.object
133− [ "direct" ==> encodeDeps V.encode depsDirect
134− , "indirect" ==> encodeDeps V.encode depsTrans
135− ]
136− , "test-dependencies" ==>
137− E.object
138− [ "direct" ==> encodeDeps V.encode testDirect
139− , "indirect" ==> encodeDeps V.encode testTrans
140− ]
141− ]
142−
143− Pkg (PkgOutline name summary license version exposed deps tests elm) ->
144− E.object
145− [ "type" ==> E.string (Json.fromChars "package")
146− , "name" ==> Pkg.encode name
147− , "summary" ==> E.string summary
148− , "license" ==> Licenses.encode license
149− , "version" ==> V.encode version
150− , "exposed-modules" ==> encodeExposed exposed
151− , "elm-version" ==> Con.encode elm
152− , "dependencies" ==> encodeDeps Con.encode deps
153− , "test-dependencies" ==> encodeDeps Con.encode tests
154− ]
155−
156−
157−encodeExposed :: Exposed -> E.Value
158−encodeExposed exposed =
159− case exposed of
160− ExposedList modules ->
161− E.list encodeModule modules
162−
163− ExposedDict chunks ->
164− E.object (map (fmap (E.list encodeModule)) chunks)
165−
166−
167−encodeModule :: ModuleName.Raw -> E.Value
168−encodeModule name =
169− E.name name
170−
171−
172−encodeDeps :: (a -> E.Value) -> Map.Map Pkg.Name a -> E.Value
173−encodeDeps encodeValue deps =
174− E.dict Pkg.toJsonString encodeValue deps
175−
176−
177−encodeSrcDir :: SrcDir -> E.Value
178−encodeSrcDir srcDir =
179− case srcDir of
180− AbsoluteSrcDir dir -> E.chars dir
181− RelativeSrcDir dir -> E.chars dir
182−
183−
184−
185−-- PARSE AND VERIFY
186−
187−
188−read :: FilePath -> IO (Either Exit.Outline Outline)
189−read root =
190− do bytes <- File.readUtf8 (root </> "elm.json")
191− case D.fromByteString decoder bytes of
192− Left err ->
193− return $ Left (Exit.OutlineHasBadStructure err)
194−
195− Right outline ->
196− case outline of
197− Pkg (PkgOutline pkg _ _ _ _ deps _ _) ->
198− return $
199− if Map.notMember Pkg.core deps && pkg /= Pkg.core
200− then Left Exit.OutlineNoPkgCore
201− else Right outline
202−
203− App (AppOutline _ srcDirs direct indirect _ _)
204− | Map.notMember Pkg.core direct ->
205− return $ Left Exit.OutlineNoAppCore
206−
207− | Map.notMember Pkg.json direct && Map.notMember Pkg.json indirect ->
208− return $ Left Exit.OutlineNoAppJson
209−
210− | otherwise ->
211− do badDirs <- filterM (isSrcDirMissing root) (NE.toList srcDirs)
212− case map toGiven badDirs of
213− d:ds ->
214− return $ Left (Exit.OutlineHasMissingSrcDirs d ds)
215−
216− [] ->
217− do maybeDups <- detectDuplicates root (NE.toList srcDirs)
218− case maybeDups of
219− Nothing ->
220− return $ Right outline
221−
222− Just (canonicalDir, (dir1,dir2)) ->
223− return $ Left (Exit.OutlineHasDuplicateSrcDirs canonicalDir dir1 dir2)
224−
225−
226−isSrcDirMissing :: FilePath -> SrcDir -> IO Bool
227−isSrcDirMissing root srcDir =
228− not <$> Dir.doesDirectoryExist (toAbsolute root srcDir)
229−
230−
231−toGiven :: SrcDir -> FilePath
232−toGiven srcDir =
233− case srcDir of
234− AbsoluteSrcDir dir -> dir
235− RelativeSrcDir dir -> dir
236−
237−
238−toAbsolute :: FilePath -> SrcDir -> FilePath
239−toAbsolute root srcDir =
240− case srcDir of
241− AbsoluteSrcDir dir -> dir
242− RelativeSrcDir dir -> root </> dir
243−
244−
245−detectDuplicates :: FilePath -> [SrcDir] -> IO (Maybe (FilePath, (FilePath, FilePath)))
246−detectDuplicates root srcDirs =
247− do pairs <- traverse (toPair root) srcDirs
248− return $ Map.lookupMin $ Map.mapMaybe isDup $
249− Map.fromListWith OneOrMore.more pairs
250−
251−
252−toPair :: FilePath -> SrcDir -> IO (FilePath, OneOrMore.OneOrMore FilePath)
253−toPair root srcDir =
254− do key <- Dir.canonicalizePath (toAbsolute root srcDir)
255− return (key, OneOrMore.one (toGiven srcDir))
256−
257−
258−isDup :: OneOrMore.OneOrMore FilePath -> Maybe (FilePath, FilePath)
259−isDup paths =
260− case paths of
261− OneOrMore.One _ -> Nothing
262− OneOrMore.More a b -> Just (OneOrMore.getFirstTwo a b)
263−
264−
265−
266−-- JSON DECODE
267−
268−
269−type Decoder a =
270− D.Decoder Exit.OutlineProblem a
271−
272−
273−decoder :: Decoder Outline
274−decoder =
275− let
276− application = Json.fromChars "application"
277− package = Json.fromChars "package"
278− in
279− do tipe <- D.field "type" D.string
280− if | tipe == application -> App <$> appDecoder
281− | tipe == package -> Pkg <$> pkgDecoder
282− | otherwise -> D.failure Exit.OP_BadType
283−
284−
285−appDecoder :: Decoder AppOutline
286−appDecoder =
287− AppOutline
288− <$> D.field "elm-version" versionDecoder
289− <*> D.field "source-directories" dirsDecoder
290− <*> D.field "dependencies" (D.field "direct" (depsDecoder versionDecoder))
291− <*> D.field "dependencies" (D.field "indirect" (depsDecoder versionDecoder))
292− <*> D.field "test-dependencies" (D.field "direct" (depsDecoder versionDecoder))
293− <*> D.field "test-dependencies" (D.field "indirect" (depsDecoder versionDecoder))
294−
295−
296−pkgDecoder :: Decoder PkgOutline
297−pkgDecoder =
298− PkgOutline
299− <$> D.field "name" nameDecoder
300− <*> D.field "summary" summaryDecoder
301− <*> D.field "license" (Licenses.decoder Exit.OP_BadLicense)
302− <*> D.field "version" versionDecoder
303− <*> D.field "exposed-modules" exposedDecoder
304− <*> D.field "dependencies" (depsDecoder constraintDecoder)
305− <*> D.field "test-dependencies" (depsDecoder constraintDecoder)
306− <*> D.field "elm-version" constraintDecoder
307−
308−
309−
310−-- JSON DECODE HELPERS
311−
312−
313−nameDecoder :: Decoder Pkg.Name
314−nameDecoder =
315− D.mapError (uncurry Exit.OP_BadPkgName) Pkg.decoder
316−
317−
318−summaryDecoder :: Decoder Json.String
319−summaryDecoder =
320− D.customString
321− (boundParser 80 Exit.OP_BadSummaryTooLong)
322− (\_ _ -> Exit.OP_BadSummaryTooLong)
323−
324−
325−versionDecoder :: Decoder V.Version
326−versionDecoder =
327− D.mapError (uncurry Exit.OP_BadVersion) V.decoder
328−
329−
330−constraintDecoder :: Decoder Con.Constraint
331−constraintDecoder =
332− D.mapError Exit.OP_BadConstraint Con.decoder
333−
334−
335−depsDecoder :: Decoder a -> Decoder (Map.Map Pkg.Name a)
336−depsDecoder valueDecoder =
337− D.dict (Pkg.keyDecoder Exit.OP_BadDependencyName) valueDecoder
338−
339−
340−dirsDecoder :: Decoder (NE.List SrcDir)
341−dirsDecoder =
342− fmap (toSrcDir . Json.toChars) <$> D.nonEmptyList D.string Exit.OP_NoSrcDirs
343−
344−
345−toSrcDir :: FilePath -> SrcDir
346−toSrcDir path =
347− if FP.isRelative path
348− then RelativeSrcDir path
349− else AbsoluteSrcDir path
350−
351−
352−
353−-- EXPOSED MODULES DECODER
354−
355−
356−exposedDecoder :: Decoder Exposed
357−exposedDecoder =
358− D.oneOf
359− [ ExposedList <$> D.list moduleDecoder
360− , ExposedDict <$> D.pairs headerKeyDecoder (D.list moduleDecoder)
361− ]
362−
363−
364−moduleDecoder :: Decoder ModuleName.Raw
365−moduleDecoder =
366− D.mapError (uncurry Exit.OP_BadModuleName) ModuleName.decoder
367−
368−
369−headerKeyDecoder :: D.KeyDecoder Exit.OutlineProblem Json.String
370−headerKeyDecoder =
371− D.KeyDecoder
372− (boundParser 20 Exit.OP_BadModuleHeaderTooLong)
373− (\_ _ -> Exit.OP_BadModuleHeaderTooLong)
374−
375−
376−
377−-- BOUND PARSER
378−
379−
380−boundParser :: Int -> x -> P.Parser x Json.String
381−boundParser bound tooLong =
382− P.Parser $ \(P.State src pos end indent row col) cok _ cerr _ ->
383− let
384− len = minusPtr end pos
385− newCol = col + fromIntegral len
386− in
387− if len < bound
388− then cok (Json.fromPtr pos end) (P.State src end end indent row newCol)
389− else cerr row newCol (\_ _ -> tooLong)
390−
391−
392−
393−-- BINARY
394−
395−
396−instance Binary SrcDir where
397− put outline =
398− case outline of
399− AbsoluteSrcDir a -> putWord8 0 >> put a
400− RelativeSrcDir a -> putWord8 1 >> put a
401−
402− get =
403− do n <- getWord8
404− case n of
405− 0 -> liftM AbsoluteSrcDir get
406− 1 -> liftM RelativeSrcDir get
407− _ -> fail "binary encoding of SrcDir was corrupted"
builder/src/File.hsdeleted−231
@@ -1,231 +0,0 @@
1−module File
2− ( Time
3− , getTime
4− , zeroTime
5− , writeBinary
6− , readBinary
7− , writeUtf8
8− , readUtf8
9− , writeBuilder
10− , writePackage
11− , exists
12− , remove
13− , removeDir
14− )
15− where
16−
17−
18−import qualified Codec.Archive.Zip as Zip
19−import Control.Exception (catch)
20−import qualified Data.Binary as Binary
21−import qualified Data.ByteString as BS
22−import qualified Data.ByteString.Internal as BS
23−import qualified Data.ByteString.Builder as B
24−import qualified Data.ByteString.Lazy as LBS
25−import qualified Data.Fixed as Fixed
26−import qualified Data.List as List
27−import qualified Data.Time.Clock as Time
28−import qualified Data.Time.Clock.POSIX as Time
29−import qualified Foreign.ForeignPtr as FPtr
30−import GHC.IO.Exception (IOException, IOErrorType(InvalidArgument))
31−import qualified System.Directory as Dir
32−import qualified System.FilePath as FP
33−import System.FilePath ((</>))
34−import qualified System.IO as IO
35−import System.IO.Error (ioeGetErrorType, annotateIOError, modifyIOError)
36−
37−
38−
39−-- TIME
40−
41−
42−newtype Time = Time Fixed.Pico
43− deriving (Eq, Ord)
44−
45−
46−getTime :: FilePath -> IO Time
47−getTime path =
48− fmap
49− (Time . Time.nominalDiffTimeToSeconds . Time.utcTimeToPOSIXSeconds)
50− (Dir.getModificationTime path)
51−
52−
53−zeroTime :: Time
54−zeroTime =
55− Time 0
56−
57−
58−instance Binary.Binary Time where
59− put (Time time) = Binary.put time
60− get = Time <$> Binary.get
61−
62−
63−
64−-- BINARY
65−
66−
67−writeBinary :: (Binary.Binary a) => FilePath -> a -> IO ()
68−writeBinary path value =
69− do let dir = FP.dropFileName path
70− Dir.createDirectoryIfMissing True dir
71− Binary.encodeFile path value
72−
73−
74−readBinary :: (Binary.Binary a) => FilePath -> IO (Maybe a)
75−readBinary path =
76− do pathExists <- Dir.doesFileExist path
77− if pathExists
78− then
79− do result <- Binary.decodeFileOrFail path
80− case result of
81− Right a ->
82− return (Just a)
83−
84− Left (offset, message) ->
85− do IO.hPutStrLn IO.stderr $ unlines $
86− [ "+-------------------------------------------------------------------------------"
87− , "| Corrupt File: " ++ path
88− , "| Byte Offset: " ++ show offset
89− , "| Message: " ++ message
90− , "|"
91− , "| Please report this to https://github.com/elm/compiler/issues"
92− , "| Trying to continue anyway."
93− , "+-------------------------------------------------------------------------------"
94− ]
95− return Nothing
96− else
97− return Nothing
98−
99−
100−
101−-- WRITE UTF-8
102−
103−
104−writeUtf8 :: FilePath -> BS.ByteString -> IO ()
105−writeUtf8 path content =
106− withUtf8 path IO.WriteMode $ \handle ->
107− BS.hPut handle content
108−
109−
110−withUtf8 :: FilePath -> IO.IOMode -> (IO.Handle -> IO a) -> IO a
111−withUtf8 path mode callback =
112− IO.withFile path mode $ \handle ->
113− do IO.hSetEncoding handle IO.utf8
114− callback handle
115−
116−
117−
118−-- READ UTF-8
119−
120−
121−readUtf8 :: FilePath -> IO BS.ByteString
122−readUtf8 path =
123− withUtf8 path IO.ReadMode $ \handle ->
124− modifyIOError (encodingError path) $
125− do fileSize <- catch (IO.hFileSize handle) useZeroIfNotRegularFile
126− let readSize = max 0 (fromIntegral fileSize) + 1
127− hGetContentsSizeHint handle readSize (max 255 readSize)
128−
129−
130−useZeroIfNotRegularFile :: IOException -> IO Integer
131−useZeroIfNotRegularFile _ =
132− return 0
133−
134−
135−hGetContentsSizeHint :: IO.Handle -> Int -> Int -> IO BS.ByteString
136−hGetContentsSizeHint handle =
137− readChunks []
138− where
139− readChunks chunks readSize incrementSize =
140− do fp <- BS.mallocByteString readSize
141− readCount <- FPtr.withForeignPtr fp $ \buf -> IO.hGetBuf handle buf readSize
142− let chunk = BS.PS fp 0 readCount
143− if readCount < readSize && readSize > 0
144− then return $! BS.concat (reverse (chunk:chunks))
145− else readChunks (chunk:chunks) incrementSize (min 32752 (readSize + incrementSize))
146−
147−
148−encodingError :: FilePath -> IOError -> IOError
149−encodingError path ioErr =
150− case ioeGetErrorType ioErr of
151− InvalidArgument ->
152− annotateIOError
153− (userError "Bad encoding; the file must be valid UTF-8")
154− ""
155− Nothing
156− (Just path)
157−
158− _ ->
159− ioErr
160−
161−
162−
163−-- WRITE BUILDER
164−
165−
166−writeBuilder :: FilePath -> B.Builder -> IO ()
167−writeBuilder path builder =
168− IO.withBinaryFile path IO.WriteMode $ \handle ->
169− do IO.hSetBuffering handle (IO.BlockBuffering Nothing)
170− B.hPutBuilder handle builder
171−
172−
173−
174−-- WRITE PACKAGE
175−
176−
177−writePackage :: FilePath -> Zip.Archive -> IO ()
178−writePackage destination archive =
179− case Zip.zEntries archive of
180− [] ->
181− return ()
182−
183− entry:entries ->
184− do let root = length (Zip.eRelativePath entry)
185− mapM_ (writeEntry destination root) entries
186−
187−
188−writeEntry :: FilePath -> Int -> Zip.Entry -> IO ()
189−writeEntry destination root entry =
190− let
191− path = drop root (Zip.eRelativePath entry)
192− in
193− if List.isPrefixOf "src/" path
194− || path == "LICENSE"
195− || path == "README.md"
196− || path == "elm.json"
197− then
198− if not (null path) && last path == '/'
199− then Dir.createDirectoryIfMissing True (destination </> path)
200− else LBS.writeFile (destination </> path) (Zip.fromEntry entry)
201− else
202− return ()
203−
204−
205−
206−-- EXISTS
207−
208−
209−exists :: FilePath -> IO Bool
210−exists path =
211− Dir.doesFileExist path
212−
213−
214−
215−-- REMOVE FILES
216−
217−
218−remove :: FilePath -> IO ()
219−remove path =
220− do exists_ <- Dir.doesFileExist path
221− if exists_
222− then Dir.removeFile path
223− else return ()
224−
225−
226−removeDir :: FilePath -> IO ()
227−removeDir path =
228− do exists_ <- Dir.doesDirectoryExist path
229− if exists_
230− then Dir.removeDirectoryRecursive path
231− else return ()
builder/src/Generate.hsdeleted−211
@@ -1,211 +0,0 @@
1−{-# LANGUAGE BangPatterns #-}
2−module Generate
3− ( debug
4− , dev
5− , prod
6− , repl
7− )
8− where
9−
10−
11−import Prelude hiding (cycle, print)
12−import Control.Concurrent (MVar, forkIO, newEmptyMVar, newMVar, putMVar, readMVar)
13−import Control.Monad (liftM2)
14−import qualified Data.ByteString.Builder as B
15−import Data.Map ((!))
16−import qualified Data.Map as Map
17−import qualified Data.Maybe as Maybe
18−import qualified Data.Name as N
19−import qualified Data.NonEmptyList as NE
20−
21−import qualified AST.Optimized as Opt
22−import qualified Build
23−import qualified Elm.Compiler.Type.Extract as Extract
24−import qualified Elm.Details as Details
25−import qualified Elm.Interface as I
26−import qualified Elm.ModuleName as ModuleName
27−import qualified Elm.Package as Pkg
28−import qualified File
29−import qualified Generate.JavaScript as JS
30−import qualified Generate.Mode as Mode
31−import qualified Nitpick.Debug as Nitpick
32−import qualified Reporting.Exit as Exit
33−import qualified Reporting.Task as Task
34−import qualified Stuff
35−
36−
37−-- NOTE: This is used by Make, Repl, and Reactor right now. But it may be
38−-- desireable to have Repl and Reactor to keep foreign objects in memory
39−-- to make things a bit faster?
40−
41−
42−
43−-- GENERATORS
44−
45−
46−type Task a =
47− Task.Task Exit.Generate a
48−
49−
50−debug :: FilePath -> Details.Details -> Build.Artifacts -> Task B.Builder
51−debug root details (Build.Artifacts pkg ifaces roots modules) =
52− do loading <- loadObjects root details modules
53− types <- loadTypes root ifaces modules
54− objects <- finalizeObjects loading
55− let mode = Mode.Dev (Just types)
56− let graph = objectsToGlobalGraph objects
57− let mains = gatherMains pkg objects roots
58− return $ JS.generate mode graph mains
59−
60−
61−dev :: FilePath -> Details.Details -> Build.Artifacts -> Task B.Builder
62−dev root details (Build.Artifacts pkg _ roots modules) =
63− do objects <- finalizeObjects =<< loadObjects root details modules
64− let mode = Mode.Dev Nothing
65− let graph = objectsToGlobalGraph objects
66− let mains = gatherMains pkg objects roots
67− return $ JS.generate mode graph mains
68−
69−
70−prod :: FilePath -> Details.Details -> Build.Artifacts -> Task B.Builder
71−prod root details (Build.Artifacts pkg _ roots modules) =
72− do objects <- finalizeObjects =<< loadObjects root details modules
73− checkForDebugUses objects
74− let graph = objectsToGlobalGraph objects
75− let mode = Mode.Prod (Mode.shortenFieldNames graph)
76− let mains = gatherMains pkg objects roots
77− return $ JS.generate mode graph mains
78−
79−
80−repl :: FilePath -> Details.Details -> Bool -> Build.ReplArtifacts -> N.Name -> Task B.Builder
81−repl root details ansi (Build.ReplArtifacts home modules localizer annotations) name =
82− do objects <- finalizeObjects =<< loadObjects root details modules
83− let graph = objectsToGlobalGraph objects
84− return $ JS.generateForRepl ansi localizer graph home name (annotations ! name)
85−
86−
87−
88−-- CHECK FOR DEBUG
89−
90−
91−checkForDebugUses :: Objects -> Task ()
92−checkForDebugUses (Objects _ locals) =
93− case Map.keys (Map.filter Nitpick.hasDebugUses locals) of
94− [] -> return ()
95− m:ms -> Task.throw (Exit.GenerateCannotOptimizeDebugValues m ms)
96−
97−
98−
99−-- GATHER MAINS
100−
101−
102−gatherMains :: Pkg.Name -> Objects -> NE.List Build.Root -> Map.Map ModuleName.Canonical Opt.Main
103−gatherMains pkg (Objects _ locals) roots =
104− Map.fromList $ Maybe.mapMaybe (lookupMain pkg locals) (NE.toList roots)
105−
106−
107−lookupMain :: Pkg.Name -> Map.Map ModuleName.Raw Opt.LocalGraph -> Build.Root -> Maybe (ModuleName.Canonical, Opt.Main)
108−lookupMain pkg locals root =
109− let
110− toPair name (Opt.LocalGraph maybeMain _ _) =
111− (,) (ModuleName.Canonical pkg name) <$> maybeMain
112− in
113− case root of
114− Build.Inside name -> toPair name =<< Map.lookup name locals
115− Build.Outside name _ g -> toPair name g
116−
117−
118−
119−-- LOADING OBJECTS
120−
121−
122−data LoadingObjects =
123− LoadingObjects
124− { _foreign_mvar :: MVar (Maybe Opt.GlobalGraph)
125− , _local_mvars :: Map.Map ModuleName.Raw (MVar (Maybe Opt.LocalGraph))
126− }
127−
128−
129−loadObjects :: FilePath -> Details.Details -> [Build.Module] -> Task LoadingObjects
130−loadObjects root details modules =
131− Task.io $
132− do mvar <- Details.loadObjects root details
133− mvars <- traverse (loadObject root) modules
134− return $ LoadingObjects mvar (Map.fromList mvars)
135−
136−
137−loadObject :: FilePath -> Build.Module -> IO (ModuleName.Raw, MVar (Maybe Opt.LocalGraph))
138−loadObject root modul =
139− case modul of
140− Build.Fresh name _ graph ->
141− do mvar <- newMVar (Just graph)
142− return (name, mvar)
143−
144− Build.Cached name _ _ ->
145− do mvar <- newEmptyMVar
146− _ <- forkIO $ putMVar mvar =<< File.readBinary (Stuff.elmo root name)
147− return (name, mvar)
148−
149−
150−
151−-- FINALIZE OBJECTS
152−
153−
154−data Objects =
155− Objects
156− { _foreign :: Opt.GlobalGraph
157− , _locals :: Map.Map ModuleName.Raw Opt.LocalGraph
158− }
159−
160−
161−finalizeObjects :: LoadingObjects -> Task Objects
162−finalizeObjects (LoadingObjects mvar mvars) =
163− Task.eio id $
164− do result <- readMVar mvar
165− results <- traverse readMVar mvars
166− case liftM2 Objects result (sequence results) of
167− Just loaded -> return (Right loaded)
168− Nothing -> return (Left Exit.GenerateCannotLoadArtifacts)
169−
170−
171−objectsToGlobalGraph :: Objects -> Opt.GlobalGraph
172−objectsToGlobalGraph (Objects globals locals) =
173− foldr Opt.addLocalGraph globals locals
174−
175−
176−
177−-- LOAD TYPES
178−
179−
180−loadTypes :: FilePath -> Map.Map ModuleName.Canonical I.DependencyInterface -> [Build.Module] -> Task Extract.Types
181−loadTypes root ifaces modules =
182− Task.eio id $
183− do mvars <- traverse (loadTypesHelp root) modules
184− let !foreigns = Extract.mergeMany (Map.elems (Map.mapWithKey Extract.fromDependencyInterface ifaces))
185− results <- traverse readMVar mvars
186− case sequence results of
187− Just ts -> return (Right (Extract.merge foreigns (Extract.mergeMany ts)))
188− Nothing -> return (Left Exit.GenerateCannotLoadArtifacts)
189−
190−
191−loadTypesHelp :: FilePath -> Build.Module -> IO (MVar (Maybe Extract.Types))
192−loadTypesHelp root modul =
193− case modul of
194− Build.Fresh name iface _ ->
195− newMVar (Just (Extract.fromInterface name iface))
196−
197− Build.Cached name _ ciMVar ->
198− do cachedInterface <- readMVar ciMVar
199− case cachedInterface of
200− Build.Unneeded ->
201− do mvar <- newEmptyMVar
202− _ <- forkIO $
203− do maybeIface <- File.readBinary (Stuff.elmi root name)
204− putMVar mvar (Extract.fromInterface name <$> maybeIface)
205− return mvar
206−
207− Build.Loaded iface ->
208− newMVar (Just (Extract.fromInterface name iface))
209−
210− Build.Corrupted ->
211− newMVar Nothing
builder/src/Http.hsdeleted−244
@@ -1,244 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Http
3− ( Manager
4− , getManager
5− , toUrl
6− -- fetch
7− , get
8− , post
9− , Header
10− , accept
11− , Error(..)
12− -- archives
13− , Sha
14− , shaToChars
15− , getArchive
16− -- upload
17− , upload
18− , filePart
19− , jsonPart
20− , stringPart
21− )
22− where
23−
24−
25−import Prelude hiding (zip)
26−import qualified Codec.Archive.Zip as Zip
27−import Control.Exception (SomeException, handle)
28−import qualified Data.Binary as Binary
29−import qualified Data.Binary.Get as Binary
30−import qualified Data.ByteString.Builder as B
31−import qualified Data.ByteString.Char8 as BS
32−import qualified Data.Digest.Pure.SHA as SHA
33−import qualified Data.String as String
34−import Network.HTTP (urlEncodeVars)
35−import Network.HTTP.Client
36−import Network.HTTP.Client.TLS (tlsManagerSettings)
37−import Network.HTTP.Types.Header (Header, hAccept, hAcceptEncoding, hUserAgent)
38−import Network.HTTP.Types.Method (Method, methodGet, methodPost)
39−import qualified Network.HTTP.Client as Multi (RequestBody(RequestBodyLBS))
40−import qualified Network.HTTP.Client.MultipartFormData as Multi
41−
42−import qualified Json.Encode as Encode
43−import qualified Elm.Version as V
44−
45−
46−
47−-- MANAGER
48−
49−
50−getManager :: IO Manager
51−getManager =
52− newManager tlsManagerSettings
53−
54−
55−
56−-- URL
57−
58−
59−toUrl :: String -> [(String,String)] -> String
60−toUrl url params =
61− case params of
62− [] -> url
63− _:_ -> url ++ "?" ++ urlEncodeVars params
64−
65−
66−
67−-- FETCH
68−
69−
70−get :: Manager -> String -> [Header] -> (Error -> e) -> (BS.ByteString -> IO (Either e a)) -> IO (Either e a)
71−get =
72− fetch methodGet
73−
74−
75−post :: Manager -> String -> [Header] -> (Error -> e) -> (BS.ByteString -> IO (Either e a)) -> IO (Either e a)
76−post =
77− fetch methodPost
78−
79−
80−fetch :: Method -> Manager -> String -> [Header] -> (Error -> e) -> (BS.ByteString -> IO (Either e a)) -> IO (Either e a)
81−fetch methodVerb manager url headers onError onSuccess =
82− handle (handleSomeException url onError) $
83− handle (handleHttpException url onError) $
84− do req0 <- parseUrlThrow url
85− let req1 =
86− req0
87− { method = methodVerb
88− , requestHeaders = addDefaultHeaders headers
89− }
90− withResponse req1 manager $ \response ->
91− do chunks <- brConsume (responseBody response)
92− onSuccess (BS.concat chunks)
93−
94−
95−addDefaultHeaders :: [Header] -> [Header]
96−addDefaultHeaders headers =
97− (hUserAgent, userAgent) : (hAcceptEncoding, "gzip") : headers
98−
99−
100−{-# NOINLINE userAgent #-}
101−userAgent :: BS.ByteString
102−userAgent =
103− BS.pack ("elm/" ++ V.toChars V.compiler)
104−
105−
106−accept :: BS.ByteString -> Header
107−accept mime =
108− (hAccept, mime)
109−
110−
111−
112−-- EXCEPTIONS
113−
114−
115−data Error
116− = BadUrl String String
117− | BadHttp String HttpExceptionContent
118− | BadMystery String SomeException
119−
120−
121−handleHttpException :: String -> (Error -> e) -> HttpException -> IO (Either e a)
122−handleHttpException url onError httpException =
123− case httpException of
124− InvalidUrlException _ reason ->
125− return (Left (onError (BadUrl url reason)))
126−
127− HttpExceptionRequest _ content ->
128− return (Left (onError (BadHttp url content)))
129−
130−
131−handleSomeException :: String -> (Error -> e) -> SomeException -> IO (Either e a)
132−handleSomeException url onError exception =
133− return (Left (onError (BadMystery url exception)))
134−
135−
136−
137−-- SHA
138−
139−
140−type Sha = SHA.Digest SHA.SHA1State
141−
142−
143−shaToChars :: Sha -> String
144−shaToChars =
145− SHA.showDigest
146−
147−
148−
149−-- FETCH ARCHIVE
150−
151−
152−getArchive
153− :: Manager
154− -> String
155− -> (Error -> e)
156− -> e
157− -> ((Sha, Zip.Archive) -> IO (Either e a))
158− -> IO (Either e a)
159−getArchive manager url onError err onSuccess =
160− handle (handleSomeException url onError) $
161− handle (handleHttpException url onError) $
162− do req0 <- parseUrlThrow url
163− let req1 =
164− req0
165− { method = methodGet
166− , requestHeaders = addDefaultHeaders []
167− }
168− withResponse req1 manager $ \response ->
169− do result <- readArchive (responseBody response)
170− case result of
171− Nothing -> return (Left err)
172− Just shaAndArchive -> onSuccess shaAndArchive
173−
174−
175−readArchive :: BodyReader -> IO (Maybe (Sha, Zip.Archive))
176−readArchive body =
177− readArchiveHelp body $
178− AS 0 SHA.sha1Incremental (Binary.runGetIncremental Binary.get)
179−
180−
181−data ArchiveState =
182− AS
183− { _len :: !Int
184− , _sha :: !(Binary.Decoder SHA.SHA1State)
185− , _zip :: !(Binary.Decoder Zip.Archive)
186− }
187−
188−
189−readArchiveHelp :: BodyReader -> ArchiveState -> IO (Maybe (Sha, Zip.Archive))
190−readArchiveHelp body (AS len sha zip) =
191− case zip of
192− Binary.Fail _ _ _ ->
193− return Nothing
194−
195− Binary.Partial k ->
196− do chunk <- brRead body
197− readArchiveHelp body $
198− AS
199− { _len = len + BS.length chunk
200− , _sha = Binary.pushChunk sha chunk
201− , _zip = k (if BS.null chunk then Nothing else Just chunk)
202− }
203−
204− Binary.Done _ _ archive ->
205− return $ Just ( SHA.completeSha1Incremental sha len, archive )
206−
207−
208−
209−-- UPLOAD
210−
211−
212−upload :: Manager -> String -> [Multi.Part] -> IO (Either Error ())
213−upload manager url parts =
214− handle (handleSomeException url id) $
215− handle (handleHttpException url id) $
216− do req0 <- parseUrlThrow url
217− req1 <-
218− Multi.formDataBody parts $
219− req0
220− { method = methodPost
221− , requestHeaders = addDefaultHeaders []
222− , responseTimeout = responseTimeoutNone
223− }
224− withResponse req1 manager $ \_ ->
225− return (Right ())
226−
227−
228−filePart :: String -> FilePath -> Multi.Part
229−filePart name filePath =
230− Multi.partFileSource (String.fromString name) filePath
231−
232−
233−jsonPart :: String -> FilePath -> Encode.Value -> Multi.Part
234−jsonPart name filePath value =
235− let
236− body =
237− Multi.RequestBodyLBS $ B.toLazyByteString $ Encode.encodeUgly value
238− in
239− Multi.partFileRequestBody (String.fromString name) filePath body
240−
241−
242−stringPart :: String -> String -> Multi.Part
243−stringPart name string =
244− Multi.partBS (String.fromString name) (BS.pack string)
builder/src/Reporting.hsdeleted−474
@@ -1,474 +0,0 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
2−module Reporting
3− ( Style
4− , silent
5− , json
6− , terminal
7− --
8− , attempt
9− , attemptWithStyle
10− --
11− , Key
12− , report
13− , ignorer
14− , ask
15− --
16− , DKey
17− , DMsg(..)
18− , trackDetails
19− --
20− , BKey
21− , BMsg(..)
22− , trackBuild
23− --
24− , reportGenerate
25− )
26− where
27−
28−
29−import Control.Concurrent
30−import Control.Exception (SomeException, AsyncException(UserInterrupt), catch, fromException, throw)
31−import Control.Monad (when)
32−import qualified Data.ByteString.Builder as B
33−import qualified Data.NonEmptyList as NE
34−import qualified System.Exit as Exit
35−import qualified System.Info as Info
36−import System.IO (hFlush, hPutStr, hPutStrLn, stderr, stdout)
37−
38−import qualified Elm.ModuleName as ModuleName
39−import qualified Elm.Package as Pkg
40−import qualified Elm.Version as V
41−import qualified Json.Encode as Encode
42−import Reporting.Doc ((<+>), (<>))
43−import qualified Reporting.Doc as D
44−import qualified Reporting.Exit as Exit
45−import qualified Reporting.Exit.Help as Help
46−
47−
48−
49−-- STYLE
50−
51−
52−data Style
53− = Silent
54− | Json
55− | Terminal (MVar ())
56−
57−
58−silent :: Style
59−silent =
60− Silent
61−
62−
63−json :: Style
64−json =
65− Json
66−
67−
68−terminal :: IO Style
69−terminal =
70− Terminal <$> newMVar ()
71−
72−
73−
74−-- ATTEMPT
75−
76−
77−attempt :: (x -> Help.Report) -> IO (Either x a) -> IO a
78−attempt toReport work =
79− do result <- work `catch` reportExceptionsNicely
80− case result of
81− Right a ->
82− return a
83−
84− Left x ->
85− do Exit.toStderr (toReport x)
86− Exit.exitFailure
87−
88−
89−attemptWithStyle :: Style -> (x -> Help.Report) -> IO (Either x a) -> IO a
90−attemptWithStyle style toReport work =
91− do result <- work `catch` reportExceptionsNicely
92− case result of
93− Right a ->
94− return a
95−
96− Left x ->
97− case style of
98− Silent ->
99− do Exit.exitFailure
100−
101− Json ->
102− do B.hPutBuilder stderr (Encode.encodeUgly (Exit.toJson (toReport x)))
103− Exit.exitFailure
104−
105− Terminal mvar ->
106− do readMVar mvar
107− Exit.toStderr (toReport x)
108− Exit.exitFailure
109−
110−
111−
112−-- MARKS
113−
114−
115−goodMark :: D.Doc
116−goodMark =
117− D.green $ if isWindows then "+" else "●"
118−
119−
120−badMark :: D.Doc
121−badMark =
122− D.red $ if isWindows then "X" else "✗"
123−
124−
125−isWindows :: Bool
126−isWindows =
127− Info.os == "mingw32"
128−
129−
130−
131−-- KEY
132−
133−
134−newtype Key msg = Key (msg -> IO ())
135−
136−
137−report :: Key msg -> msg -> IO ()
138−report (Key send) msg =
139− send msg
140−
141−
142−ignorer :: Key msg
143−ignorer =
144− Key (\_ -> return ())
145−
146−
147−
148−-- ASK
149−
150−
151−ask :: D.Doc -> IO Bool
152−ask doc =
153− do Help.toStdout doc
154− askHelp
155−
156−
157−askHelp :: IO Bool
158−askHelp =
159− do hFlush stdout
160− input <- getLine
161− case input of
162− "" -> return True
163− "Y" -> return True
164− "y" -> return True
165− "n" -> return False
166− _ ->
167− do putStr "Must type 'y' for yes or 'n' for no: "
168− askHelp
169−
170−
171−-- DETAILS
172−
173−
174−type DKey = Key DMsg
175−
176−
177−trackDetails :: Style -> (DKey -> IO a) -> IO a
178−trackDetails style callback =
179− case style of
180− Silent ->
181− callback (Key (\_ -> return ()))
182−
183− Json ->
184− callback (Key (\_ -> return ()))
185−
186− Terminal mvar ->
187− do chan <- newChan
188−
189− _ <- forkIO $
190− do takeMVar mvar
191− detailsLoop chan (DState 0 0 0 0 0 0 0)
192− putMVar mvar ()
193−
194− answer <- callback (Key (writeChan chan . Just))
195− writeChan chan Nothing
196− return answer
197−
198−
199−detailsLoop :: Chan (Maybe DMsg) -> DState -> IO ()
200−detailsLoop chan state@(DState total _ _ _ _ built _) =
201− do msg <- readChan chan
202− case msg of
203− Just dmsg ->
204− detailsLoop chan =<< detailsStep dmsg state
205−
206− Nothing ->
207− putStrLn $ clear (toBuildProgress total total) $
208− if built == total
209− then "Dependencies ready!"
210− else "Dependency problem!"
211−
212−
213−data DState =
214− DState
215− { _total :: !Int
216− , _cached :: !Int
217− , _requested :: !Int
218− , _received :: !Int
219− , _failed :: !Int
220− , _built :: !Int
221− , _broken :: !Int
222− }
223−
224−
225−data DMsg
226− = DStart Int
227− | DCached
228− | DRequested
229− | DReceived Pkg.Name V.Version
230− | DFailed Pkg.Name V.Version
231− | DBuilt
232− | DBroken
233−
234−
235−detailsStep :: DMsg -> DState -> IO DState
236−detailsStep msg (DState total cached rqst rcvd failed built broken) =
237− case msg of
238− DStart numDependencies ->
239− return (DState numDependencies 0 0 0 0 0 0)
240−
241− DCached ->
242− putTransition (DState total (cached + 1) rqst rcvd failed built broken)
243−
244− DRequested ->
245− do when (rqst == 0) (putStrLn "Starting downloads...\n")
246− return (DState total cached (rqst + 1) rcvd failed built broken)
247−
248− DReceived pkg vsn ->
249− do putDownload goodMark pkg vsn
250− putTransition (DState total cached rqst (rcvd + 1) failed built broken)
251−
252− DFailed pkg vsn ->
253− do putDownload badMark pkg vsn
254− putTransition (DState total cached rqst rcvd (failed + 1) built broken)
255−
256− DBuilt ->
257− putBuilt (DState total cached rqst rcvd failed (built + 1) broken)
258−
259− DBroken ->
260− putBuilt (DState total cached rqst rcvd failed built (broken + 1))
261−
262−
263−putDownload :: D.Doc -> Pkg.Name -> V.Version -> IO ()
264−putDownload mark pkg vsn =
265− Help.toStdout $ D.indent 2 $
266− mark
267− <+> D.fromPackage pkg
268− <+> D.fromVersion vsn
269− <> "\n"
270−
271−
272−putTransition :: DState -> IO DState
273−putTransition state@(DState total cached _ rcvd failed built broken) =
274− if cached + rcvd + failed < total then
275− return state
276−
277− else
278− do let char = if rcvd + failed == 0 then '\r' else '\n'
279− putStrFlush (char : toBuildProgress (built + broken + failed) total)
280− return state
281−
282−
283−putBuilt :: DState -> IO DState
284−putBuilt state@(DState total cached _ rcvd failed built broken) =
285− do when (total == cached + rcvd + failed) $
286− putStrFlush $ '\r' : toBuildProgress (built + broken + failed) total
287− return state
288−
289−
290−toBuildProgress :: Int -> Int -> [Char]
291−toBuildProgress built total =
292− "Verifying dependencies (" ++ show built ++ "/" ++ show total ++ ")"
293−
294−
295−clear :: [Char] -> [Char] -> [Char]
296−clear before after =
297− '\r' : replicate (length before) ' ' ++ '\r' : after
298−
299−
300−
301−-- BUILD
302−
303−
304−type BKey = Key BMsg
305−
306−type BResult a = Either Exit.BuildProblem a
307−
308−
309−trackBuild :: Style -> (BKey -> IO (BResult a)) -> IO (BResult a)
310−trackBuild style callback =
311− case style of
312− Silent ->
313− callback (Key (\_ -> return ()))
314−
315− Json ->
316− callback (Key (\_ -> return ()))
317−
318− Terminal mvar ->
319− do chan <- newChan
320−
321− _ <- forkIO $
322− do takeMVar mvar
323− putStrFlush "Compiling ..."
324− buildLoop chan 0
325− putMVar mvar ()
326−
327− result <- callback (Key (writeChan chan . Left))
328− writeChan chan (Right result)
329− return result
330−
331−
332−data BMsg
333− = BDone
334−
335−
336−buildLoop :: Chan (Either BMsg (BResult a)) -> Int -> IO ()
337−buildLoop chan done =
338− do msg <- readChan chan
339− case msg of
340− Left BDone ->
341− do let !done1 = done + 1
342− putStrFlush $ "\rCompiling (" ++ show done1 ++ ")"
343− buildLoop chan done1
344−
345− Right result ->
346− let
347− !message = toFinalMessage done result
348− !width = 12 + length (show done)
349− in
350− putStrLn $
351− if length message < width
352− then '\r' : replicate width ' ' ++ '\r' : message
353− else '\r' : message
354−
355−
356−toFinalMessage :: Int -> BResult a -> [Char]
357−toFinalMessage done result =
358− case result of
359− Right _ ->
360− case done of
361− 0 -> "Success!"
362− 1 -> "Success! Compiled 1 module."
363− n -> "Success! Compiled " ++ show n ++ " modules."
364−
365− Left problem ->
366− case problem of
367− Exit.BuildBadModules _ _ [] ->
368− "Detected problems in 1 module."
369−
370− Exit.BuildBadModules _ _ (_:ps) ->
371− "Detected problems in " ++ show (2 + length ps) ++ " modules."
372−
373− Exit.BuildProjectProblem _ ->
374− "Detected a problem."
375−
376−
377−
378−-- GENERATE
379−
380−
381−reportGenerate :: Style -> NE.List ModuleName.Raw -> FilePath -> IO ()
382−reportGenerate style names output =
383− case style of
384− Silent ->
385− return ()
386−
387− Json ->
388− return ()
389−
390− Terminal mvar ->
391− do readMVar mvar
392− let cnames = fmap ModuleName.toChars names
393− putStrLn ('\n' : toGenDiagram cnames output)
394−
395−
396−toGenDiagram :: NE.List [Char] -> FilePath -> [Char]
397−toGenDiagram (NE.List name names) output =
398− let
399− width = 3 + foldr (max . length) (length name) names
400− in
401− case names of
402− [] ->
403− toGenLine width name ('>' : ' ' : output ++ "\n")
404−
405− _:_ ->
406− unlines $
407− toGenLine width name (vtop : hbar : hbar : '>' : ' ' : output)
408− : reverse (zipWith (toGenLine width) (reverse names) ([vbottom] : repeat [vmiddle]))
409−
410−
411−toGenLine :: Int -> [Char] -> [Char] -> [Char]
412−toGenLine width name end =
413− " " ++ name ++ ' ' : replicate (width - length name) hbar ++ end
414−
415−
416−hbar :: Char
417−hbar = if isWindows then '-' else '─'
418−
419−vtop :: Char
420−vtop = if isWindows then '+' else '┬'
421−
422−vmiddle :: Char
423−vmiddle = if isWindows then '+' else '┤'
424−
425−vbottom :: Char
426−vbottom = if isWindows then '+' else '┘'
427−
428−
429−--
430−
431−
432−putStrFlush :: String -> IO ()
433−putStrFlush str =
434− hPutStr stdout str >> hFlush stdout
435−
436−
437−
438−-- REPORT EXCEPTIONS NICELY
439−
440−
441−reportExceptionsNicely :: SomeException -> IO a
442−reportExceptionsNicely e =
443− case fromException e of
444− Just UserInterrupt -> throw e
445− _ -> putException e >> throw e
446−
447−
448−putException :: SomeException -> IO ()
449−putException e = do
450− hPutStrLn stderr ""
451− Help.toStderr $ D.stack $
452− [ D.dullyellow "-- ERROR -----------------------------------------------------------------------"
453− , D.reflow $
454− "I ran into something that bypassed the normal error reporting process!\
455− \ I extracted whatever information I could from the internal error:"
456− , D.vcat $ map (\line -> D.red ">" <> " " <> D.fromChars line) (lines (show e))
457− , D.reflow $
458− "These errors are usually pretty confusing, so start by asking around on one of\
459− \ forums listed at https://elm-lang.org/community to see if anyone can get you\
460− \ unstuck quickly."
461− , D.dullyellow "-- REQUEST ---------------------------------------------------------------------"
462− , D.reflow $
463− "If you are feeling up to it, please try to get your code down to the smallest\
464− \ version that still triggers this message. Ideally in a single Main.elm and\
465− \ elm.json file."
466− , D.reflow $
467− "From there open a NEW issue at https://github.com/elm/compiler/issues with\
468− \ your reduced example pasted in directly. (Not a link to a repo or gist!) Do not\
469− \ worry about if someone else saw something similar. More examples is better!"
470− , D.reflow $
471− "This kind of error is usually tied up in larger architectural choices that are\
472− \ hard to change, so even when we have a couple good examples, it can take some\
473− \ time to resolve in a solid way."
474− ]
builder/src/Reporting/Exit.hsdeleted−2069
@@ -1,2069 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Reporting.Exit
3− ( Init(..), initToReport
4− , Diff(..), diffToReport
5− , Make(..), makeToReport
6− , Bump(..), bumpToReport
7− , Repl(..), replToReport
8− , Publish(..), publishToReport
9− , Install(..), installToReport
10− , Reactor(..), reactorToReport
11− , newPackageOverview
12− --
13− , Solver(..)
14− , Outline(..)
15− , OutlineProblem(..)
16− , Details(..)
17− , DetailsBadDep(..)
18− , PackageProblem(..)
19− , RegistryProblem(..)
20− , BuildProblem(..)
21− , BuildProjectProblem(..)
22− , DocsProblem(..)
23− , Generate(..)
24− --
25− , toString
26− , toStderr
27− , toJson
28− )
29− where
30−
31−
32−import qualified Data.ByteString as BS
33−import qualified Data.ByteString.UTF8 as BS_UTF8
34−import qualified Data.List as List
35−import qualified Data.Map as Map
36−import qualified Data.Name as N
37−import qualified Data.NonEmptyList as NE
38−import qualified Network.HTTP.Client as HTTP
39−import qualified Network.HTTP.Types.Header as HTTP
40−import qualified Network.HTTP.Types.Status as HTTP
41−import qualified System.FilePath as FP
42−import System.FilePath ((</>), (<.>))
43−
44−import qualified Elm.Constraint as C
45−import qualified Elm.Magnitude as M
46−import qualified Elm.ModuleName as ModuleName
47−import qualified Elm.Package as Pkg
48−import qualified Elm.Version as V
49−import qualified File
50−import qualified Http
51−import qualified Json.Decode as Decode
52−import qualified Json.Encode as Encode
53−import qualified Json.String as Json
54−import Parse.Primitives (Row, Col)
55−import qualified Reporting.Annotation as A
56−import Reporting.Doc ((<>))
57−import qualified Reporting.Doc as D
58−import qualified Reporting.Error.Import as Import
59−import qualified Reporting.Error.Json as Json
60−import qualified Reporting.Exit.Help as Help
61−import qualified Reporting.Error as Error
62−import qualified Reporting.Render.Code as Code
63−
64−
65−
66−-- RENDERERS
67−
68−
69−toString :: Help.Report -> String
70−toString report =
71− Help.toString (Help.reportToDoc report)
72−
73−
74−toStderr :: Help.Report -> IO ()
75−toStderr report =
76− Help.toStderr (Help.reportToDoc report)
77−
78−
79−toJson :: Help.Report -> Encode.Value
80−toJson report =
81− Help.reportToJson report
82−
83−
84−
85−-- INIT
86−
87−
88−data Init
89− = InitNoSolution [Pkg.Name]
90− | InitNoOfflineSolution [Pkg.Name]
91− | InitSolverProblem Solver
92− | InitAlreadyExists
93− | InitRegistryProblem RegistryProblem
94−
95−
96−initToReport :: Init -> Help.Report
97−initToReport exit =
98− case exit of
99− InitNoSolution pkgs ->
100− Help.report "NO SOLUTION" Nothing
101− "I tried to create an elm.json with the following direct dependencies:"
102− [ D.indent 4 $ D.vcat $
103− map (D.dullyellow . D.fromChars . Pkg.toChars) pkgs
104− , D.reflow $
105− "I could not find compatible versions though! This should not happen, so please\
106− \ ask around one of the community forums at https://elm-lang.org/community to learn\
107− \ what is going on!"
108− ]
109−
110− InitNoOfflineSolution pkgs ->
111− Help.report "NO OFFLINE SOLUTION" Nothing
112− "I tried to create an elm.json with the following direct dependencies:"
113− [ D.indent 4 $ D.vcat $
114− map (D.dullyellow . D.fromChars . Pkg.toChars) pkgs
115− , D.reflow $
116− "I could not find compatible versions though, but that may be because I could not\
117− \ connect to https://package.elm-lang.org to get the latest list of packages. Are\
118− \ you able to connect to the internet? Please ask around one of the community\
119− \ forums at https://elm-lang.org/community for help!"
120− ]
121−
122− InitSolverProblem solver ->
123− toSolverReport solver
124−
125− InitAlreadyExists ->
126− Help.report "EXISTING PROJECT" Nothing
127− "You already have an elm.json file, so there is nothing for me to initialize!"
128− [ D.fillSep
129− ["Maybe",D.green (D.fromChars (D.makeLink "init")),"can","help"
130− ,"you","figure","out","what","to","do","next?"
131− ]
132− ]
133−
134− InitRegistryProblem problem ->
135− toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
136− "I need the list of published packages before I can start initializing projects"
137−
138−
139−
140−-- DIFF
141−
142−
143−data Diff
144− = DiffNoOutline
145− | DiffBadOutline Outline
146− | DiffApplication
147− | DiffNoExposed
148− | DiffUnpublished
149− | DiffUnknownPackage Pkg.Name [Pkg.Name]
150− | DiffUnknownVersion Pkg.Name V.Version [V.Version]
151− | DiffDocsProblem V.Version DocsProblem
152− | DiffMustHaveLatestRegistry RegistryProblem
153− | DiffBadDetails Details
154− | DiffBadBuild BuildProblem
155−
156−
157−diffToReport :: Diff -> Help.Report
158−diffToReport diff =
159− case diff of
160− DiffNoOutline ->
161− Help.report "DIFF WHAT?" Nothing
162− "I cannot find an elm.json so I am not sure what you want me to diff.\
163− \ Normally you run `elm diff` from within a project!"
164− [ D.reflow $ "If you are just curious to see a diff, try running this command:"
165− , D.indent 4 $ D.green $ "elm diff elm/http 1.0.0 2.0.0"
166− ]
167−
168− DiffBadOutline outline ->
169− toOutlineReport outline
170−
171− DiffApplication ->
172− Help.report "CANNOT DIFF APPLICATIONS" (Just "elm.json")
173− "Your elm.json says this project is an application, but `elm diff` only works\
174− \ with packages. That way there are previously published versions of the API to\
175− \ diff against!"
176− [ D.reflow $ "If you are just curious to see a diff, try running this command:"
177− , D.indent 4 $ D.dullyellow $ "elm diff elm/json 1.0.0 1.1.2"
178− ]
179−
180− DiffNoExposed ->
181− Help.report "NO EXPOSED MODULES" (Just "elm.json")
182− "Your elm.json has no \"exposed-modules\" which means there is no public API at\
183− \ all right now! What am I supposed to diff?"
184− [ D.reflow $
185− "Try adding some modules back to the \"exposed-modules\" field."
186− ]
187−
188− DiffUnpublished ->
189− Help.report "UNPUBLISHED" Nothing
190− "This package is not published yet. There is nothing to diff against!"
191− []
192−
193− DiffUnknownPackage pkg suggestions ->
194− Help.report "UNKNOWN PACKAGE" Nothing
195− ( "I cannot find a package called:"
196− )
197− [ D.indent 4 $ D.red $ D.fromChars $ Pkg.toChars pkg
198− , "Maybe you want one of these instead?"
199− , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Pkg.toChars) suggestions
200− , "But check <https://package.elm-lang.org> to see all possibilities!"
201− ]
202−
203− DiffUnknownVersion _pkg vsn realVersions ->
204− Help.docReport "UNKNOWN VERSION" Nothing
205− ( D.fillSep $
206− [ "Version", D.red (D.fromVersion vsn)
207− , "has", "never", "been", "published,", "so", "I"
208− , "cannot", "diff", "against", "it."
209− ]
210− )
211− [ "Here are all the versions that HAVE been published:"
212− , D.indent 4 $ D.dullyellow $ D.vcat $
213− let
214− sameMajor v1 v2 = V._major v1 == V._major v2
215− mkRow vsns = D.hsep $ map D.fromVersion vsns
216− in
217− map mkRow $ List.groupBy sameMajor (List.sort realVersions)
218− , "Want one of those instead?"
219− ]
220−
221− DiffDocsProblem version problem ->
222− toDocsProblemReport problem $
223− "I need the docs for " ++ V.toChars version ++ " to compute this diff"
224−
225− DiffMustHaveLatestRegistry problem ->
226− toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
227− "I need the latest list of published packages before I do this diff"
228−
229− DiffBadDetails details ->
230− toDetailsReport details
231−
232− DiffBadBuild buildProblem ->
233− toBuildProblemReport buildProblem
234−
235−
236−
237−-- BUMP
238−
239−
240−data Bump
241− = BumpNoOutline
242− | BumpBadOutline Outline
243− | BumpApplication
244− | BumpUnexpectedVersion V.Version [V.Version]
245− | BumpMustHaveLatestRegistry RegistryProblem
246− | BumpCannotFindDocs Pkg.Name V.Version DocsProblem
247− | BumpBadDetails Details
248− | BumpNoExposed
249− | BumpBadBuild BuildProblem
250−
251−
252−bumpToReport :: Bump -> Help.Report
253−bumpToReport bump =
254− case bump of
255− BumpNoOutline ->
256− Help.report "BUMP WHAT?" Nothing
257− "I cannot find an elm.json so I am not sure what you want me to bump."
258− [ D.reflow $
259− "Elm packages always have an elm.json that says current the version number. If\
260− \ you run this command from a directory with an elm.json file, I will try to bump\
261− \ the version in there based on the API changes."
262− ]
263−
264− BumpBadOutline outline ->
265− toOutlineReport outline
266−
267− BumpApplication ->
268− Help.report "CANNOT BUMP APPLICATIONS" (Just "elm.json")
269− "Your elm.json says this is an application. That means it cannot be published\
270− \ on <https://package.elm-lang.org> and therefore has no version to bump!"
271− []
272−
273− BumpUnexpectedVersion vsn versions ->
274− Help.docReport "CANNOT BUMP" (Just "elm.json")
275− ( D.fillSep
276− ["Your","elm.json","says","I","should","bump","relative","to","version"
277− ,D.red (D.fromVersion vsn) <> ","
278− ,"but","I","cannot","find","that","version","on","<https://package.elm-lang.org>."
279− ,"That","means","there","is","no","API","for","me","to","diff","against","and"
280− ,"figure","out","if","these","are","MAJOR,","MINOR,","or","PATCH","changes."
281− ]
282− )
283− [ D.fillSep $
284− ["Try","bumping","again","after","changing","the",D.dullyellow "\"version\"","in","elm.json"]
285− ++ if length versions == 1 then ["to:"] else ["to","one","of","these:"]
286− , D.vcat $ map (D.green . D.fromVersion) versions
287− ]
288−
289− BumpMustHaveLatestRegistry problem ->
290− toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
291− "I need the latest list of published packages before I can bump any versions"
292−
293− BumpCannotFindDocs _ version problem ->
294− toDocsProblemReport problem $
295− "I need the docs for " ++ V.toChars version ++ " to compute the next version number"
296−
297− BumpBadDetails details ->
298− toDetailsReport details
299−
300− BumpNoExposed ->
301− Help.docReport "NO EXPOSED MODULES" (Just "elm.json")
302− ( D.fillSep $
303− [ "To", "bump", "a", "package,", "the"
304− , D.dullyellow "\"exposed-modules\"", "field", "of", "your"
305− , "elm.json", "must", "list", "at", "least", "one", "module."
306− ]
307− )
308− [ D.reflow $
309− "Try adding some modules back to the \"exposed-modules\" field."
310− ]
311−
312− BumpBadBuild problem ->
313− toBuildProblemReport problem
314−
315−
316−
317−-- OVERVIEW OF VERSIONING
318−
319−
320−newPackageOverview :: String
321−newPackageOverview =
322− unlines
323− [ "This package has never been published before. Here's how things work:"
324− , ""
325− , " - Versions all have exactly three parts: MAJOR.MINOR.PATCH"
326− , ""
327− , " - All packages start with initial version " ++ V.toChars V.one
328− , ""
329− , " - Versions are incremented based on how the API changes:"
330− , ""
331− , " PATCH = the API is the same, no risk of breaking code"
332− , " MINOR = values have been added, existing values are unchanged"
333− , " MAJOR = existing values have been changed or removed"
334− , ""
335− , " - I will bump versions for you, automatically enforcing these rules"
336− , ""
337− ]
338−
339−
340−
341−-- PUBLISH
342−
343−
344−data Publish
345− = PublishNoOutline
346− | PublishBadOutline Outline
347− | PublishBadDetails Details
348− | PublishMustHaveLatestRegistry RegistryProblem
349− | PublishApplication
350− | PublishNotInitialVersion V.Version
351− | PublishAlreadyPublished V.Version
352− | PublishInvalidBump V.Version V.Version
353− | PublishBadBump V.Version V.Version M.Magnitude V.Version M.Magnitude
354− | PublishNoSummary
355− | PublishNoExposed
356− | PublishNoReadme
357− | PublishShortReadme
358− | PublishNoLicense
359− | PublishBuildProblem BuildProblem
360− | PublishMissingTag V.Version
361− | PublishCannotGetTag V.Version Http.Error
362− | PublishCannotGetTagData V.Version String BS.ByteString
363− | PublishCannotGetZip Http.Error
364− | PublishCannotDecodeZip String
365− | PublishCannotGetDocs V.Version V.Version DocsProblem
366− | PublishCannotRegister Http.Error
367− | PublishNoGit
368− | PublishLocalChanges V.Version
369− --
370− | PublishZipBadDetails Details
371− | PublishZipApplication
372− | PublishZipNoExposed
373− | PublishZipBuildProblem BuildProblem
374−
375−
376−publishToReport :: Publish -> Help.Report
377−publishToReport publish =
378− case publish of
379− PublishNoOutline ->
380− Help.report "PUBLISH WHAT?" Nothing
381− "I cannot find an elm.json so I am not sure what you want me to publish."
382− [ D.reflow $
383− "Elm packages always have an elm.json that states the version number,\
384− \ dependencies, exposed modules, etc."
385− ]
386−
387− PublishBadOutline outline ->
388− toOutlineReport outline
389−
390− PublishBadDetails problem ->
391− toDetailsReport problem
392−
393− PublishMustHaveLatestRegistry problem ->
394− toRegistryProblemReport "PROBLEM UPDATING PACKAGE LIST" problem $
395− "I need the latest list of published packages to make sure this is safe to publish"
396−
397− PublishApplication ->
398− Help.report "UNPUBLISHABLE" Nothing "I cannot publish applications, only packages!" []
399−
400− PublishNotInitialVersion vsn ->
401− Help.docReport "INVALID VERSION" Nothing
402− ( D.fillSep
403− ["I","cannot","publish"
404− ,D.red (D.fromVersion vsn)
405− ,"as","the","initial","version."
406− ]
407− )
408− [ D.fillSep
409− ["Change","it","to",D.green "1.0.0","which","is"
410− ,"the","initial","version","for","all","Elm","packages."
411− ]
412− ]
413−
414− PublishAlreadyPublished vsn ->
415− Help.docReport "ALREADY PUBLISHED" Nothing
416− ( D.vcat
417− [ D.fillSep
418− [ "Version", D.green (D.fromVersion vsn)
419− , "has", "already", "been", "published.", "You", "cannot"
420− , "publish", "it", "again!"
421− ]
422− , "Try using the `bump` command:"
423− ]
424− )
425− [ D.dullyellow $ D.indent 4 "elm bump"
426− , D.reflow $
427− "It computes the version number based on API changes, ensuring\
428− \ that no breaking changes end up in PATCH releases!"
429− ]
430−
431− PublishInvalidBump statedVersion latestVersion ->
432− Help.docReport "INVALID VERSION" (Just "elm.json")
433− ( D.fillSep $
434− ["Your","elm.json","says","the","next","version","should","be"
435− ,D.red (D.fromVersion statedVersion) <> ","
436− ,"but","that","is","not","valid","based","on","the","previously"
437− ,"published","versions."
438− ]
439− )
440− [ D.fillSep $
441− ["Change","the","version","back","to"
442− ,D.green (D.fromVersion latestVersion)
443− ,"which","is","the","most","recently","published","version."
444− ,"From","there,","have","Elm","bump","the","version","by","running:"
445− ]
446− , D.indent 4 $ D.green "elm bump"
447− , D.reflow $
448− "If you want more insight on the API changes Elm detects, you\
449− \ can run `elm diff` at this point as well."
450− ]
451−
452− PublishBadBump old new magnitude realNew realMagnitude ->
453− Help.docReport "INVALID VERSION" (Just "elm.json")
454− (
455− D.fillSep $
456− ["Your","elm.json","says","the","next","version","should","be"
457− ,D.red (D.fromVersion new) <> ","
458− ,"indicating","a",D.fromChars (M.toChars magnitude)
459− ,"change","to","the","public","API."
460− ,"This","does","not","match","the","API","diff","given","by:"
461− ]
462− )
463− [ D.indent 4 $ D.fromChars $
464− "elm diff " ++ V.toChars old
465−
466− , D.fillSep $
467− ["This","command","says","this","is","a"
468− ,D.fromChars (M.toChars realMagnitude)
469− ,"change,","so","the","next","version","should","be"
470− ,D.green (D.fromVersion realNew) <> "."
471− ,"Double","check","everything","to","make","sure","you"
472− ,"are","publishing","what","you","want!"
473− ]
474− , D.reflow $
475− "Also, next time use `elm bump` and I'll figure all this out for you!"
476− ]
477−
478− PublishNoSummary ->
479− Help.docReport "NO SUMMARY" (Just "elm.json")
480− ( D.fillSep $
481− [ "To", "publish", "a", "package,", "your", "elm.json", "must"
482− , "have", "a", D.dullyellow "\"summary\"", "field", "that", "gives"
483− , "a", "consice", "overview", "of", "your", "project."
484− ]
485− )
486− [ D.reflow $
487− "The summary must be less than 80 characters. It should describe\
488− \ the concrete use of your package as clearly and as plainly as possible."
489− ]
490−
491− PublishNoExposed ->
492− Help.docReport "NO EXPOSED MODULES" (Just "elm.json")
493− ( D.fillSep $
494− [ "To", "publish", "a", "package,", "the"
495− , D.dullyellow "\"exposed-modules\"", "field", "of", "your"
496− , "elm.json", "must", "list", "at", "least", "one", "module."
497− ]
498− )
499− [ D.reflow $
500− "Which modules do you want users of the package to have access to? Add their\
501− \ names to the \"exposed-modules\" list."
502− ]
503−
504− PublishNoReadme ->
505− toBadReadmeReport "NO README" $
506− "Every published package must have a helpful README.md\
507− \ file, but I do not see one in your project."
508−
509− PublishShortReadme ->
510− toBadReadmeReport "SHORT README" $
511− "This README.md is too short. Having more details will help\
512− \ people assess your package quickly and fairly."
513−
514− PublishNoLicense ->
515− Help.report "NO LICENSE FILE" (Just "LICENSE")
516− "By publishing a package you are inviting the Elm community to build\
517− \ upon your work. But without knowing your license, we have no idea if\
518− \ that is legal!"
519− [ D.reflow $
520− "Once you pick an OSI approved license from <https://spdx.org/licenses/>,\
521− \ you must share that choice in two places. First, the license\
522− \ identifier must appear in your elm.json file. Second, the full\
523− \ license text must appear in the root of your project in a file\
524− \ named LICENSE. Add that file and you will be all set!"
525− ]
526−
527− PublishBuildProblem buildProblem ->
528− toBuildProblemReport buildProblem
529−
530− PublishMissingTag version ->
531− let vsn = V.toChars version in
532− Help.docReport "NO TAG" Nothing
533− ( D.fillSep $
534− [ "Packages", "must", "be", "tagged", "in", "git,", "but", "I"
535− , "cannot", "find", "a", D.green (D.fromChars vsn), "tag."
536− ]
537− )
538− [ D.vcat
539− [ "These tags make it possible to find this specific version on GitHub."
540− , "To tag the most recent commit and push it to GitHub, run this:"
541− ]
542− , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromChars $
543− [ "git tag -a " ++ vsn ++ " -m \"new release\""
544− , "git push origin " ++ vsn
545− ]
546− , "The -m flag is for a helpful message. Try to make it more informative!"
547− ]
548−
549− PublishCannotGetTag version httpError ->
550− case httpError of
551− Http.BadHttp _ (HTTP.StatusCodeException response _)
552− | HTTP.statusCode (HTTP.responseStatus response) == 404 ->
553− let vsn = V.toChars version in
554− Help.report "NO TAG ON GITHUB" Nothing
555− ("You have version " ++ vsn ++ " tagged locally, but not on GitHub.")
556− [ D.reflow
557− "Run the following command to make this tag available on GitHub:"
558− , D.indent 4 $ D.dullyellow $ D.fromChars $
559− "git push origin " ++ vsn
560− , D.reflow
561− "This will make it possible to find your code online based on the version number."
562− ]
563−
564− _ ->
565− toHttpErrorReport "PROBLEM VERIFYING TAG" httpError
566− "I need to check that the version tag is registered on GitHub"
567−
568− PublishCannotGetTagData version url body ->
569− Help.report "PROBLEM VERIFYING TAG" Nothing
570− ("I need to check that version " ++ V.toChars version ++ " is tagged on GitHub, so I fetched:")
571− [ D.indent 4 $ D.dullyellow $ D.fromChars url
572− , D.reflow $
573− "I got the data back, but it was not what I was expecting. The response\
574− \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
575− ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
576− , D.indent 4 $ D.dullyellow $ D.fromChars $
577− if BS.length body <= 76
578− then BS_UTF8.toString body
579− else take 73 (BS_UTF8.toString body) ++ "..."
580− , D.reflow $
581− "Does this error keep showing up? Maybe there is something weird with your\
582− \ internet connection. We have gotten reports that schools, businesses,\
583− \ airports, etc. sometimes intercept requests and add things to the body\
584− \ or change its contents entirely. Could that be the problem?"
585− ]
586−
587− PublishCannotGetZip httpError ->
588− toHttpErrorReport "PROBLEM DOWNLOADING CODE" httpError $
589− "I need to check that folks can download and build the source code when they\
590− \ install this package"
591−
592− PublishCannotDecodeZip url ->
593− Help.report "PROBLEM DOWNLOADING CODE" Nothing
594− "I need to check that folks can download and build the source code when they\
595− \ install this package, so I downloaded the code from:"
596− [ D.indent 4 $ D.dullyellow $ D.fromChars url
597− , D.reflow $
598− "I was unable to unzip the archive though. Maybe there is something weird with\
599− \ your internet connection. We have gotten reports that schools, businesses,\
600− \ airports, etc. sometimes intercept requests and add things to the body or\
601− \ change its contents entirely. Could that be the problem?"
602− ]
603−
604− PublishCannotGetDocs old new docsProblem ->
605− toDocsProblemReport docsProblem $
606− "I need the docs for " ++ V.toChars old ++ " to verify that "
607− ++ V.toChars new ++ " really does come next"
608−
609− PublishCannotRegister httpError ->
610− toHttpErrorReport "PROBLEM PUBLISHING PACKAGE" httpError $
611− "I need to send information about your package to the package website"
612−
613− PublishNoGit ->
614− Help.report "NO GIT" Nothing
615− "I searched your PATH environment variable for `git` and could not\
616− \ find it. Is it available through your PATH?"
617− [ D.reflow $
618− "Who cares about this? Well, I currently use `git` to check if there\
619− \ are any local changes in your code. Local changes are a good sign\
620− \ that some important improvements have gotten mistagged, so this\
621− \ check can be extremely helpful for package authors!"
622− , D.toSimpleNote $
623− "We plan to do this without the `git` binary in a future release."
624− ]
625−
626− PublishLocalChanges version ->
627− let vsn = V.toChars version in
628− Help.docReport "LOCAL CHANGES" Nothing
629− ( D.fillSep $
630− [ "The", "code", "tagged", "as", D.green (D.fromChars vsn), "in"
631− , "git", "does", "not", "match", "the", "code", "in", "your"
632− , "working", "directory.", "This", "means", "you", "have"
633− , "commits", "or", "local", "changes", "that", "are", "not"
634− , "going", "to", "be", "published!"
635− ]
636− )
637− [ D.toSimpleNote $
638− "If you are sure everything is in order, you can run `git checkout "
639− ++ vsn ++ "` and publish your code from there."
640− ]
641−
642− PublishZipBadDetails _ ->
643− badZipReport
644−
645− PublishZipApplication ->
646− badZipReport
647−
648− PublishZipNoExposed ->
649− badZipReport
650−
651− PublishZipBuildProblem _ ->
652− badZipReport
653−
654−
655−toBadReadmeReport :: String -> String -> Help.Report
656−toBadReadmeReport title summary =
657− Help.report title (Just "README.md") summary
658− [ D.reflow $
659− "When people look at your README, they are wondering:"
660− , D.vcat
661− [ " - What does this package even do?"
662− , " - Will it help me solve MY problems?"
663− ]
664− , D.reflow $
665− "So I recommend starting your README with a small example of the\
666− \ most common usage scenario. Show people what they can expect if\
667− \ they learn more!"
668− , D.toSimpleNote $
669− "By publishing your package, you are inviting people to invest time in\
670− \ understanding your work. Spending an hour on your README to communicate your\
671− \ knowledge more clearly can save the community days or weeks of time in\
672− \ aggregate, and saving time in aggregate is the whole point of publishing\
673− \ packages! People really appreciate it, and it makes the whole ecosystem feel\
674− \ nicer!"
675− ]
676−
677−
678−badZipReport :: Help.Report
679−badZipReport =
680− Help.report "PROBLEM VERIFYING PACKAGE" Nothing
681− "Before publishing packages, I download the code from GitHub and try to build it\
682− \ from scratch. That way I can be more confident that it will work for other\
683− \ people too. But I am not able to build it!"
684− [ D.reflow $
685− "I was just able to build your local copy though. Is there some way the version\
686− \ on GitHub could be different?"
687− ]
688−
689−
690−
691−-- DOCS
692−
693−
694−data DocsProblem
695− = DP_Http Http.Error
696− | DP_Data String BS.ByteString
697− | DP_Cache
698−
699−
700−toDocsProblemReport :: DocsProblem -> String -> Help.Report
701−toDocsProblemReport problem context =
702− case problem of
703− DP_Http httpError ->
704− toHttpErrorReport "PROBLEM LOADING DOCS" httpError context
705−
706− DP_Data url body ->
707− Help.report "PROBLEM LOADING DOCS" Nothing (context ++ ", so I fetched:")
708− [ D.indent 4 $ D.dullyellow $ D.fromChars url
709− , D.reflow $
710− "I got the data back, but it was not what I was expecting. The response\
711− \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
712− ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
713− , D.indent 4 $ D.dullyellow $ D.fromChars $
714− if BS.length body <= 76
715− then BS_UTF8.toString body
716− else take 73 (BS_UTF8.toString body) ++ "..."
717− , D.reflow $
718− "Does this error keep showing up? Maybe there is something weird with your\
719− \ internet connection. We have gotten reports that schools, businesses,\
720− \ airports, etc. sometimes intercept requests and add things to the body\
721− \ or change its contents entirely. Could that be the problem?"
722− ]
723−
724− DP_Cache ->
725− Help.report "PROBLEM LOADING DOCS" Nothing (context ++ ", but the local copy seems to be corrupted.")
726− [ D.reflow $
727− "I deleted the cached version, so the next run should download a fresh copy of\
728− \ the docs. Hopefully that will get you unstuck, but it will not resolve the root\
729− \ problem if, for example, a 3rd party editor plugin is modifing cached files\
730− \ for some reason."
731− ]
732−
733−
734−
735−-- INSTALL
736−
737−
738−data Install
739− = InstallNoOutline
740− | InstallBadOutline Outline
741− | InstallBadRegistry RegistryProblem
742− | InstallNoArgs FilePath
743− | InstallNoOnlineAppSolution Pkg.Name
744− | InstallNoOfflineAppSolution Pkg.Name
745− | InstallNoOnlinePkgSolution Pkg.Name
746− | InstallNoOfflinePkgSolution Pkg.Name
747− | InstallHadSolverTrouble Solver
748− | InstallUnknownPackageOnline Pkg.Name [Pkg.Name]
749− | InstallUnknownPackageOffline Pkg.Name [Pkg.Name]
750− | InstallBadDetails Details
751−
752−
753−installToReport :: Install -> Help.Report
754−installToReport exit =
755− case exit of
756− InstallNoOutline ->
757− Help.report "NEW PROJECT?" Nothing
758− "Are you trying to start a new project? Try this command instead:"
759− [ D.indent 4 $ D.green "elm init"
760− , D.reflow "It will help you get started!"
761− ]
762−
763− InstallBadOutline outline ->
764− toOutlineReport outline
765−
766− InstallBadRegistry problem ->
767− toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
768− "I need the list of published packages to figure out how to install things"
769−
770− InstallNoArgs elmHome ->
771− Help.report "INSTALL WHAT?" Nothing
772− "I am expecting commands like:"
773− [ D.green $ D.indent 4 $ D.vcat $
774− [ "elm install elm/http"
775− , "elm install elm/json"
776− , "elm install elm/random"
777− ]
778− , D.toFancyHint
779− ["In","JavaScript","folks","run","`npm install`","to","start","projects."
780− ,"\"Gotta","download","everything!\"","But","why","download","packages"
781− ,"again","and","again?","Instead,","Elm","caches","packages","in"
782− ,D.dullyellow (D.fromChars elmHome)
783− ,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
784− ,"Elm","projects","check","that","cache","before","trying","the","internet."
785− ,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
786− ,"easier","to","work","offline.","As","a","result"
787− ,D.dullcyan "elm install","is","only","for","adding","dependencies","to","elm.json,"
788− ,"whereas",D.dullcyan "elm make","is","in","charge","of","gathering","dependencies"
789− ,"and","building","everything.","So","maybe","try",D.green "elm make","instead?"
790− ]
791− ]
792−
793− InstallNoOnlineAppSolution pkg ->
794− Help.report "CANNOT FIND COMPATIBLE VERSION" (Just "elm.json")
795− (
796− "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
797− \ with your existing dependencies."
798− )
799− [ D.reflow $
800− "I checked all the published versions. When that failed, I tried to find any\
801− \ compatible combination of these packages, even if it meant changing all your\
802− \ existing dependencies! That did not work either!"
803− , D.reflow $
804− "This is most likely to happen when a package is not upgraded yet. Maybe a new\
805− \ version of Elm came out recently? Maybe a common package was changed recently?\
806− \ Maybe a better package came along, so there was no need to upgrade this one?\
807− \ Try asking around https://elm-lang.org/community to learn what might be going on\
808− \ with this package."
809− , D.toSimpleNote $
810− "Whatever the case, please be kind to the relevant package authors! Having\
811− \ friendly interactions with users is great motivation, and conversely, getting\
812− \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
813− \ authors are humans with families, friends, jobs, vacations, responsibilities,\
814− \ goals, etc. They face obstacles outside of their technical work you will never\
815− \ know about, so please assume the best and try to be patient and supportive!"
816− ]
817−
818− InstallNoOfflineAppSolution pkg ->
819− Help.report "CANNOT FIND COMPATIBLE VERSION LOCALLY" (Just "elm.json")
820− (
821− "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
822− \ with your existing dependencies."
823− )
824− [ D.reflow $
825− "I was not able to connect to https://package.elm-lang.org/ though, so I was only\
826− \ able to look through packages that you have downloaded in the past."
827− , D.reflow $
828− "Try again later when you have internet!"
829− ]
830−
831− InstallNoOnlinePkgSolution pkg ->
832− Help.report "CANNOT FIND COMPATIBLE VERSION" (Just "elm.json")
833− (
834− "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
835− \ with your existing constraints."
836− )
837− [ D.reflow $
838− "With applications, I try to broaden the constraints to see if anything works,\
839− \ but messing with package constraints is much more delicate business. E.g. making\
840− \ your constraints stricter may make it harder for applications to find compatible\
841− \ dependencies. So fixing something here may break it for a lot of other people!"
842− , D.reflow $
843− "So I recommend making an application with the same dependencies as your package.\
844− \ See if there is a solution at all. From there it may be easier to figure out\
845− \ how to proceed in a way that will disrupt your users as little as possible. And\
846− \ the solution may be to help other package authors to get their packages updated,\
847− \ or to drop a dependency entirely."
848− ]
849−
850− InstallNoOfflinePkgSolution pkg ->
851− Help.report "CANNOT FIND COMPATIBLE VERSION LOCALLY" (Just "elm.json")
852− (
853− "I cannot find a version of " ++ Pkg.toChars pkg ++ " that is compatible\
854− \ with your existing constraints."
855− )
856− [ D.reflow $
857− "I was not able to connect to https://package.elm-lang.org/ though, so I was only\
858− \ able to look through packages that you have downloaded in the past."
859− , D.reflow $
860− "Try again later when you have internet!"
861− ]
862−
863− InstallHadSolverTrouble solver ->
864− toSolverReport solver
865−
866− InstallUnknownPackageOnline pkg suggestions ->
867− Help.docReport "UNKNOWN PACKAGE" Nothing
868− (
869− D.fillSep
870− ["I","cannot","find","a","package","named",D.red (D.fromPackage pkg) <> "."]
871− )
872− [ D.reflow $
873− "I looked through https://package.elm-lang.org for packages with similar names\
874− \ and found these:"
875− , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromPackage suggestions
876− , D.reflow $ "Maybe you want one of these instead?"
877− ]
878−
879− InstallUnknownPackageOffline pkg suggestions ->
880− Help.docReport "UNKNOWN PACKAGE" Nothing
881− (
882− D.fillSep
883− ["I","cannot","find","a","package","named",D.red (D.fromPackage pkg) <> "."]
884− )
885− [ D.reflow $
886− "I could not connect to https://package.elm-lang.org though, so new packages may\
887− \ have been published since I last updated my local cache of package names."
888− , D.reflow $
889− "Looking through the locally cached names, the closest ones are:"
890− , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromPackage suggestions
891− , D.reflow $ "Maybe you want one of these instead?"
892− ]
893−
894− InstallBadDetails details ->
895− toDetailsReport details
896−
897−
898−
899−-- SOLVER
900−
901−
902−data Solver
903− = SolverBadCacheData Pkg.Name V.Version
904− | SolverBadHttpData Pkg.Name V.Version String
905− | SolverBadHttp Pkg.Name V.Version Http.Error
906−
907−
908−toSolverReport :: Solver -> Help.Report
909−toSolverReport problem =
910− case problem of
911− SolverBadCacheData pkg vsn ->
912− Help.report "PROBLEM SOLVING PACKAGE CONSTRAINTS" Nothing
913− (
914− "I need the elm.json of " ++ Pkg.toChars pkg ++ " " ++ V.toChars vsn ++ " to\
915− \ help me search for a set of compatible packages. I had it cached locally, but\
916− \ it looks like the file was corrupted!"
917− )
918− [ D.reflow $
919− "I deleted the cached version, so the next run should download a fresh copy.\
920− \ Hopefully that will get you unstuck, but it will not resolve the root\
921− \ problem if a 3rd party tool is modifing cached files for some reason."
922− ]
923−
924− SolverBadHttpData pkg vsn url ->
925− Help.report "PROBLEM SOLVING PACKAGE CONSTRAINTS" Nothing
926− (
927− "I need the elm.json of " ++ Pkg.toChars pkg ++ " " ++ V.toChars vsn ++ " to\
928− \ help me search for a set of compatible packages, but I ran into corrupted\
929− \ information from:"
930− )
931− [ D.indent 4 $ D.dullyellow $ D.fromChars url
932− , D.reflow $
933− "Is something weird with your internet connection. We have gotten reports that\
934− \ schools, businesses, airports, etc. sometimes intercept requests and add things\
935− \ to the body or change its contents entirely. Could that be the problem?"
936− ]
937−
938− SolverBadHttp pkg vsn httpError ->
939− toHttpErrorReport "PROBLEM SOLVING PACKAGE CONSTRAINTS" httpError $
940− "I need the elm.json of " ++ Pkg.toChars pkg ++ " " ++ V.toChars vsn
941− ++ " to help me search for a set of compatible packages"
942−
943−
944−
945−-- OUTLINE
946−
947−
948−data Outline
949− = OutlineHasBadStructure (Decode.Error OutlineProblem)
950− | OutlineHasMissingSrcDirs FilePath [FilePath]
951− | OutlineHasDuplicateSrcDirs FilePath FilePath FilePath
952− | OutlineNoPkgCore
953− | OutlineNoAppCore
954− | OutlineNoAppJson
955−
956−
957−data OutlineProblem
958− = OP_BadType
959− | OP_BadPkgName Row Col
960− | OP_BadVersion Row Col
961− | OP_BadConstraint C.Error
962− | OP_BadModuleName Row Col
963− | OP_BadModuleHeaderTooLong
964− | OP_BadDependencyName Row Col
965− | OP_BadLicense Json.String [Json.String]
966− | OP_BadSummaryTooLong
967− | OP_NoSrcDirs
968−
969−
970−toOutlineReport :: Outline -> Help.Report
971−toOutlineReport problem =
972− case problem of
973− OutlineHasBadStructure decodeError ->
974− Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError $
975− Json.ExplicitReason "I ran into a problem with your elm.json file."
976−
977− OutlineHasMissingSrcDirs dir dirs ->
978− case dirs of
979− [] ->
980− Help.report "MISSING SOURCE DIRECTORY" (Just "elm.json")
981− "I need a valid elm.json file, but the \"source-directories\" field lists the following directory:"
982− [ D.indent 4 $ D.red $ D.fromChars dir
983− , D.reflow $
984− "I cannot find it though. Is it missing? Is there a typo?"
985− ]
986−
987− _:_ ->
988− Help.report "MISSING SOURCE DIRECTORIES" (Just "elm.json")
989− "I need a valid elm.json file, but the \"source-directories\" field lists the following directories:"
990− [ D.indent 4 $ D.vcat $
991− map (D.red . D.fromChars) (dir:dirs)
992− , D.reflow $
993− "I cannot find them though. Are they missing? Are there typos?"
994− ]
995−
996− OutlineHasDuplicateSrcDirs canonicalDir dir1 dir2 ->
997− if dir1 == dir2 then
998− Help.report "REDUNDANT SOURCE DIRECTORIES" (Just "elm.json")
999− "I need a valid elm.json file, but the \"source-directories\" field lists the same directory twice:"
1000− [ D.indent 4 $ D.vcat $
1001− map (D.red . D.fromChars) [dir1,dir2]
1002− , D.reflow $
1003− "Remove one of the entries!"
1004− ]
1005− else
1006− Help.report "REDUNDANT SOURCE DIRECTORIES" (Just "elm.json")
1007− "I need a valid elm.json file, but the \"source-directories\" field has some redundant directories:"
1008− [ D.indent 4 $ D.vcat $
1009− map (D.red . D.fromChars) [dir1,dir2]
1010− , D.reflow $
1011− "These are two different ways of refering to the same directory:"
1012− , D.indent 4 $ D.dullyellow $ D.fromChars canonicalDir
1013− , D.reflow $
1014− "Remove one of the redundant entries from your \"source-directories\" field."
1015− ]
1016−
1017− OutlineNoPkgCore ->
1018− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1019− "I need to see an \"elm/core\" dependency your elm.json file. The default imports\
1020− \ of `List` and `Maybe` do not work without it."
1021− [ D.reflow $
1022− "If you modified your elm.json by hand, try to change it back! And if you are\
1023− \ having trouble getting back to a working elm.json, it may be easier to find a\
1024− \ working package and start fresh with their elm.json file."
1025− ]
1026−
1027− OutlineNoAppCore ->
1028− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1029− "I need to see an \"elm/core\" dependency your elm.json file. The default imports\
1030− \ of `List` and `Maybe` do not work without it."
1031− [ D.reflow $
1032− "If you modified your elm.json by hand, try to change it back! And if you are\
1033− \ having trouble getting back to a working elm.json, it may be easier to delete it\
1034− \ and use `elm init` to start fresh."
1035− ]
1036−
1037− OutlineNoAppJson ->
1038− Help.report "MISSING DEPENDENCY" (Just "elm.json")
1039− "I need to see an \"elm/json\" dependency your elm.json file. It helps me handle\
1040− \ flags and ports."
1041− [ D.reflow $
1042− "If you modified your elm.json by hand, try to change it back! And if you are\
1043− \ having trouble getting back to a working elm.json, it may be easier to delete it\
1044− \ and use `elm init` to start fresh."
1045− ]
1046−
1047−
1048−toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
1049−toOutlineProblemReport path source _ region problem =
1050− let
1051− toHighlight row col =
1052− Just $ A.Region (A.Position row col) (A.Position row col)
1053−
1054− toSnippet title highlight pair =
1055− Help.jsonReport title (Just path) $
1056− Code.toSnippet source region highlight pair
1057− in
1058− case problem of
1059− OP_BadType ->
1060− toSnippet "UNEXPECTED TYPE" Nothing
1061− ( D.reflow $
1062− "I got stuck while reading your elm.json file. I cannot handle a \"type\" like this:"
1063− , D.fillSep
1064− ["Try","changing","the","\"type\"","to"
1065− ,D.green "\"application\"","or",D.green "\"package\"","instead."
1066− ]
1067− )
1068−
1069− OP_BadPkgName row col ->
1070− toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
1071− ( D.reflow $
1072− "I got stuck while reading your elm.json file. I ran into trouble with the package name:"
1073− , D.stack
1074− [ D.fillSep
1075− ["Package","names","are","always","written","as"
1076− ,D.green "\"author/project\""
1077− ,"so","I","am","expecting","to","see","something","like:"
1078− ]
1079− , D.dullyellow $ D.indent 4 $ D.vcat $
1080− [ "\"mdgriffith/elm-ui\""
1081− , "\"w0rm/elm-physics\""
1082− , "\"Microsoft/elm-json-tree-view\""
1083− , "\"FordLabs/elm-star-rating\""
1084− , "\"1602/json-schema\""
1085− ]
1086− , D.reflow
1087− "The author name should match your GitHub name exactly, and the project name\
1088− \ needs to follow these rules:"
1089− , D.indent 4 $ D.vcat $
1090− [ "+--------------------------------------+-----------+-----------+"
1091− , "| RULE | BAD | GOOD |"
1092− , "+--------------------------------------+-----------+-----------+"
1093− , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
1094− , "| no leading digits | 3D | elm-3d |"
1095− , "| no non-ASCII characters | elm-bjørn | elm-bear |"
1096− , "| no underscores | elm_ui | elm-ui |"
1097− , "| no double hyphens | elm--hash | elm-hash |"
1098− , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
1099− , "+--------------------------------------+-----------+-----------+"
1100− ]
1101− , D.toSimpleNote $
1102− "These rules only apply to the project name, so you should never need\
1103− \ to change your GitHub name!"
1104− ]
1105− )
1106−
1107− OP_BadVersion row col ->
1108− toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
1109− ( D.reflow $
1110− "I got stuck while reading your elm.json file. I was expecting a version number here:"
1111− , D.fillSep
1112− ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
1113− ,"that","explicitly","states","all","three","numbers!"
1114− ]
1115− )
1116−
1117− OP_BadConstraint constraintError ->
1118− case constraintError of
1119− C.BadFormat row col ->
1120− toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
1121− ( D.reflow $
1122− "I got stuck while reading your elm.json file. I do not understand this version constraint:"
1123− , D.stack
1124− [ D.fillSep
1125− ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
1126− ,"that","explicitly","lists","the","lower","and","upper","bounds."
1127− ]
1128− , D.toSimpleNote $
1129− "The spaces in there are required! Taking them out will confuse me. Adding\
1130− \ extra spaces confuses me too. I recommend starting with a valid example\
1131− \ and just changing the version numbers."
1132− ]
1133− )
1134−
1135− C.InvalidRange before after ->
1136− if before == after then
1137− toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1138− ( D.reflow $
1139− "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1140− , D.fillSep
1141− ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
1142− ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
1143− ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
1144− ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
1145− ,"happen","in","any","of","the","versions","in","that","range."
1146− ]
1147− )
1148−
1149− else
1150− toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1151− ( D.reflow $
1152− "I got stuck while reading your elm.json file. I ran into an invalid version constraint:"
1153− , D.fillSep
1154− ["Maybe","you","want","something","like"
1155− ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
1156− ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1157− ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1158− ,"cannot","happen","in","any","of","the","versions","in","that","range."
1159− ]
1160− )
1161−
1162− OP_BadModuleName row col ->
1163− toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1164− ( D.reflow $
1165− "I got stuck while reading your elm.json file. I was expecting a module name here:"
1166− , D.fillSep
1167− ["I","need","something","like",D.green "\"Html.Events\""
1168− ,"or",D.green "\"Browser.Navigation\""
1169− ,"where","each","segment","starts","with","a","capital"
1170− ,"letter","and","the","segments","are","separated","by","dots."
1171− ]
1172− )
1173−
1174− OP_BadModuleHeaderTooLong ->
1175− toSnippet "HEADER TOO LONG" Nothing
1176− ( D.reflow $
1177− "I got stuck while reading your elm.json file. This section header is too long:"
1178− , D.stack
1179− [ D.fillSep
1180− ["I","need","it","to","be"
1181− ,D.green "under",D.green "20",D.green "bytes"
1182− ,"so","it","renders","nicely","on","the","package","website!"
1183− ]
1184− , D.toSimpleNote
1185− "I count the length in bytes, so using non-ASCII characters costs extra.\
1186− \ Please report your case at https://github.com/elm/compiler/issues if this seems\
1187− \ overly restrictive for your needs."
1188− ]
1189− )
1190−
1191− OP_BadDependencyName row col ->
1192− toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1193− ( D.reflow $
1194− "I got stuck while reading your elm.json file. There is something wrong with this dependency name:"
1195− , D.stack
1196− [ D.fillSep
1197− ["Package","names","always","include","the","name","of","the","author,"
1198− ,"so","I","am","expecting","to","see","dependencies","like"
1199− ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1200− ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1201− ]
1202− , D.fillSep $
1203− ["I","generally","recommend","finding","the","package","you","want","on"
1204− ,"the","package","website,","and","installing","it","with","the"
1205− ,D.green "elm install","command!"
1206− ]
1207− ]
1208− )
1209−
1210− OP_BadLicense _ suggestions ->
1211− toSnippet "UNKNOWN LICENSE" Nothing
1212− ( D.reflow $
1213− "I got stuck while reading your elm.json file. I do not know about this type of license:"
1214− ,
1215− D.stack
1216− [ D.fillSep
1217− ["Elm","packages","generally","use"
1218− ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1219− ,"but","I","accept","any","OSI","approved","SPDX","license."
1220− ,"Here","some","that","seem","close","to","what","you","wrote:"
1221− ]
1222− , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1223− , D.reflow $
1224− "Check out https://spdx.org/licenses/ for the full list of options."
1225− ]
1226− )
1227−
1228− OP_BadSummaryTooLong ->
1229− toSnippet "SUMMARY TOO LONG" Nothing
1230− ( D.reflow $
1231− "I got stuck while reading your elm.json file. Your \"summary\" is too long:"
1232− , D.stack
1233− [ D.fillSep
1234− ["I","need","it","to","be"
1235− ,D.green "under",D.green "80",D.green "bytes"
1236− ,"so","it","renders","nicely","on","the","package","website!"
1237− ]
1238− , D.toSimpleNote
1239− "I count the length in bytes, so using non-ASCII characters costs extra.\
1240− \ Please report your case at https://github.com/elm/compiler/issues if this seems\
1241− \ overly restrictive for your needs."
1242− ]
1243− )
1244−
1245− OP_NoSrcDirs ->
1246− toSnippet "NO SOURCE DIRECTORIES" Nothing
1247− ( D.reflow $
1248− "I got stuck while reading your elm.json file. You do not have any \"source-directories\" listed here:"
1249− , D.fillSep
1250− ["I","need","something","like",D.green "[\"src\"]"
1251− ,"so","I","know","where","to","look","for","your","modules!"
1252− ]
1253− )
1254−
1255−
1256−
1257−-- DETAILS
1258−
1259−
1260−data Details
1261− = DetailsNoSolution
1262− | DetailsNoOfflineSolution
1263− | DetailsSolverProblem Solver
1264− | DetailsBadElmInPkg C.Constraint
1265− | DetailsBadElmInAppOutline V.Version
1266− | DetailsHandEditedDependencies
1267− | DetailsBadOutline Outline
1268− | DetailsCannotGetRegistry RegistryProblem
1269− | DetailsBadDeps FilePath [DetailsBadDep]
1270−
1271−
1272−data DetailsBadDep
1273− = BD_BadDownload Pkg.Name V.Version PackageProblem
1274− | BD_BadBuild Pkg.Name V.Version (Map.Map Pkg.Name V.Version)
1275−
1276−
1277−toDetailsReport :: Details -> Help.Report
1278−toDetailsReport details =
1279− case details of
1280− DetailsNoSolution ->
1281− Help.report "INCOMPATIBLE DEPENDENCIES" (Just "elm.json")
1282− "The dependencies in your elm.json are not compatible."
1283− [ D.fillSep
1284− ["Did","you","change","them","by","hand?","Try","to","change","it","back!"
1285− ,"It","is","much","more","reliable","to","add","dependencies","with",D.green "elm install" <> "."
1286− ]
1287− , D.reflow $
1288− "Please ask for help on the community forums if you try those paths and are still\
1289− \ having problems!"
1290− ]
1291−
1292− DetailsNoOfflineSolution ->
1293− Help.report "TROUBLE VERIFYING DEPENDENCIES" (Just "elm.json")
1294− "I could not connect to https://package.elm-lang.org to get the latest list of\
1295− \ packages, and I was unable to verify your dependencies with the information I\
1296− \ have cached locally."
1297− [ D.reflow $
1298− "Are you able to connect to the internet? These dependencies may work once you\
1299− \ get access to the registry!"
1300− , D.toFancyNote
1301− ["If","you","changed","your","dependencies","by","hand,","try","to","change","them","back!"
1302− ,"It","is","much","more","reliable","to","add","dependencies","with",D.green "elm install" <> "."
1303− ]
1304− ]
1305−
1306− DetailsSolverProblem solver ->
1307− toSolverReport solver
1308−
1309− DetailsBadElmInPkg constraint ->
1310− Help.report "ELM VERSION MISMATCH" (Just "elm.json")
1311− "Your elm.json says this package needs a version of Elm in this range:"
1312− [ D.indent 4 $ D.dullyellow $ D.fromChars $ C.toChars constraint
1313− , D.fillSep
1314− [ "But", "you", "are", "using", "Elm"
1315− , D.red (D.fromVersion V.compiler)
1316− , "right", "now."
1317− ]
1318− ]
1319−
1320− DetailsBadElmInAppOutline version ->
1321− Help.report "ELM VERSION MISMATCH" (Just "elm.json")
1322− "Your elm.json says this application needs a different version of Elm."
1323− [ D.fillSep
1324− [ "It", "requires"
1325− , D.green (D.fromVersion version) <> ","
1326− , "but", "you", "are", "using"
1327− , D.red (D.fromVersion V.compiler)
1328− , "right", "now."
1329− ]
1330− ]
1331−
1332− DetailsHandEditedDependencies ->
1333− Help.report "ERROR IN DEPENDENCIES" (Just "elm.json")
1334− "It looks like the dependencies elm.json in were edited by hand (or by a 3rd\
1335− \ party tool) leaving them in an invalid state."
1336− [ D.fillSep
1337− ["Try","to","change","them","back","to","what","they","were","before!"
1338− ,"It","is","much","more","reliable","to","add","dependencies","with",D.green "elm install" <> "."
1339− ]
1340− , D.reflow $
1341− "Please ask for help on the community forums if you try those paths and are still\
1342− \ having problems!"
1343− ]
1344−
1345− DetailsBadOutline outline ->
1346− toOutlineReport outline
1347−
1348− DetailsCannotGetRegistry problem ->
1349− toRegistryProblemReport "PROBLEM LOADING PACKAGE LIST" problem $
1350− "I need the list of published packages to verify your dependencies"
1351−
1352− DetailsBadDeps cacheDir deps ->
1353− case List.sortOn toBadDepRank deps of
1354− [] ->
1355− Help.report "PROBLEM BUILDING DEPENDENCIES" Nothing
1356− "I am not sure what is going wrong though."
1357− [ D.reflow $
1358− "I would try deleting the " ++ cacheDir ++ " and elm-stuff/ directories, then\
1359− \ trying to build again. That will work if some cached files got corrupted\
1360− \ somehow."
1361− , D.reflow $
1362− "If that does not work, go to https://elm-lang.org/community and ask for\
1363− \ help. This is a weird case!"
1364− ]
1365−
1366− d:_ ->
1367− case d of
1368− BD_BadDownload pkg vsn packageProblem ->
1369− toPackageProblemReport pkg vsn packageProblem
1370−
1371− BD_BadBuild pkg vsn fingerprint ->
1372− Help.report "PROBLEM BUILDING DEPENDENCIES" Nothing
1373− "I ran into a compilation error when trying to build the following package:"
1374− [ D.indent 4 $ D.red $ D.fromChars $ Pkg.toChars pkg ++ " " ++ V.toChars vsn
1375− , D.reflow $
1376− "This probably means it has package constraints that are too wide. It may be\
1377− \ possible to tweak your elm.json to avoid the root problem as a stopgap. Head\
1378− \ over to https://elm-lang.org/community to get help figuring out how to take\
1379− \ this path!"
1380− , D.toSimpleNote $
1381− "To help with the root problem, please report this to the package author along\
1382− \ with the following information:"
1383− , D.indent 4 $ D.vcat $
1384− map (\(p,v) -> D.fromChars $ Pkg.toChars p ++ " " ++ V.toChars v) $
1385− Map.toList fingerprint
1386− , D.reflow $
1387− "If you want to help out even more, try building the package locally. That should\
1388− \ give you much more specific information about why this package is failing to\
1389− \ build, which will in turn make it easier for the package author to fix it!"
1390− ]
1391−
1392−
1393−toBadDepRank :: DetailsBadDep -> Int -- lower is better
1394−toBadDepRank badDep =
1395− case badDep of
1396− BD_BadDownload _ _ _ -> 0
1397− BD_BadBuild _ _ _ -> 1
1398−
1399−
1400−
1401−-- PACKAGE PROBLEM
1402−
1403−
1404−data PackageProblem
1405− = PP_BadEndpointRequest Http.Error
1406− | PP_BadEndpointContent String
1407− | PP_BadArchiveRequest Http.Error
1408− | PP_BadArchiveContent String
1409− | PP_BadArchiveHash String String String
1410−
1411−
1412−toPackageProblemReport :: Pkg.Name -> V.Version -> PackageProblem -> Help.Report
1413−toPackageProblemReport pkg vsn problem =
1414− let
1415− thePackage =
1416− Pkg.toChars pkg ++ " " ++ V.toChars vsn
1417− in
1418− case problem of
1419− PP_BadEndpointRequest httpError ->
1420− toHttpErrorReport "PROBLEM DOWNLOADING PACKAGE" httpError $
1421− "I need to find the latest download link for " ++ thePackage
1422−
1423− PP_BadEndpointContent url ->
1424− Help.report "PROBLEM DOWNLOADING PACKAGE" Nothing
1425− (
1426− "I need to find the latest download link for " ++ thePackage ++ ", but I ran into corrupted information from:"
1427− )
1428− [ D.indent 4 $ D.dullyellow $ D.fromChars url
1429− , D.reflow $
1430− "Is something weird with your internet connection. We have gotten reports that\
1431− \ schools, businesses, airports, etc. sometimes intercept requests and add things\
1432− \ to the body or change its contents entirely. Could that be the problem?"
1433− ]
1434−
1435− PP_BadArchiveRequest httpError ->
1436− toHttpErrorReport "PROBLEM DOWNLOADING PACKAGE" httpError $
1437− "I was trying to download the source code for " ++ thePackage
1438−
1439− PP_BadArchiveContent url ->
1440− Help.report "PROBLEM DOWNLOADING PACKAGE" Nothing
1441− (
1442− "I downloaded the source code for " ++ thePackage ++ " from:"
1443− )
1444− [ D.indent 4 $ D.dullyellow $ D.fromChars url
1445− , D.reflow $
1446− "But I was unable to unzip the data. Maybe there is something weird with\
1447− \ your internet connection. We have gotten reports that schools, businesses,\
1448− \ airports, etc. sometimes intercept requests and add things to the body or\
1449− \ change its contents entirely. Could that be the problem?"
1450− ]
1451−
1452− PP_BadArchiveHash url expectedHash actualHash ->
1453− Help.report "CORRUPT PACKAGE DATA" Nothing
1454− (
1455− "I downloaded the source code for " ++ thePackage ++ " from:"
1456− )
1457− [ D.indent 4 $ D.dullyellow $ D.fromChars url
1458− , D.reflow "But it looks like the hash of the archive has changed since publication:"
1459− , D.vcat $ map D.fromChars $
1460− [ " Expected: " ++ expectedHash
1461− , " Actual: " ++ actualHash
1462− ]
1463− , D.reflow $
1464− "This usually means that the package author moved the version\
1465− \ tag, so report it to them and see if that is the issue. Folks\
1466− \ on Elm slack can probably help as well."
1467− ]
1468−
1469−
1470−
1471−-- REGISTRY PROBLEM
1472−
1473−
1474−data RegistryProblem
1475− = RP_Http Http.Error
1476− | RP_Data String BS.ByteString
1477−
1478−
1479−toRegistryProblemReport :: String -> RegistryProblem -> String -> Help.Report
1480−toRegistryProblemReport title problem context =
1481− case problem of
1482− RP_Http err ->
1483− toHttpErrorReport title err context
1484−
1485− RP_Data url body ->
1486− Help.report title Nothing (context ++ ", so I fetched:")
1487− [ D.indent 4 $ D.dullyellow $ D.fromChars url
1488− , D.reflow $
1489− "I got the data back, but it was not what I was expecting. The response\
1490− \ body contains " ++ show (BS.length body) ++ " bytes. Here is the "
1491− ++ if BS.length body <= 76 then "whole thing:" else "beginning:"
1492− , D.indent 4 $ D.dullyellow $ D.fromChars $
1493− if BS.length body <= 76
1494− then BS_UTF8.toString body
1495− else take 73 (BS_UTF8.toString body) ++ "..."
1496− , D.reflow $
1497− "Does this error keep showing up? Maybe there is something weird with your\
1498− \ internet connection. We have gotten reports that schools, businesses,\
1499− \ airports, etc. sometimes intercept requests and add things to the body\
1500− \ or change its contents entirely. Could that be the problem?"
1501− ]
1502−
1503−
1504−toHttpErrorReport :: String -> Http.Error -> String -> Help.Report
1505−toHttpErrorReport title err context =
1506− let
1507− toHttpReport intro url details =
1508− Help.report title Nothing intro $
1509− D.indent 4 (D.dullyellow (D.fromChars url)) : details
1510− in
1511− case err of
1512− Http.BadUrl url reason ->
1513− toHttpReport (context ++ ", so I wanted to fetch:") url
1514− [ D.reflow $ "But my HTTP library is saying this is not a valid URL. It is saying:"
1515− , D.indent 4 $ D.fromChars reason
1516− , D.reflow $
1517− "This may indicate that there is some problem in the compiler, so please open an\
1518− \ issue at https://github.com/elm/compiler/issues listing your operating system, Elm\
1519− \ version, the command you ran, the terminal output, and any additional information\
1520− \ that might help others reproduce the error."
1521− ]
1522−
1523− Http.BadHttp url httpExceptionContent ->
1524− case httpExceptionContent of
1525− HTTP.StatusCodeException response body ->
1526− let
1527− (HTTP.Status code message) = HTTP.responseStatus response
1528− in
1529− toHttpReport (context ++ ", so I tried to fetch:") url
1530− [ D.fillSep $
1531− ["But","it","came","back","as",D.red (D.fromInt code)]
1532− ++ map D.fromChars (words (BS_UTF8.toString message))
1533− , D.indent 4 $ D.reflow $ BS_UTF8.toString body
1534− , D.reflow $
1535− "This may mean some online endpoint changed in an unexpected way, so if does not\
1536− \ seem like something on your side is causing this (e.g. firewall) please report\
1537− \ this to https://github.com/elm/compiler/issues with your operating system, Elm\
1538− \ version, the command you ran, the terminal output, and any additional information\
1539− \ that can help others reproduce the error!"
1540− ]
1541−
1542− HTTP.TooManyRedirects responses ->
1543− toHttpReport (context ++ ", so I tried to fetch:") url
1544− [ D.reflow $ "But I gave up after following these " ++ show (length responses) ++ " redirects:"
1545− , D.indent 4 $ D.vcat $ map toRedirectDoc responses
1546− , D.reflow $
1547− "Is it possible that your internet connection intercepts certain requests? That\
1548− \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
1549− \ and certain countries. Try asking for help locally or in a community forum!"
1550− ]
1551−
1552− otherException ->
1553− toHttpReport (context ++ ", so I tried to fetch:") url
1554− [ D.reflow $ "But my HTTP library is giving me the following error message:"
1555− , D.indent 4 $ D.fromChars (show otherException)
1556− , D.reflow $
1557− "Are you somewhere with a slow internet connection? Or no internet?\
1558− \ Does the link I am trying to fetch work in your browser? Maybe the\
1559− \ site is down? Does your internet connection have a firewall that\
1560− \ blocks certain domains? It is usually something like that!"
1561− ]
1562−
1563− Http.BadMystery url someException ->
1564− toHttpReport (context ++ ", so I tried to fetch:") url
1565− [ D.reflow $ "But I ran into something weird! I was able to extract this error message:"
1566− , D.indent 4 $ D.fromChars (show someException)
1567− , D.reflow $
1568− "Is it possible that your internet connection intercepts certain requests? That\
1569− \ sometimes causes problems for folks in schools, businesses, airports, hotels,\
1570− \ and certain countries. Try asking for help locally or in a community forum!"
1571− ]
1572−
1573−
1574−toRedirectDoc :: HTTP.Response body -> D.Doc
1575−toRedirectDoc response =
1576− let
1577− (HTTP.Status code message) = HTTP.responseStatus response
1578− in
1579− case List.lookup HTTP.hLocation (HTTP.responseHeaders response) of
1580− Just loc -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString loc)
1581− Nothing -> D.red (D.fromInt code) <> " - " <> D.fromChars (BS_UTF8.toString message)
1582−
1583−
1584−
1585−-- MAKE
1586−
1587−
1588−data Make
1589− = MakeNoOutline
1590− | MakeCannotOptimizeAndDebug
1591− | MakeBadDetails Details
1592− | MakeAppNeedsFileNames
1593− | MakePkgNeedsExposing
1594− | MakeMultipleFilesIntoHtml
1595− | MakeNoMain
1596− | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
1597− | MakeCannotBuild BuildProblem
1598− | MakeBadGenerate Generate
1599−
1600−
1601−makeToReport :: Make -> Help.Report
1602−makeToReport make =
1603− case make of
1604− MakeNoOutline ->
1605− Help.report "NO elm.json FILE" Nothing
1606− "It looks like you are starting a new Elm project. Very exciting! Try running:"
1607− [ D.indent 4 $ D.green $ "elm init"
1608− , D.reflow $
1609− "It will help you get set up. It is really simple!"
1610− ]
1611−
1612− MakeCannotOptimizeAndDebug ->
1613− Help.docReport "CLASHING FLAGS" Nothing
1614− ( D.fillSep
1615− ["I","cannot","compile","with",D.red "--optimize","and"
1616− ,D.red "--debug","at","the","same","time."
1617− ]
1618− )
1619− [ D.reflow
1620− "I need to take away information to optimize things, and I need to\
1621− \ add information to add the debugger. It is impossible to do both\
1622− \ at once though! Pick just one of those flags and it should work!"
1623− ]
1624−
1625− MakeBadDetails detailsProblem ->
1626− toDetailsReport detailsProblem
1627−
1628− MakeAppNeedsFileNames ->
1629− Help.report "NO INPUT" Nothing
1630− "What should I make though? I need specific files like:"
1631− [ D.vcat
1632− [ D.indent 4 $ D.green "elm make src/Main.elm"
1633− , D.indent 4 $ D.green "elm make src/This.elm src/That.elm"
1634− ]
1635− , D.reflow $
1636− "I recommend reading through https://guide.elm-lang.org for guidance on what to\
1637− \ actually put in those files!"
1638− ]
1639−
1640− MakePkgNeedsExposing ->
1641− Help.report "NO INPUT" Nothing
1642− "What should I make though? I need specific files like:"
1643− [ D.vcat
1644− [ D.indent 4 $ D.green "elm make src/Main.elm"
1645− , D.indent 4 $ D.green "elm make src/This.elm src/That.elm"
1646− ]
1647− , D.reflow $
1648− "You can also entries to the \"exposed-modules\" list in your elm.json file, and\
1649− \ I will try to compile the relevant files."
1650− ]
1651−
1652− MakeMultipleFilesIntoHtml ->
1653− Help.report "TOO MANY FILES" Nothing
1654− (
1655− "When producing an HTML file, I can only handle one file."
1656− )
1657− [ D.fillSep
1658− ["Switch","to",D.dullyellow "--output=/dev/null","if","you","just","want"
1659− ,"to","get","compile","errors.","This","skips","the","code","gen","phase,"
1660− ,"so","it","can","be","a","bit","faster","than","other","options","sometimes."
1661− ]
1662− , D.fillSep
1663− ["Switch","to",D.dullyellow "--output=elm.js","if","you","want","multiple"
1664− ,"`main`","values","available","in","a","single","JavaScript","file.","Then"
1665− ,"you","can","make","your","own","customized","HTML","file","that","embeds"
1666− ,"multiple","Elm","nodes.","The","generated","JavaScript","also","shares"
1667− ,"dependencies","between","modules,","so","it","should","be","smaller","than"
1668− ,"compiling","each","module","separately."
1669− ]
1670− ]
1671−
1672− MakeNoMain ->
1673− Help.report "NO MAIN" Nothing
1674− (
1675− "When producing an HTML file, I require that the given file has a `main` value.\
1676− \ That way I have something to show on screen!"
1677− )
1678− [ D.reflow $
1679− "Try adding a `main` value to your file? Or if you just want to verify that this\
1680− \ module compiles, switch to --output=/dev/null to skip the code gen phase\
1681− \ altogether."
1682− , D.toSimpleNote $
1683− "Adding a `main` value can be as brief as adding something like this:"
1684− , D.vcat
1685− [ D.fillSep [D.cyan "import","Html"]
1686− , ""
1687− , D.fillSep [D.green "main","="]
1688− , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1689− ]
1690− , D.reflow $
1691− "From there I can create an HTML file that says \"Hello!\" on screen. I recommend\
1692− \ looking through https://guide.elm-lang.org for more guidance on how to fill in\
1693− \ the `main` value."
1694− ]
1695−
1696− MakeNonMainFilesIntoJavaScript m ms ->
1697− case ms of
1698− [] ->
1699− Help.report "NO MAIN" Nothing
1700− (
1701− "When producing a JS file, I require that the given file has a `main` value. That\
1702− \ way Elm." ++ ModuleName.toChars m ++ ".init() is definitely defined in the\
1703− \ resulting file!"
1704− )
1705− [ D.reflow $
1706− "Try adding a `main` value to your file? Or if you just want to verify that this\
1707− \ module compiles, switch to --output=/dev/null to skip the code gen phase\
1708− \ altogether."
1709− , D.toSimpleNote $
1710− "Adding a `main` value can be as brief as adding something like this:"
1711− , D.vcat
1712− [ D.fillSep [D.cyan "import","Html"]
1713− , ""
1714− , D.fillSep [D.green "main","="]
1715− , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1716− ]
1717− , D.reflow $
1718− "Or use https://package.elm-lang.org/packages/elm/core/latest/Platform#worker to\
1719− \ make a `main` with no user interface."
1720− ]
1721−
1722− _:_ ->
1723− Help.report "NO MAIN" Nothing
1724− (
1725− "When producing a JS file, I require that given files all have `main` values.\
1726− \ That way functions like Elm." ++ ModuleName.toChars m ++ ".init() are\
1727− \ definitely defined in the resulting file. I am missing `main` values in:"
1728− )
1729− [ D.indent 4 $ D.red $ D.vcat $ map D.fromName (m:ms)
1730− , D.reflow $
1731− "Try adding a `main` value to them? Or if you just want to verify that these\
1732− \ modules compile, switch to --output=/dev/null to skip the code gen phase\
1733− \ altogether."
1734− , D.toSimpleNote $
1735− "Adding a `main` value can be as brief as adding something like this:"
1736− , D.vcat
1737− [ D.fillSep [D.cyan "import","Html"]
1738− , ""
1739− , D.fillSep [D.green "main","="]
1740− , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
1741− ]
1742− , D.reflow $
1743− "Or use https://package.elm-lang.org/packages/elm/core/latest/Platform#worker to\
1744− \ make a `main` with no user interface."
1745− ]
1746−
1747− MakeCannotBuild buildProblem ->
1748− toBuildProblemReport buildProblem
1749−
1750− MakeBadGenerate generateProblem ->
1751− toGenerateReport generateProblem
1752−
1753−
1754−
1755−-- BUILD PROBLEM
1756−
1757−
1758−data BuildProblem
1759− = BuildBadModules FilePath Error.Module [Error.Module]
1760− | BuildProjectProblem BuildProjectProblem
1761−
1762−
1763−data BuildProjectProblem
1764− = BP_PathUnknown FilePath
1765− | BP_WithBadExtension FilePath
1766− | BP_WithAmbiguousSrcDir FilePath FilePath FilePath
1767− | BP_MainPathDuplicate FilePath FilePath
1768− | BP_RootNameDuplicate ModuleName.Raw FilePath FilePath
1769− | BP_RootNameInvalid FilePath FilePath [String]
1770− | BP_CannotLoadDependencies
1771− | BP_Cycle ModuleName.Raw [ModuleName.Raw]
1772− | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
1773−
1774−
1775−toBuildProblemReport :: BuildProblem -> Help.Report
1776−toBuildProblemReport problem =
1777− case problem of
1778− BuildBadModules root e es ->
1779− Help.compilerReport root e es
1780−
1781− BuildProjectProblem projectProblem ->
1782− toProjectProblemReport projectProblem
1783−
1784−
1785−toProjectProblemReport :: BuildProjectProblem -> Help.Report
1786−toProjectProblemReport projectProblem =
1787− case projectProblem of
1788− BP_PathUnknown path ->
1789− Help.report "FILE NOT FOUND" Nothing
1790− "I cannot find this file:"
1791− [ D.indent 4 $ D.red $ D.fromChars path
1792− , D.reflow $ "Is there a typo?"
1793− , D.toSimpleNote $
1794− "If you are just getting started, try working through the examples in the\
1795− \ official guide https://guide.elm-lang.org to get an idea of the kinds of things\
1796− \ that typically go in a src/Main.elm file."
1797− ]
1798−
1799− BP_WithBadExtension path ->
1800− Help.report "UNEXPECTED FILE EXTENSION" Nothing
1801− "I can only compile Elm files (with a .elm extension) but you want me to compile:"
1802− [ D.indent 4 $ D.red $ D.fromChars path
1803− , D.reflow $ "Is there a typo? Can the file extension be changed?"
1804− ]
1805−
1806− BP_WithAmbiguousSrcDir path srcDir1 srcDir2 ->
1807− Help.report "CONFUSING FILE" Nothing
1808− "I am getting confused when I try to compile this file:"
1809− [ D.indent 4 $ D.red $ D.fromChars path
1810− , D.reflow $
1811− "I always check if files appear in any of the \"source-directories\" listed in\
1812− \ your elm.json to see if there might be some cached information about them. That\
1813− \ can help me compile faster! But in this case, it looks like this file may be in\
1814− \ either of these directories:"
1815− , D.indent 4 $ D.red $ D.vcat $ map D.fromChars [srcDir1,srcDir2]
1816− , D.reflow $
1817− "Try to make it so no source directory contains another source directory!"
1818− ]
1819−
1820− BP_MainPathDuplicate path1 path2 ->
1821− Help.report "CONFUSING FILES" Nothing
1822− "You are telling me to compile these two files:"
1823− [ D.indent 4 $ D.red $ D.vcat $ map D.fromChars [ path1, path2 ]
1824− , D.reflow $
1825− if path1 == path2 then
1826− "Why are you telling me twice? Is something weird going on with a script?\
1827− \ I figured I would let you know about it just in case something is wrong.\
1828− \ Only list it once and you should be all set!"
1829− else
1830− "But seem to be the same file though... It makes me think something tricky is\
1831− \ going on with symlinks in your project, so I figured I would let you know\
1832− \ about it just in case. Remove one of these files from your command to get\
1833− \ unstuck!"
1834− ]
1835−
1836− BP_RootNameDuplicate name outsidePath otherPath ->
1837− Help.report "MODULE NAME CLASH" Nothing
1838− "These two files are causing a module name clash:"
1839− [ D.indent 4 $ D.red $ D.vcat $ map D.fromChars [ outsidePath, otherPath ]
1840− , D.reflow $
1841− "They both say `module " ++ ModuleName.toChars name ++ " exposing (..)` up\
1842− \ at the top, but they cannot have the same name!"
1843− , D.reflow $
1844− "Try changing to a different module name in one of them!"
1845− ]
1846−
1847− BP_RootNameInvalid givenPath srcDir _ ->
1848− Help.report "UNEXPECTED FILE NAME" Nothing
1849− "I am having trouble with this file name:"
1850− [ D.indent 4 $ D.red $ D.fromChars givenPath
1851− , D.reflow $
1852− "I found it in your " ++ FP.addTrailingPathSeparator srcDir ++ " directory\
1853− \ which is good, but I expect all of the files in there to use the following\
1854− \ module naming convention:"
1855− , toModuleNameConventionTable srcDir [ "Main", "HomePage", "Http.Helpers" ]
1856− , D.reflow $
1857− "Notice that the names always start with capital letters! Can you make your file\
1858− \ use this naming convention?"
1859− , D.toSimpleNote $
1860− "Having a strict naming convention like this makes it a lot easier to find\
1861− \ things in large projects. If you see a module imported, you know where to look\
1862− \ for the corresponding file every time!"
1863− ]
1864−
1865− BP_CannotLoadDependencies ->
1866− corruptCacheReport
1867−
1868− BP_Cycle name names ->
1869− Help.report "IMPORT CYCLE" Nothing
1870− "Your module imports form a cycle:"
1871− [ D.cycle 4 name names
1872− , D.reflow $
1873− "Learn more about why this is disallowed and how to break cycles here:"
1874− ++ D.makeLink "import-cycles"
1875− ]
1876−
1877− BP_MissingExposed (NE.List (name, problem) _) ->
1878− case problem of
1879− Import.NotFound ->
1880− Help.report "MISSING MODULE" (Just "elm.json")
1881− "The \"exposed-modules\" of your elm.json lists the following module:"
1882− [ D.indent 4 $ D.red $ D.fromName name
1883− , D.reflow $
1884− "But I cannot find it in your src/ directory. Is there a typo? Was it renamed?"
1885− ]
1886−
1887− Import.Ambiguous _ _ pkg _ ->
1888− Help.report "AMBIGUOUS MODULE NAME" (Just "elm.json")
1889− "The \"exposed-modules\" of your elm.json lists the following module:"
1890− [ D.indent 4 $ D.red $ D.fromName name
1891− , D.reflow $
1892− "But a module from " ++ Pkg.toChars pkg ++ " already uses that name. Try\
1893− \ choosing a different name for your local file."
1894− ]
1895−
1896− Import.AmbiguousLocal path1 path2 paths ->
1897− Help.report "AMBIGUOUS MODULE NAME" (Just "elm.json")
1898− "The \"exposed-modules\" of your elm.json lists the following module:"
1899− [ D.indent 4 $ D.red $ D.fromName name
1900− , D.reflow $
1901− "But I found multiple files with that name:"
1902− , D.dullyellow $ D.indent 4 $ D.vcat $
1903− map D.fromChars (path1:path2:paths)
1904− , D.reflow $
1905− "Change the module names to be distinct!"
1906− ]
1907−
1908− Import.AmbiguousForeign _ _ _ ->
1909− Help.report "MISSING MODULE" (Just "elm.json")
1910− "The \"exposed-modules\" of your elm.json lists the following module:"
1911− [ D.indent 4 $ D.red $ D.fromName name
1912− , D.reflow $
1913− "But I cannot find it in your src/ directory. Is there a typo? Was it renamed?"
1914− , D.toSimpleNote $
1915− "It is not possible to \"re-export\" modules from other packages. You can only\
1916− \ expose modules that you define in your own code."
1917− ]
1918−
1919−
1920−toModuleNameConventionTable :: FilePath -> [String] -> D.Doc
1921−toModuleNameConventionTable srcDir names =
1922− let
1923− toPair name =
1924− ( name
1925− , srcDir </> map (\c -> if c == '.' then FP.pathSeparator else c) name <.> "elm"
1926− )
1927−
1928− namePairs = map toPair names
1929− nameWidth = maximum (11 : map (length . fst) namePairs)
1930− pathWidth = maximum ( 9 : map (length . snd) namePairs)
1931−
1932− padded width str =
1933− str ++ replicate (width - length str) ' '
1934−
1935− toRow (name, path) =
1936− D.fromChars $
1937− "| " ++ padded nameWidth name ++ " | " ++ padded pathWidth path ++ " |"
1938−
1939− bar =
1940− D.fromChars $
1941− "+-" ++ replicate nameWidth '-' ++ "-+-" ++ replicate pathWidth '-' ++ "-+"
1942− in
1943− D.indent 4 $ D.vcat $
1944− [ bar, toRow ("Module Name", "File Path"), bar ] ++ map toRow namePairs ++ [ bar ]
1945−
1946−
1947−
1948−-- GENERATE
1949−
1950−
1951−data Generate
1952− = GenerateCannotLoadArtifacts
1953− | GenerateCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
1954−
1955−
1956−toGenerateReport :: Generate -> Help.Report
1957−toGenerateReport problem =
1958− case problem of
1959− GenerateCannotLoadArtifacts ->
1960− corruptCacheReport
1961−
1962− GenerateCannotOptimizeDebugValues m ms ->
1963− Help.report "DEBUG REMNANTS" Nothing
1964− "There are uses of the `Debug` module in the following modules:"
1965− [ D.indent 4 $ D.red $ D.vcat $ map (D.fromChars . ModuleName.toChars) (m:ms)
1966− , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
1967− , D.toSimpleNote $
1968− "The issue is that --optimize strips out info needed by `Debug` functions.\
1969− \ Here are two examples:"
1970− , D.indent 4 $ D.reflow $
1971− "(1) It shortens record field names. This makes the generated JavaScript\
1972− \ smaller, but `Debug.toString` cannot know the real field names anymore."
1973− , D.indent 4 $ D.reflow $
1974− "(2) Values like `type Height = Height Float` are unboxed. This reduces\
1975− \ allocation, but it also means that `Debug.toString` cannot tell if it is\
1976− \ looking at a `Height` or `Float` value."
1977− , D.reflow $
1978− "There are a few other cases like that, and it will be much worse once we start\
1979− \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
1980− \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
1981− \ exists!"
1982− ]
1983−
1984−
1985−
1986−-- CORRUPT CACHE
1987−
1988−
1989−corruptCacheReport :: Help.Report
1990−corruptCacheReport =
1991− Help.report "CORRUPT CACHE" Nothing
1992− "It looks like some of the information cached in elm-stuff/ has been corrupted."
1993− [ D.reflow $
1994− "Try deleting your elm-stuff/ directory to get unstuck."
1995− , D.toSimpleNote $
1996− "This almost certainly means that a 3rd party tool (or editor plugin) is\
1997− \ causing problems your the elm-stuff/ directory. Try disabling 3rd party tools\
1998− \ one by one until you figure out which it is!"
1999− ]
2000−
2001−
2002−
2003−-- REACTOR
2004−
2005−
2006−data Reactor
2007− = ReactorNoOutline
2008− | ReactorBadDetails Details
2009− | ReactorBadBuild BuildProblem
2010− | ReactorBadGenerate Generate
2011−
2012−
2013−reactorToReport :: Reactor -> Help.Report
2014−reactorToReport problem =
2015− case problem of
2016− ReactorNoOutline ->
2017− Help.report "NEW PROJECT?" Nothing
2018− "Are you trying to start a new project? Try this command in the terminal:"
2019− [ D.indent 4 $ D.green "elm init"
2020− , D.reflow "It will help you get started!"
2021− ]
2022−
2023− ReactorBadDetails details ->
2024− toDetailsReport details
2025−
2026− ReactorBadBuild buildProblem ->
2027− toBuildProblemReport buildProblem
2028−
2029− ReactorBadGenerate generate ->
2030− toGenerateReport generate
2031−
2032−
2033−
2034−-- REPL
2035−
2036−
2037−data Repl
2038− = ReplBadDetails Details
2039− | ReplBadInput BS.ByteString Error.Error
2040− | ReplBadLocalDeps FilePath Error.Module [Error.Module]
2041− | ReplProjectProblem BuildProjectProblem
2042− | ReplBadGenerate Generate
2043− | ReplBadCache
2044− | ReplBlocked
2045−
2046−
2047−replToReport :: Repl -> Help.Report
2048−replToReport problem =
2049− case problem of
2050− ReplBadDetails details ->
2051− toDetailsReport details
2052−
2053− ReplBadInput source err ->
2054− Help.compilerReport "/" (Error.Module N.replModule "REPL" File.zeroTime source err) []
2055−
2056− ReplBadLocalDeps root e es ->
2057− Help.compilerReport root e es
2058−
2059− ReplProjectProblem projectProblem ->
2060− toProjectProblemReport projectProblem
2061−
2062− ReplBadGenerate generate ->
2063− toGenerateReport generate
2064−
2065− ReplBadCache ->
2066− corruptCacheReport
2067−
2068− ReplBlocked ->
2069− corruptCacheReport
builder/src/Reporting/Exit/Help.hsdeleted−136
@@ -1,136 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Reporting.Exit.Help
3− ( Report
4− , report
5− , docReport
6− , jsonReport
7− , compilerReport
8− , reportToDoc
9− , reportToJson
10− , toString
11− , toStdout
12− , toStderr
13− )
14− where
15−
16−
17−import GHC.IO.Handle (hIsTerminalDevice)
18−import System.IO (Handle, hPutStr, stderr, stdout)
19−
20−import qualified Json.Encode as E
21−import Json.Encode ((==>))
22−import Reporting.Doc ((<+>))
23−import qualified Reporting.Doc as D
24−import qualified Reporting.Error as Error
25−
26−
27−
28−-- REPORT
29−
30−
31−data Report
32− = CompilerReport FilePath Error.Module [Error.Module]
33− | Report
34− { _title :: String
35− , _path :: Maybe FilePath
36− , _message :: D.Doc
37− }
38−
39−
40−report :: String -> Maybe FilePath -> String -> [D.Doc] -> Report
41−report title path startString others =
42− Report title path $ D.stack (D.reflow startString:others)
43−
44−
45−docReport :: String -> Maybe FilePath -> D.Doc -> [D.Doc] -> Report
46−docReport title path startDoc others =
47− Report title path $ D.stack (startDoc:others)
48−
49−
50−jsonReport :: String -> Maybe FilePath -> D.Doc -> Report
51−jsonReport =
52− Report
53−
54−
55−compilerReport :: FilePath -> Error.Module -> [Error.Module] -> Report
56−compilerReport =
57− CompilerReport
58−
59−
60−
61−-- TO DOC
62−
63−
64−reportToDoc :: Report -> D.Doc
65−reportToDoc report_ =
66− case report_ of
67− CompilerReport root e es ->
68− Error.toDoc root e es
69−
70− Report title maybePath message ->
71− let
72− makeDashes n =
73− replicate (max 1 (80 - n)) '-'
74−
75− errorBarEnd =
76− case maybePath of
77− Nothing ->
78− makeDashes (4 + length title)
79−
80− Just path ->
81− makeDashes (5 + length title + length path) ++ " " ++ path
82−
83− errorBar =
84− D.dullcyan $
85− "--" <+> D.fromChars title <+> D.fromChars errorBarEnd
86− in
87− D.stack [errorBar, message, ""]
88−
89−
90−
91−-- TO JSON
92−
93−
94−reportToJson :: Report -> E.Value
95−reportToJson report_ =
96− case report_ of
97− CompilerReport _ e es ->
98− E.object
99− [ "type" ==> E.chars "compile-errors"
100− , "errors" ==> E.list Error.toJson (e:es)
101− ]
102−
103− Report title maybePath message ->
104− E.object
105− [ "type" ==> E.chars "error"
106− , "path" ==> maybe E.null E.chars maybePath
107− , "title" ==> E.chars title
108− , "message" ==> D.encode message
109− ]
110−
111−
112−
113−-- OUTPUT
114−
115−
116−toString :: D.Doc -> String
117−toString =
118− D.toString
119−
120−
121−toStdout :: D.Doc -> IO ()
122−toStdout doc =
123− toHandle stdout doc
124−
125−
126−toStderr :: D.Doc -> IO ()
127−toStderr doc =
128− toHandle stderr doc
129−
130−
131−toHandle :: Handle -> D.Doc -> IO ()
132−toHandle handle doc =
133− do isTerminal <- hIsTerminalDevice handle
134− if isTerminal
135− then D.toAnsi handle doc
136− else hPutStr handle (toString doc)
builder/src/Reporting/Task.hsdeleted−114
@@ -1,114 +0,0 @@
1−{-# LANGUAGE Rank2Types #-}
2−module Reporting.Task
3− ( Task
4− , run
5− , throw
6− , mapError
7− --
8− , io
9− , mio
10− , eio
11− )
12− where
13−
14−
15−
16−-- TASKS
17−
18−
19−newtype Task x a =
20− Task
21− (
22− forall result. (a -> IO result) -> (x -> IO result) -> IO result
23− )
24−
25−
26−run :: Task x a -> IO (Either x a)
27−run (Task task) =
28− task (return . Right) (return . Left)
29−
30−
31−throw :: x -> Task x a
32−throw x =
33− Task $ \_ err -> err x
34−
35−
36−mapError :: (x -> y) -> Task x a -> Task y a
37−mapError func (Task task) =
38− Task $ \ok err ->
39− task ok (err . func)
40−
41−
42−
43−-- IO
44−
45−
46−{-# INLINE io #-}
47−io :: IO a -> Task x a
48−io work =
49− Task $ \ok _ -> work >>= ok
50−
51−
52−mio :: x -> IO (Maybe a) -> Task x a
53−mio x work =
54− Task $ \ok err ->
55− do result <- work
56− case result of
57− Just a -> ok a
58− Nothing -> err x
59−
60−
61−eio :: (x -> y) -> IO (Either x a) -> Task y a
62−eio func work =
63− Task $ \ok err ->
64− do result <- work
65− case result of
66− Right a -> ok a
67− Left x -> err (func x)
68−
69−
70−
71−-- INSTANCES
72−
73−
74−instance Functor (Task x) where
75− {-# INLINE fmap #-}
76− fmap func (Task taskA) =
77− Task $ \ok err ->
78− let
79− okA arg = ok (func arg)
80− in
81− taskA okA err
82−
83−
84−instance Applicative (Task x) where
85− {-# INLINE pure #-}
86− pure a =
87− Task $ \ok _ -> ok a
88−
89− {-# INLINE (<*>) #-}
90− (<*>) (Task taskFunc) (Task taskArg) =
91− Task $ \ok err ->
92− let
93− okFunc func =
94− let
95− okArg arg = ok (func arg)
96− in
97− taskArg okArg err
98− in
99− taskFunc okFunc err
100−
101−
102−instance Monad (Task x) where
103− {-# INLINE return #-}
104− return = pure
105−
106− {-# INLINE (>>=) #-}
107− (>>=) (Task taskA) callback =
108− Task $ \ok err ->
109− let
110− okA a =
111− case callback a of
112− Task taskB -> taskB ok err
113− in
114− taskA okA err
builder/src/Stuff.hsdeleted−179
@@ -1,179 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Stuff
3− ( details
4− , interfaces
5− , objects
6− , prepublishDir
7− , elmi
8− , elmo
9− , temp
10− , findRoot
11− , withRootLock
12− , withRegistryLock
13− , PackageCache
14− , getPackageCache
15− , registry
16− , package
17− , getReplCache
18− , getElmHome
19− )
20− where
21−
22−
23−import qualified System.Directory as Dir
24−import qualified System.Environment as Env
25−import qualified System.FileLock as Lock
26−import qualified System.FilePath as FP
27−import System.FilePath ((</>), (<.>))
28−
29−import qualified Elm.ModuleName as ModuleName
30−import qualified Elm.Package as Pkg
31−import qualified Elm.Version as V
32−
33−
34−
35−-- PATHS
36−
37−
38−stuff :: FilePath -> FilePath
39−stuff root =
40− root </> "elm-stuff" </> compilerVersion
41−
42−
43−details :: FilePath -> FilePath
44−details root =
45− stuff root </> "d.dat"
46−
47−
48−interfaces :: FilePath -> FilePath
49−interfaces root =
50− stuff root </> "i.dat"
51−
52−
53−objects :: FilePath -> FilePath
54−objects root =
55− stuff root </> "o.dat"
56−
57−
58−prepublishDir :: FilePath -> FilePath
59−prepublishDir root =
60− stuff root </> "prepublish"
61−
62−
63−compilerVersion :: FilePath
64−compilerVersion =
65− V.toChars V.compiler
66−
67−
68−
69−-- ELMI and ELMO
70−
71−
72−elmi :: FilePath -> ModuleName.Raw -> FilePath
73−elmi root name =
74− toArtifactPath root name "elmi"
75−
76−
77−elmo :: FilePath -> ModuleName.Raw -> FilePath
78−elmo root name =
79− toArtifactPath root name "elmo"
80−
81−
82−toArtifactPath :: FilePath -> ModuleName.Raw -> String -> FilePath
83−toArtifactPath root name ext =
84− stuff root </> ModuleName.toHyphenPath name <.> ext
85−
86−
87−
88−-- TEMP
89−
90−
91−temp :: FilePath -> String -> FilePath
92−temp root ext =
93− stuff root </> "temp" <.> ext
94−
95−
96−
97−-- ROOT
98−
99−
100−findRoot :: IO (Maybe FilePath)
101−findRoot =
102− do dir <- Dir.getCurrentDirectory
103− findRootHelp (FP.splitDirectories dir)
104−
105−
106−findRootHelp :: [String] -> IO (Maybe FilePath)
107−findRootHelp dirs =
108− case dirs of
109− [] ->
110− return Nothing
111−
112− _:_ ->
113− do exists <- Dir.doesFileExist (FP.joinPath dirs </> "elm.json")
114− if exists
115− then return (Just (FP.joinPath dirs))
116− else findRootHelp (init dirs)
117−
118−
119−
120−-- LOCKS
121−
122−
123−withRootLock :: FilePath -> IO a -> IO a
124−withRootLock root work =
125− do let dir = stuff root
126− Dir.createDirectoryIfMissing True dir
127− Lock.withFileLock (dir </> "lock") Lock.Exclusive (\_ -> work)
128−
129−
130−withRegistryLock :: PackageCache -> IO a -> IO a
131−withRegistryLock (PackageCache dir) work =
132− Lock.withFileLock (dir </> "lock") Lock.Exclusive (\_ -> work)
133−
134−
135−
136−-- PACKAGE CACHES
137−
138−
139−newtype PackageCache = PackageCache FilePath
140−
141−
142−getPackageCache :: IO PackageCache
143−getPackageCache =
144− PackageCache <$> getCacheDir "packages"
145−
146−
147−registry :: PackageCache -> FilePath
148−registry (PackageCache dir) =
149− dir </> "registry.dat"
150−
151−
152−package :: PackageCache -> Pkg.Name -> V.Version -> FilePath
153−package (PackageCache dir) name version =
154− dir </> Pkg.toFilePath name </> V.toChars version
155−
156−
157−
158−-- CACHE
159−
160−
161−getReplCache :: IO FilePath
162−getReplCache =
163− getCacheDir "repl"
164−
165−
166−getCacheDir :: FilePath -> IO FilePath
167−getCacheDir projectName =
168− do home <- getElmHome
169− let root = home </> compilerVersion </> projectName
170− Dir.createDirectoryIfMissing True root
171− return root
172−
173−
174−getElmHome :: IO FilePath
175−getElmHome =
176− do maybeCustomHome <- Env.lookupEnv "ELM_HOME"
177− case maybeCustomHome of
178− Just customHome -> return customHome
179− Nothing -> Dir.getAppUserDataDirectory "elm"
cabal.configdeleted−2
@@ -1,2 +0,0 @@
1−profiling: False
2−library-profiling: True
docs/upgrade-instructions/earlier.md → changelog.mdrenamed

The content is the same.

compiler/src/AST/Source.hsdeleted−209
@@ -1,209 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module AST.Source
3− ( Expr, Expr_(..), VarType(..)
4− , Def(..)
5− , Pattern, Pattern_(..)
6− , Type, Type_(..)
7− , Module(..)
8− , getName
9− , getImportName
10− , Import(..)
11− , Value(..)
12− , Union(..)
13− , Alias(..)
14− , Infix(..)
15− , Port(..)
16− , Effects(..)
17− , Manager(..)
18− , Docs(..)
19− , Comment(..)
20− , Exposing(..)
21− , Exposed(..)
22− , Privacy(..)
23− )
24− where
25−
26−
27−import Data.Name (Name)
28−import qualified Data.Name as Name
29−
30−import qualified AST.Utils.Binop as Binop
31−import qualified AST.Utils.Shader as Shader
32−import qualified Elm.Float as EF
33−import qualified Elm.String as ES
34−import qualified Parse.Primitives as P
35−import qualified Reporting.Annotation as A
36−
37−
38−
39−-- EXPRESSIONS
40−
41−
42−type Expr = A.Located Expr_
43−
44−
45−data Expr_
46− = Chr ES.String
47− | Str ES.String
48− | Int Int
49− | Float EF.Float
50− | Var VarType Name
51− | VarQual VarType Name Name
52− | List [Expr]
53− | Op Name
54− | Negate Expr
55− | Binops [(Expr, A.Located Name)] Expr
56− | Lambda [Pattern] Expr
57− | Call Expr [Expr]
58− | If [(Expr, Expr)] Expr
59− | Let [A.Located Def] Expr
60− | Case Expr [(Pattern, Expr)]
61− | Accessor Name
62− | Access Expr (A.Located Name)
63− | Update (A.Located Name) [(A.Located Name, Expr)]
64− | Record [(A.Located Name, Expr)]
65− | Unit
66− | Tuple Expr Expr [Expr]
67− | Shader Shader.Source Shader.Types
68−
69−
70−data VarType = LowVar | CapVar
71−
72−
73−
74−-- DEFINITIONS
75−
76−
77−data Def
78− = Define (A.Located Name) [Pattern] Expr (Maybe Type)
79− | Destruct Pattern Expr
80−
81−
82−
83−-- PATTERN
84−
85−
86−type Pattern = A.Located Pattern_
87−
88−
89−data Pattern_
90− = PAnything
91− | PVar Name
92− | PRecord [A.Located Name]
93− | PAlias Pattern (A.Located Name)
94− | PUnit
95− | PTuple Pattern Pattern [Pattern]
96− | PCtor A.Region Name [Pattern]
97− | PCtorQual A.Region Name Name [Pattern]
98− | PList [Pattern]
99− | PCons Pattern Pattern
100− | PChr ES.String
101− | PStr ES.String
102− | PInt Int
103−
104−
105−
106−-- TYPE
107−
108−
109−type Type =
110− A.Located Type_
111−
112−
113−data Type_
114− = TLambda Type Type
115− | TVar Name
116− | TType A.Region Name [Type]
117− | TTypeQual A.Region Name Name [Type]
118− | TRecord [(A.Located Name, Type)] (Maybe (A.Located Name))
119− | TUnit
120− | TTuple Type Type [Type]
121−
122−
123−
124−-- MODULE
125−
126−
127−data Module =
128− Module
129− { _name :: Maybe (A.Located Name)
130− , _exports :: A.Located Exposing
131− , _docs :: Docs
132− , _imports :: [Import]
133− , _values :: [A.Located Value]
134− , _unions :: [A.Located Union]
135− , _aliases :: [A.Located Alias]
136− , _binops :: [A.Located Infix]
137− , _effects :: Effects
138− }
139−
140−
141−getName :: Module -> Name
142−getName (Module maybeName _ _ _ _ _ _ _ _) =
143− case maybeName of
144− Just (A.At _ name) ->
145− name
146−
147− Nothing ->
148− Name._Main
149−
150−
151−getImportName :: Import -> Name
152−getImportName (Import (A.At _ name) _ _) =
153− name
154−
155−
156−data Import =
157− Import
158− { _import :: A.Located Name
159− , _alias :: Maybe Name
160− , _exposing :: Exposing
161− }
162−
163−
164−data Value = Value (A.Located Name) [Pattern] Expr (Maybe Type)
165−data Union = Union (A.Located Name) [A.Located Name] [(A.Located Name, [Type])]
166−data Alias = Alias (A.Located Name) [A.Located Name] Type
167−data Infix = Infix Name Binop.Associativity Binop.Precedence Name
168−data Port = Port (A.Located Name) Type
169−
170−
171−data Effects
172− = NoEffects
173− | Ports [Port]
174− | Manager A.Region Manager
175−
176−
177−data Manager
178− = Cmd (A.Located Name)
179− | Sub (A.Located Name)
180− | Fx (A.Located Name) (A.Located Name)
181−
182−
183−data Docs
184− = NoDocs A.Region
185− | YesDocs Comment [(Name, Comment)]
186−
187−
188−newtype Comment =
189− Comment P.Snippet
190−
191−
192−
193−-- EXPOSING
194−
195−
196−data Exposing
197− = Open
198− | Explicit [Exposed]
199−
200−
201−data Exposed
202− = Lower (A.Located Name)
203− | Upper (A.Located Name) Privacy
204− | Operator A.Region Name
205−
206−
207−data Privacy
208− = Public A.Region
209− | Private
compiler/src/AST/Utils/Shader.hsdeleted−91
@@ -1,91 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE EmptyDataDecls #-}
3−module AST.Utils.Shader
4− ( Source
5− , Types(..)
6− , Type(..)
7− , fromChars
8− , toJsStringBuilder
9− )
10− where
11−
12−
13−import Control.Monad (liftM)
14−import Data.Binary (Binary, get, put)
15−import qualified Data.ByteString as BS
16−import qualified Data.ByteString.Builder as B
17−import qualified Data.ByteString.UTF8 as BS_UTF8
18−import qualified Data.Map as Map
19−import qualified Data.Name as Name
20−
21−
22−
23−-- SOURCE
24−
25−
26−newtype Source =
27− Source BS.ByteString
28−
29−
30−
31−-- TYPES
32−
33−
34−data Types =
35− Types
36− { _attribute :: Map.Map Name.Name Type
37− , _uniform :: Map.Map Name.Name Type
38− , _varying :: Map.Map Name.Name Type
39− }
40−
41−
42−data Type
43− = Int
44− | Float
45− | V2
46− | V3
47− | V4
48− | M4
49− | Texture
50−
51−
52−
53−-- TO BUILDER
54−
55−
56−toJsStringBuilder :: Source -> B.Builder
57−toJsStringBuilder (Source src) =
58− B.byteString src
59−
60−
61−
62−-- FROM CHARS
63−
64−
65−fromChars :: [Char] -> Source
66−fromChars chars =
67− Source (BS_UTF8.fromString (escape chars))
68−
69−
70−escape :: [Char] -> [Char]
71−escape chars =
72− case chars of
73− [] ->
74− []
75−
76− c:cs
77− | c == '\r' -> escape cs
78− | c == '\n' -> '\\' : 'n' : escape cs
79− | c == '\"' -> '\\' : '"' : escape cs
80− | c == '\'' -> '\\' : '\'' : escape cs
81− | c == '\\' -> '\\' : '\\' : escape cs
82− | otherwise -> c : escape cs
83−
84−
85−
86−-- BINARY
87−
88−
89−instance Binary Source where
90− get = liftM Source get
91− put (Source a) = put a
compiler/src/Canonicalize/Environment/Foreign.hsdeleted−304
@@ -1,304 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns #-}
3−{-# LANGUAGE OverloadedStrings #-}
4−module Canonicalize.Environment.Foreign
5− ( createInitialEnv
6− )
7− where
8−
9−
10−import Control.Monad (foldM)
11−import qualified Data.List as List
12−import qualified Data.Map.Strict as Map
13−import Data.Map.Strict ((!))
14−import qualified Data.Name as Name
15−
16−import qualified AST.Canonical as Can
17−import qualified AST.Source as Src
18−import qualified Canonicalize.Environment as Env
19−import qualified Elm.Interface as I
20−import qualified Elm.ModuleName as ModuleName
21−import qualified Elm.Package as Pkg
22−import qualified Reporting.Annotation as A
23−import qualified Reporting.Error.Canonicalize as Error
24−import qualified Reporting.Result as Result
25−
26−
27−
28−-- RESULT
29−
30−
31−type Result i w a =
32− Result.Result i w Error.Error a
33−
34−
35−createInitialEnv :: ModuleName.Canonical -> Map.Map ModuleName.Raw I.Interface -> [Src.Import] -> Result i w Env.Env
36−createInitialEnv home ifaces imports =
37− do (State vs ts cs bs qvs qts qcs) <- foldM (addImport ifaces) emptyState (toSafeImports home imports)
38− Result.ok (Env.Env home (Map.map infoToVar vs) ts cs bs qvs qts qcs)
39−
40−
41−infoToVar :: Env.Info Can.Annotation -> Env.Var
42−infoToVar info =
43− case info of
44− Env.Specific home tipe -> Env.Foreign home tipe
45− Env.Ambiguous h hs -> Env.Foreigns h hs
46−
47−
48−
49−-- STATE
50−
51−
52−data State =
53− State
54− { _vars :: Env.Exposed Can.Annotation
55− , _types :: Env.Exposed Env.Type
56− , _ctors :: Env.Exposed Env.Ctor
57− , _binops :: Env.Exposed Env.Binop
58− , _q_vars :: Env.Qualified Can.Annotation
59− , _q_types :: Env.Qualified Env.Type
60− , _q_ctors :: Env.Qualified Env.Ctor
61− }
62−
63−
64−emptyState :: State
65−emptyState =
66− State Map.empty emptyTypes Map.empty Map.empty Map.empty Map.empty Map.empty
67−
68−
69−emptyTypes :: Env.Exposed Env.Type
70−emptyTypes =
71− Map.singleton "List" (Env.Specific ModuleName.list (Env.Union 1 ModuleName.list))
72−
73−
74−
75−-- TO SAFE IMPORTS
76−
77−
78−toSafeImports :: ModuleName.Canonical -> [Src.Import] -> [Src.Import]
79−toSafeImports (ModuleName.Canonical pkg _) imports =
80− if Pkg.isKernel pkg
81− then filter isNormal imports
82− else imports
83−
84−
85−isNormal :: Src.Import -> Bool
86−isNormal (Src.Import (A.At _ name) maybeAlias _) =
87− if Name.isKernel name
88− then
89− case maybeAlias of
90− Nothing -> False
91− Just _ -> error "kernel imports cannot use `as`"
92− else
93− True
94−
95−
96−
97−-- ADD IMPORTS
98−
99−
100−addImport :: Map.Map ModuleName.Raw I.Interface -> State -> Src.Import -> Result i w State
101−addImport ifaces (State vs ts cs bs qvs qts qcs) (Src.Import (A.At _ name) maybeAlias exposing) =
102− let
103− (I.Interface pkg defs unions aliases binops) = ifaces ! name
104− !prefix = maybe name id maybeAlias
105− !home = ModuleName.Canonical pkg name
106−
107− !rawTypeInfo =
108− Map.union
109− (Map.mapMaybeWithKey (unionToType home) unions)
110− (Map.mapMaybeWithKey (aliasToType home) aliases)
111−
112− !vars = Map.map (Env.Specific home) defs
113− !types = Map.map (Env.Specific home . fst) rawTypeInfo
114− !ctors = Map.foldr (addExposed . snd) Map.empty rawTypeInfo
115−
116− !qvs2 = addQualified prefix vars qvs
117− !qts2 = addQualified prefix types qts
118− !qcs2 = addQualified prefix ctors qcs
119− in
120− case exposing of
121− Src.Open ->
122− let
123− !vs2 = addExposed vs vars
124− !ts2 = addExposed ts types
125− !cs2 = addExposed cs ctors
126− !bs2 = addExposed bs (Map.mapWithKey (binopToBinop home) binops)
127− in
128− Result.ok (State vs2 ts2 cs2 bs2 qvs2 qts2 qcs2)
129−
130− Src.Explicit exposedList ->
131− foldM
132− (addExposedValue home vars rawTypeInfo binops)
133− (State vs ts cs bs qvs2 qts2 qcs2)
134− exposedList
135−
136−
137−addExposed :: Env.Exposed a -> Env.Exposed a -> Env.Exposed a
138−addExposed =
139− Map.unionWith Env.mergeInfo
140−
141−
142−addQualified :: Name.Name -> Env.Exposed a -> Env.Qualified a -> Env.Qualified a
143−addQualified prefix exposed qualified =
144− Map.insertWith addExposed prefix exposed qualified
145−
146−
147−
148−-- UNION
149−
150−
151−unionToType :: ModuleName.Canonical -> Name.Name -> I.Union -> Maybe (Env.Type, Env.Exposed Env.Ctor)
152−unionToType home name union =
153− unionToTypeHelp home name <$> I.toPublicUnion union
154−
155−
156−unionToTypeHelp :: ModuleName.Canonical -> Name.Name -> Can.Union -> (Env.Type, Env.Exposed Env.Ctor)
157−unionToTypeHelp home name union@(Can.Union vars ctors _ _) =
158− let
159− addCtor dict (Can.Ctor ctor index _ args) =
160− Map.insert ctor (Env.Specific home (Env.Ctor home name union index args)) dict
161− in
162− ( Env.Union (length vars) home
163− , List.foldl' addCtor Map.empty ctors
164− )
165−
166−
167−
168−-- ALIAS
169−
170−
171−aliasToType :: ModuleName.Canonical -> Name.Name -> I.Alias -> Maybe (Env.Type, Env.Exposed Env.Ctor)
172−aliasToType home name alias =
173− aliasToTypeHelp home name <$> I.toPublicAlias alias
174−
175−
176−aliasToTypeHelp :: ModuleName.Canonical -> Name.Name -> Can.Alias -> (Env.Type, Env.Exposed Env.Ctor)
177−aliasToTypeHelp home name (Can.Alias vars tipe) =
178− (
179− Env.Alias (length vars) home vars tipe
180− ,
181− case tipe of
182− Can.TRecord fields Nothing ->
183− let
184− avars = map (\var -> (var, Can.TVar var)) vars
185− alias =
186− foldr
187− (\(_,t1) t2 -> Can.TLambda t1 t2)
188− (Can.TAlias home name avars (Can.Filled tipe))
189− (Can.fieldsToList fields)
190− in
191− Map.singleton name (Env.Specific home (Env.RecordCtor home vars alias))
192−
193− _ ->
194− Map.empty
195− )
196−
197−
198−
199−-- BINOP
200−
201−
202−binopToBinop :: ModuleName.Canonical -> Name.Name -> I.Binop -> Env.Info Env.Binop
203−binopToBinop home op (I.Binop name annotation associativity precedence) =
204− Env.Specific home (Env.Binop op home name annotation associativity precedence)
205−
206−
207−
208−-- ADD EXPOSED VALUE
209−
210−
211−addExposedValue
212− :: ModuleName.Canonical
213− -> Env.Exposed Can.Annotation
214− -> Map.Map Name.Name (Env.Type, Env.Exposed Env.Ctor)
215− -> Map.Map Name.Name I.Binop
216− -> State
217− -> Src.Exposed
218− -> Result i w State
219−addExposedValue home vars types binops (State vs ts cs bs qvs qts qcs) exposed =
220− case exposed of
221− Src.Lower (A.At region name) ->
222− case Map.lookup name vars of
223− Just info ->
224− Result.ok (State (Map.insertWith Env.mergeInfo name info vs) ts cs bs qvs qts qcs)
225−
226− Nothing ->
227− Result.throw (Error.ImportExposingNotFound region home name (Map.keys vars))
228−
229− Src.Upper (A.At region name) privacy ->
230− case privacy of
231− Src.Private ->
232− case Map.lookup name types of
233− Just (tipe, ctors) ->
234− case tipe of
235− Env.Union _ _ ->
236− let
237− !ts2 = Map.insert name (Env.Specific home tipe) ts
238− in
239− Result.ok (State vs ts2 cs bs qvs qts qcs)
240−
241− Env.Alias _ _ _ _ ->
242− let
243− !ts2 = Map.insert name (Env.Specific home tipe) ts
244− !cs2 = addExposed cs ctors
245− in
246− Result.ok (State vs ts2 cs2 bs qvs qts qcs)
247−
248− Nothing ->
249− case checkForCtorMistake name types of
250− tipe:_ ->
251− Result.throw $ Error.ImportCtorByName region name tipe
252−
253− [] ->
254− Result.throw $ Error.ImportExposingNotFound region home name (Map.keys types)
255−
256− Src.Public dotDotRegion ->
257− case Map.lookup name types of
258− Just (tipe, ctors) ->
259− case tipe of
260− Env.Union _ _ ->
261− let
262− !ts2 = Map.insert name (Env.Specific home tipe) ts
263− !cs2 = addExposed cs ctors
264− in
265− Result.ok (State vs ts2 cs2 bs qvs qts qcs)
266−
267− Env.Alias _ _ _ _ ->
268− Result.throw (Error.ImportOpenAlias dotDotRegion name)
269−
270− Nothing ->
271− Result.throw (Error.ImportExposingNotFound region home name (Map.keys types))
272−
273− Src.Operator region op ->
274− case Map.lookup op binops of
275− Just binop ->
276− let
277− !bs2 = Map.insert op (binopToBinop home op binop) bs
278− in
279− Result.ok (State vs ts cs bs2 qvs qts qcs)
280−
281− Nothing ->
282− Result.throw (Error.ImportExposingNotFound region home op (Map.keys binops))
283−
284−
285−checkForCtorMistake :: Name.Name -> Map.Map Name.Name (Env.Type, Env.Exposed Env.Ctor) -> [Name.Name]
286−checkForCtorMistake givenName types =
287− Map.foldr addMatches [] types
288− where
289− addMatches (_, exposedCtors) matches =
290− Map.foldrWithKey addMatch matches exposedCtors
291−
292− addMatch ctorName info matches =
293− if ctorName /= givenName
294− then matches
295− else
296− case info of
297− Env.Specific _ (Env.Ctor _ tipeName _ _ _) ->
298− tipeName : matches
299−
300− Env.Specific _ (Env.RecordCtor _ _ _) ->
301− matches
302−
303− Env.Ambiguous _ _ ->
304− matches
compiler/src/Compile.hsdeleted−92
@@ -1,92 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−module Compile
3− ( Artifacts(..)
4− , compile
5− )
6− where
7−
8−
9−import qualified Data.Map as Map
10−import qualified Data.Name as Name
11−
12−import qualified AST.Source as Src
13−import qualified AST.Canonical as Can
14−import qualified AST.Optimized as Opt
15−import qualified Canonicalize.Module as Canonicalize
16−import qualified Elm.Interface as I
17−import qualified Elm.ModuleName as ModuleName
18−import qualified Elm.Package as Pkg
19−import qualified Nitpick.PatternMatches as PatternMatches
20−import qualified Optimize.Module as Optimize
21−import qualified Reporting.Error as E
22−import qualified Reporting.Result as R
23−import qualified Reporting.Render.Type.Localizer as Localizer
24−import qualified Type.Constrain.Module as Type
25−import qualified Type.Solve as Type
26−
27−import System.IO.Unsafe (unsafePerformIO)
28−
29−
30−
31−-- COMPILE
32−
33−
34−data Artifacts =
35− Artifacts
36− { _modul :: Can.Module
37− , _types :: Map.Map Name.Name Can.Annotation
38− , _graph :: Opt.LocalGraph
39− }
40−
41−
42−compile :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Artifacts
43−compile pkg ifaces modul =
44− do canonical <- canonicalize pkg ifaces modul
45− annotations <- typeCheck modul canonical
46− () <- nitpick canonical
47− objects <- optimize modul annotations canonical
48− return (Artifacts canonical annotations objects)
49−
50−
51−
52−-- PHASES
53−
54−
55−canonicalize :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Can.Module
56−canonicalize pkg ifaces modul =
57− case snd $ R.run $ Canonicalize.canonicalize pkg ifaces modul of
58− Right canonical ->
59− Right canonical
60−
61− Left errors ->
62− Left $ E.BadNames errors
63−
64−
65−typeCheck :: Src.Module -> Can.Module -> Either E.Error (Map.Map Name.Name Can.Annotation)
66−typeCheck modul canonical =
67− case unsafePerformIO (Type.run =<< Type.constrain canonical) of
68− Right annotations ->
69− Right annotations
70−
71− Left errors ->
72− Left (E.BadTypes (Localizer.fromModule modul) errors)
73−
74−
75−nitpick :: Can.Module -> Either E.Error ()
76−nitpick canonical =
77− case PatternMatches.check canonical of
78− Right () ->
79− Right ()
80−
81− Left errors ->
82− Left (E.BadPatterns errors)
83−
84−
85−optimize :: Src.Module -> Map.Map Name.Name Can.Annotation -> Can.Module -> Either E.Error Opt.LocalGraph
86−optimize modul annotations canonical =
87− case snd $ R.run $ Optimize.optimize annotations canonical of
88− Right localGraph ->
89− Right localGraph
90−
91− Left errors ->
92− Left (E.BadMains (Localizer.fromModule modul) errors)
compiler/src/Data/Map/Utils.hsdeleted−43
@@ -1,43 +0,0 @@
1−module Data.Map.Utils
2− ( fromKeys
3− , fromKeysA
4− , fromValues
5− , any
6− )
7− where
8−
9−
10−import Prelude hiding (any)
11−import qualified Data.Map as Map
12−import Data.Map.Internal (Map(..))
13−
14−
15−
16−-- FROM KEYS
17−
18−
19−fromKeys :: (Ord k) => (k -> v) -> [k] -> Map.Map k v
20−fromKeys toValue keys =
21− Map.fromList $ map (\k -> (k, toValue k)) keys
22−
23−
24−fromKeysA :: (Applicative f, Ord k) => (k -> f v) -> [k] -> f (Map.Map k v)
25−fromKeysA toValue keys =
26− Map.fromList <$> traverse (\k -> (,) k <$> toValue k) keys
27−
28−
29−fromValues :: (Ord k) => (v -> k) -> [v] -> Map.Map k v
30−fromValues toKey values =
31− Map.fromList $ map (\v -> (toKey v, v)) values
32−
33−
34−
35−-- ANY
36−
37−
38−{-# INLINE any #-}
39−any :: (v -> Bool) -> Map.Map k v -> Bool
40−any isGood = go
41− where
42− go Tip = False
43− go (Bin _ _ v l r) = isGood v || go l || go r
compiler/src/Data/Name.hsdeleted−610
@@ -1,610 +0,0 @@
1−{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
2−{-# LANGUAGE BangPatterns, EmptyDataDecls, FlexibleInstances, MagicHash, UnboxedTuples #-}
3−module Data.Name
4− ( Name
5− --
6− , toChars
7− , toElmString
8− , toBuilder
9− --
10− , fromPtr
11− , fromChars
12− --
13− , getKernel
14− , hasDot
15− , splitDots
16− , isKernel
17− , isNumberType
18− , isComparableType
19− , isAppendableType
20− , isCompappendType
21− , fromVarIndex
22− , fromWords
23− , fromManyNames
24− , fromTypeVariable
25− , fromTypeVariableScheme
26− , sepBy
27− --
28− , int, float, bool, char, string
29− , maybe, result, list, array, dict, tuple, jsArray
30− , task, router, cmd, sub, platform, virtualDom
31− , shader, debug, debugger, bitwise, basics
32− , utils, negate, true, false, value
33− , node, program, _main, _Main, dollar, identity
34− , replModule, replValueToPrint
35− )
36− where
37−
38−
39−import Prelude hiding (length, maybe, negate)
40−import Control.Exception (assert)
41−import qualified Data.Binary as Binary
42−import qualified Data.ByteString.Builder.Internal as B
43−import qualified Data.Coerce as Coerce
44−import qualified Data.List as List
45−import qualified Data.String as Chars
46−import qualified Data.Utf8 as Utf8
47−import GHC.Exts
48− ( Int(I#), Ptr
49− , MutableByteArray#
50− , isTrue#
51− , newByteArray#
52− , sizeofByteArray#
53− , unsafeFreezeByteArray#
54− )
55−import GHC.ST (ST(ST), runST)
56−import GHC.Prim
57−import GHC.Word (Word8(W8#))
58−
59−import qualified Elm.String as ES
60−
61−
62−
63−-- NAME
64−
65−
66−type Name =
67− Utf8.Utf8 ELM_NAME
68−
69−
70−data ELM_NAME
71−
72−
73−
74−-- INSTANCES
75−
76−
77−instance Chars.IsString (Utf8.Utf8 ELM_NAME) where
78− fromString = Utf8.fromChars
79−
80−instance Binary.Binary (Utf8.Utf8 ELM_NAME) where
81− get = Utf8.getUnder256
82− put = Utf8.putUnder256
83−
84−
85−
86−-- TO
87−
88−
89−toChars :: Name -> [Char]
90−toChars =
91− Utf8.toChars
92−
93−
94−toElmString :: Name -> ES.String
95−toElmString =
96− Coerce.coerce
97−
98−
99−{-# INLINE toBuilder #-}
100−toBuilder :: Name -> B.Builder
101−toBuilder =
102− Utf8.toBuilder
103−
104−
105−
106−-- FROM
107−
108−
109−fromPtr :: Ptr Word8 -> Ptr Word8 -> Name
110−fromPtr =
111− Utf8.fromPtr
112−
113−
114−fromChars :: [Char] -> Name
115−fromChars =
116− Utf8.fromChars
117−
118−
119−
120−-- HAS DOT
121−
122−
123−hasDot :: Name -> Bool
124−hasDot name =
125− Utf8.contains 0x2E {- . -} name
126−
127−
128−splitDots :: Name -> [Name]
129−splitDots name =
130− Utf8.split 0x2E {- . -} name
131−
132−
133−
134−-- GET KERNEL
135−
136−
137−getKernel :: Name -> Name
138−getKernel name@(Utf8.Utf8 ba#) =
139− assert (isKernel name)
140− (
141− runST
142− (
143− let
144− !size# = sizeofByteArray# ba# -# 11#
145− in
146− ST $ \s ->
147− case newByteArray# size# s of
148− (# s, mba# #) ->
149− case copyByteArray# ba# 11# mba# 0# size# s of
150− s ->
151− case unsafeFreezeByteArray# mba# s of
152− (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
153− )
154− )
155−
156−
157−
158−-- STARTS WITH
159−
160−
161−isKernel :: Name -> Bool
162−isKernel = Utf8.startsWith prefix_kernel
163−
164−isNumberType :: Name -> Bool
165−isNumberType = Utf8.startsWith prefix_number
166−
167−isComparableType :: Name -> Bool
168−isComparableType = Utf8.startsWith prefix_comparable
169−
170−isAppendableType :: Name -> Bool
171−isAppendableType = Utf8.startsWith prefix_appendable
172−
173−isCompappendType :: Name -> Bool
174−isCompappendType = Utf8.startsWith prefix_compappend
175−
176−{-# NOINLINE prefix_kernel #-}
177−prefix_kernel :: Name
178−prefix_kernel = fromChars "Elm.Kernel."
179−
180−{-# NOINLINE prefix_number #-}
181−prefix_number :: Name
182−prefix_number = fromChars "number"
183−
184−{-# NOINLINE prefix_comparable #-}
185−prefix_comparable :: Name
186−prefix_comparable = fromChars "comparable"
187−
188−{-# NOINLINE prefix_appendable #-}
189−prefix_appendable :: Name
190−prefix_appendable = fromChars "appendable"
191−
192−{-# NOINLINE prefix_compappend #-}
193−prefix_compappend :: Name
194−prefix_compappend = fromChars "compappend"
195−
196−
197−
198−-- FROM VAR INDEX
199−
200−
201−fromVarIndex :: Int -> Name
202−fromVarIndex n =
203− runST
204− (
205− do let !size = 2 + getIndexSize n
206− mba <- newByteArray size
207− writeWord8 mba 0 0x5F {- _ -}
208− writeWord8 mba 1 0x76 {- v -}
209− writeDigitsAtEnd mba size n
210− freeze mba
211− )
212−
213−
214−{-# INLINE getIndexSize #-}
215−getIndexSize :: Int -> Int
216−getIndexSize n
217− | n < 10 = 1
218− | n < 100 = 2
219− | True = ceiling (logBase 10 (fromIntegral n + 1) :: Float)
220−
221−
222−
223−writeDigitsAtEnd :: MBA s -> Int -> Int -> ST s ()
224−writeDigitsAtEnd !mba !oldOffset !n =
225− do let (q,r) = quotRem n 10
226− let !newOffset = oldOffset - 1
227− writeWord8 mba newOffset (0x30 + fromIntegral r)
228− if q <= 0
229− then return ()
230− else writeDigitsAtEnd mba newOffset q
231−
232−
233−
234−-- FROM TYPE VARIABLE
235−
236−
237−fromTypeVariable :: Name -> Int -> Name
238−fromTypeVariable name@(Utf8.Utf8 ba#) index =
239− if index <= 0 then
240− name
241− else
242− let
243− len# = sizeofByteArray# ba#
244− end# = indexWord8Array# ba# (len# -# 1#)
245− in
246− if isTrue# (leWord# 0x30## end#) && isTrue# (leWord# end# 0x39##) then
247− runST
248− (
249− do let !size = I# len# + 1 + getIndexSize index
250− mba <- newByteArray size
251− copyToMBA name mba
252− writeWord8 mba (I# len#) 0x5F {- _ -}
253− writeDigitsAtEnd mba size index
254− freeze mba
255− )
256− else
257− runST
258− (
259− do let !size = I# len# + getIndexSize index
260− mba <- newByteArray size
261− copyToMBA name mba
262− writeDigitsAtEnd mba size index
263− freeze mba
264− )
265−
266−
267−
268−-- FROM TYPE VARIABLE SCHEME
269−
270−
271−fromTypeVariableScheme :: Int -> Name
272−fromTypeVariableScheme scheme =
273− runST
274− (
275− if scheme < 26 then
276− do mba <- newByteArray 1
277− writeWord8 mba 0 (0x61 + fromIntegral scheme)
278− freeze mba
279− else
280− do let (extra, letter) = quotRem scheme 26
281− let !size = 1 + getIndexSize extra
282− mba <- newByteArray size
283− writeWord8 mba 0 (0x61 + fromIntegral letter)
284− writeDigitsAtEnd mba size extra
285− freeze mba
286− )
287−
288−
289−
290−-- FROM MANY NAMES
291−--
292−-- Creating a unique name by combining all the subnames can create names
293−-- longer than 256 bytes relatively easily. So instead, the first given name
294−-- (e.g. foo) is prefixed chars that are valid in JS but not Elm (e.g. _M$foo)
295−--
296−-- This should be a unique name since 0.19 disallows shadowing. It would not
297−-- be possible for multiple top-level cycles to include values with the same
298−-- name, so the important thing is to make the cycle name distinct from the
299−-- normal name. Same logic for destructuring patterns like (x,y)
300−
301−
302−fromManyNames :: [Name] -> Name
303−fromManyNames names =
304− case names of
305− [] ->
306− blank
307− -- NOTE: this case is needed for (let _ = Debug.log "x" x in ...)
308− -- but maybe unused patterns should be stripped out instead
309−
310− Utf8.Utf8 ba# : _ ->
311− let
312− len# = sizeofByteArray# ba#
313− in
314− runST
315− (
316− ST $ \s ->
317− case newByteArray# (len# +# 3#) s of
318− (# s, mba# #) ->
319− case writeWord8Array# mba# 0# 0x5F## {-_-} s of
320− s ->
321− case writeWord8Array# mba# 1# 0x4D## {-M-} s of
322− s ->
323− case writeWord8Array# mba# 2# 0x24## {-$-} s of
324− s ->
325− case copyByteArray# ba# 0# mba# 3# len# s of
326− s ->
327− case unsafeFreezeByteArray# mba# s of
328− (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
329− )
330−
331−
332−{-# NOINLINE blank #-}
333−blank :: Name
334−blank =
335− fromWords [0x5F,0x4D,0x24] {-_M$-}
336−
337−
338−
339−-- FROM WORDS
340−
341−
342−fromWords :: [Word8] -> Name
343−fromWords words =
344− runST
345− (
346− do mba <- newByteArray (List.length words)
347− writeWords mba 0 words
348− freeze mba
349− )
350−
351−
352−writeWords :: MBA s -> Int -> [Word8] -> ST s ()
353−writeWords !mba !i words =
354− case words of
355− [] ->
356− return ()
357−
358− w:ws ->
359− do writeWord8 mba i w
360− writeWords mba (i+1) ws
361−
362−
363−
364−-- SEP BY
365−
366−
367−sepBy :: Word8 -> Name -> Name -> Name
368−sepBy (W8# sep#) (Utf8.Utf8 ba1#) (Utf8.Utf8 ba2#) =
369− let
370− !len1# = sizeofByteArray# ba1#
371− !len2# = sizeofByteArray# ba2#
372− in
373− runST
374− (
375− ST $ \s ->
376− case newByteArray# (len1# +# len2# +# 1#) s of
377− (# s, mba# #) ->
378− case copyByteArray# ba1# 0# mba# 0# len1# s of
379− s ->
380− case writeWord8Array# mba# len1# sep# s of
381− s ->
382− case copyByteArray# ba2# 0# mba# (len1# +# 1#) len2# s of
383− s ->
384− case unsafeFreezeByteArray# mba# s of
385− (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
386− )
387−
388−
389−
390−-- PRIMITIVES
391−
392−
393−data MBA s =
394− MBA# (MutableByteArray# s)
395−
396−
397−{-# INLINE newByteArray #-}
398−newByteArray :: Int -> ST s (MBA s)
399−newByteArray (I# len#) =
400− ST $ \s ->
401− case newByteArray# len# s of
402− (# s, mba# #) -> (# s, MBA# mba# #)
403−
404−
405−{-# INLINE freeze #-}
406−freeze :: MBA s -> ST s Name
407−freeze (MBA# mba#) =
408− ST $ \s ->
409− case unsafeFreezeByteArray# mba# s of
410− (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
411−
412−
413−{-# INLINE writeWord8 #-}
414−writeWord8 :: MBA s -> Int -> Word8 -> ST s ()
415−writeWord8 (MBA# mba#) (I# offset#) (W8# w#) =
416− ST $ \s ->
417− case writeWord8Array# mba# offset# w# s of
418− s -> (# s, () #)
419−
420−
421−{-# INLINE copyToMBA #-}
422−copyToMBA :: Name -> MBA s -> ST s ()
423−copyToMBA (Utf8.Utf8 ba#) (MBA# mba#) =
424− ST $ \s ->
425− case copyByteArray# ba# 0# mba# 0# (sizeofByteArray# ba#) s of
426− s -> (# s, () #)
427−
428−
429−
430−-- COMMON NAMES
431−
432−
433−{-# NOINLINE int #-}
434−int :: Name
435−int = fromChars "Int"
436−
437−
438−{-# NOINLINE float #-}
439−float :: Name
440−float = fromChars "Float"
441−
442−
443−{-# NOINLINE bool #-}
444−bool :: Name
445−bool = fromChars "Bool"
446−
447−
448−{-# NOINLINE char #-}
449−char :: Name
450−char = fromChars "Char"
451−
452−
453−{-# NOINLINE string #-}
454−string :: Name
455−string = fromChars "String"
456−
457−
458−{-# NOINLINE maybe #-}
459−maybe :: Name
460−maybe = fromChars "Maybe"
461−
462−
463−{-# NOINLINE result #-}
464−result :: Name
465−result = fromChars "Result"
466−
467−
468−{-# NOINLINE list #-}
469−list :: Name
470−list = fromChars "List"
471−
472−
473−{-# NOINLINE array #-}
474−array :: Name
475−array = fromChars "Array"
476−
477−
478−{-# NOINLINE dict #-}
479−dict :: Name
480−dict = fromChars "Dict"
481−
482−
483−{-# NOINLINE tuple #-}
484−tuple :: Name
485−tuple = fromChars "Tuple"
486−
487−
488−{-# NOINLINE jsArray #-}
489−jsArray :: Name
490−jsArray = fromChars "JsArray"
491−
492−
493−{-# NOINLINE task #-}
494−task :: Name
495−task = fromChars "Task"
496−
497−
498−{-# NOINLINE router #-}
499−router :: Name
500−router = fromChars "Router"
501−
502−
503−{-# NOINLINE cmd #-}
504−cmd :: Name
505−cmd = fromChars "Cmd"
506−
507−
508−{-# NOINLINE sub #-}
509−sub :: Name
510−sub = fromChars "Sub"
511−
512−
513−{-# NOINLINE platform #-}
514−platform :: Name
515−platform = fromChars "Platform"
516−
517−
518−{-# NOINLINE virtualDom #-}
519−virtualDom :: Name
520−virtualDom = fromChars "VirtualDom"
521−
522−
523−{-# NOINLINE shader #-}
524−shader :: Name
525−shader = fromChars "Shader"
526−
527−
528−{-# NOINLINE debug #-}
529−debug :: Name
530−debug = fromChars "Debug"
531−
532−
533−{-# NOINLINE debugger #-}
534−debugger :: Name
535−debugger = fromChars "Debugger"
536−
537−
538−{-# NOINLINE bitwise #-}
539−bitwise :: Name
540−bitwise = fromChars "Bitwise"
541−
542−
543−{-# NOINLINE basics #-}
544−basics :: Name
545−basics = fromChars "Basics"
546−
547−
548−{-# NOINLINE utils #-}
549−utils :: Name
550−utils = fromChars "Utils"
551−
552−
553−{-# NOINLINE negate #-}
554−negate :: Name
555−negate = fromChars "negate"
556−
557−
558−{-# NOINLINE true #-}
559−true :: Name
560−true = fromChars "True"
561−
562−
563−{-# NOINLINE false #-}
564−false :: Name
565−false = fromChars "False"
566−
567−
568−{-# NOINLINE value #-}
569−value :: Name
570−value = fromChars "Value"
571−
572−
573−{-# NOINLINE node #-}
574−node :: Name
575−node = fromChars "Node"
576−
577−
578−{-# NOINLINE program #-}
579−program :: Name
580−program = fromChars "Program"
581−
582−
583−{-# NOINLINE _main #-}
584−_main :: Name
585−_main = fromChars "main"
586−
587−
588−{-# NOINLINE _Main #-}
589−_Main :: Name
590−_Main = fromChars "Main"
591−
592−
593−{-# NOINLINE dollar #-}
594−dollar :: Name
595−dollar = fromChars "$"
596−
597−
598−{-# NOINLINE identity #-}
599−identity :: Name
600−identity = fromChars "identity"
601−
602−
603−{-# NOINLINE replModule #-}
604−replModule :: Name
605−replModule = fromChars "Elm_Repl"
606−
607−
608−{-# NOINLINE replValueToPrint #-}
609−replValueToPrint :: Name
610−replValueToPrint = fromChars "repl_input_value_"
compiler/src/Data/NonEmptyList.hsdeleted−78
@@ -1,78 +0,0 @@
1−module Data.NonEmptyList
2− ( List(..)
3− , singleton
4− , toList
5− , sortBy
6− )
7− where
8−
9−
10−import Control.Monad (liftM2)
11−import Data.Binary (Binary, get, put)
12−import qualified Data.List as List
13−
14−
15−
16−-- LIST
17−
18−
19−data List a =
20− List a [a]
21−
22−
23−singleton :: a -> List a
24−singleton a =
25− List a []
26−
27−
28−toList :: List a -> [a]
29−toList (List x xs) =
30− x:xs
31−
32−
33−
34−-- INSTANCES
35−
36−
37−instance Functor List where
38− fmap func (List x xs) = List (func x) (map func xs)
39−
40−
41−instance Traversable List where
42− traverse func (List x xs) = List <$> func x <*> traverse func xs
43−
44−
45−instance Foldable List where
46− foldr step state (List x xs) = step x (foldr step state xs)
47− foldl step state (List x xs) = foldl step (step state x) xs
48− foldl1 step (List x xs) = foldl step x xs
49−
50−
51−
52−-- SORT BY
53−
54−
55−sortBy :: (Ord b) => (a -> b) -> List a -> List a
56−sortBy toRank (List x xs) =
57− let
58− comparison a b =
59− compare (toRank a) (toRank b)
60− in
61− case List.sortBy comparison xs of
62− [] ->
63− List x []
64−
65− y:ys ->
66− case comparison x y of
67− LT -> List x (y:ys)
68− EQ -> List x (y:ys)
69− GT -> List y (List.insertBy comparison x ys)
70−
71−
72−
73−-- BINARY
74−
75−
76−instance (Binary a) => Binary (List a) where
77− put (List x xs) = put x >> put xs
78− get = liftM2 List get get
compiler/src/Data/OneOrMore.hsdeleted−99
@@ -1,99 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Data.OneOrMore
3− ( OneOrMore(..)
4− , one
5− , more
6− , map
7− , destruct
8− , getFirstTwo
9− )
10− where
11−
12−
13−import Prelude hiding (map)
14−
15−
16−
17−-- ONE OR MORE
18−
19−
20−data OneOrMore a
21− = One a
22− | More (OneOrMore a) (OneOrMore a)
23−
24−
25−one :: a -> OneOrMore a
26−one =
27− One
28−
29−
30−more :: OneOrMore a -> OneOrMore a -> OneOrMore a
31−more =
32− More
33−
34−
35−
36−-- MAP
37−
38−
39−map :: (a -> b) -> OneOrMore a -> OneOrMore b
40−map func oneOrMore =
41− case oneOrMore of
42− One value ->
43− One (func value)
44−
45− More left right ->
46− More (map func left) (map func right)
47−
48−
49−
50−-- DESTRUCT
51−
52−
53−destruct :: (a -> [a] -> b) -> OneOrMore a -> b
54−destruct func oneOrMore =
55− destructLeft func oneOrMore []
56−
57−
58−destructLeft :: (a -> [a] -> b) -> OneOrMore a -> [a] -> b
59−destructLeft func oneOrMore xs =
60− case oneOrMore of
61− One x ->
62− func x xs
63−
64− More a b ->
65− destructLeft func a (destructRight b xs)
66−
67−
68−destructRight :: OneOrMore a -> [a] -> [a]
69−destructRight oneOrMore xs =
70− case oneOrMore of
71− One x ->
72− x : xs
73−
74− More a b ->
75− destructRight a (destructRight b xs)
76−
77−
78−
79−-- GET FIRST TWO
80−
81−
82−getFirstTwo :: OneOrMore a -> OneOrMore a -> (a,a)
83−getFirstTwo left right =
84− case left of
85− One x ->
86− (x, getFirstOne right)
87−
88− More lleft lright ->
89− getFirstTwo lleft lright
90−
91−
92−getFirstOne :: OneOrMore a -> a
93−getFirstOne oneOrMore =
94− case oneOrMore of
95− One x ->
96− x
97−
98− More left _ ->
99− getFirstOne left
compiler/src/Data/Utf8.hsdeleted−618
@@ -1,618 +0,0 @@
1−{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
2−{-# LANGUAGE BangPatterns, FlexibleInstances, MagicHash, UnboxedTuples #-}
3−module Data.Utf8
4− ( Utf8(..)
5− , isEmpty
6− , empty
7− , size
8− , contains
9− , startsWith
10− , startsWithChar
11− , endsWithWord8
12− , split
13− , join
14− --
15− , getUnder256
16− , putUnder256
17− --
18− , getVeryLong
19− , putVeryLong
20− --
21− , toChars
22− , toBuilder
23− , toEscapedBuilder
24− --
25− , fromPtr
26− , fromSnippet
27− , fromChars
28− --
29− , MBA
30− , newByteArray
31− , copyFromPtr
32− , writeWord8
33− , freeze
34− )
35− where
36−
37−
38−import Prelude hiding (String, all, any, concat)
39−import Data.Binary (Get, get, getWord8, Put, put, putWord8)
40−import Data.Binary.Put (putBuilder)
41−import Data.Binary.Get.Internal (readN)
42−import Data.Bits ((.&.), shiftR)
43−import qualified Data.ByteString.Internal as B
44−import qualified Data.ByteString.Builder.Internal as B
45−import qualified Data.Char as Char
46−import qualified Data.List as List
47−import Foreign.ForeignPtr (touchForeignPtr)
48−import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
49−import Foreign.Ptr (minusPtr, plusPtr)
50−import GHC.Exts
51− ( Int(I#), Ptr(Ptr), Char(C#)
52− , RealWorld
53− , ByteArray#, MutableByteArray#
54− , isTrue#
55− , newByteArray#
56− , unsafeFreezeByteArray#
57− , sizeofByteArray#
58− , copyByteArray#
59− , copyAddrToByteArray#
60− , copyByteArrayToAddr#
61− , writeWord8Array#
62− )
63−import GHC.IO
64−import GHC.ST (ST(ST), runST)
65−import GHC.Prim
66−import GHC.Word (Word8(W8#))
67−
68−import qualified Parse.Primitives as P
69−
70−
71−
72−-- UTF-8
73−
74−
75−data Utf8 tipe =
76− Utf8 ByteArray#
77−
78−
79−
80−-- EMPTY
81−
82−
83−{-# NOINLINE empty #-}
84−empty :: Utf8 t
85−empty =
86− runST (freeze =<< newByteArray 0)
87−
88−
89−isEmpty :: Utf8 t -> Bool
90−isEmpty (Utf8 ba#) =
91− isTrue# (sizeofByteArray# ba# ==# 0#)
92−
93−
94−
95−-- SIZE
96−
97−
98−size :: Utf8 t -> Int
99−size (Utf8 ba#) =
100− I# (sizeofByteArray# ba#)
101−
102−
103−
104−-- CONTAINS
105−
106−
107−contains :: Word8 -> Utf8 t -> Bool
108−contains (W8# word#) (Utf8 ba#) =
109− containsHelp word# ba# 0# (sizeofByteArray# ba#)
110−
111−
112−containsHelp :: Word# -> ByteArray# -> Int# -> Int# -> Bool
113−containsHelp word# ba# !offset# len# =
114− if isTrue# (offset# <# len#) then
115− if isTrue# (eqWord# word# (indexWord8Array# ba# offset#))
116− then True
117− else containsHelp word# ba# (offset# +# 1#) len#
118− else
119− False
120−
121−
122−
123−-- STARTS WITH
124−
125−
126−{-# INLINE startsWith #-}
127−startsWith :: Utf8 t -> Utf8 t -> Bool
128−startsWith (Utf8 ba1#) (Utf8 ba2#) =
129− let
130− !len1# = sizeofByteArray# ba1#
131− !len2# = sizeofByteArray# ba2#
132− in
133− isTrue# (len1# <=# len2#)
134− &&
135− isTrue# (0# ==# compareByteArrays# ba1# 0# ba2# 0# len1#)
136−
137−
138−
139−-- STARTS WITH CHAR
140−
141−
142−startsWithChar :: (Char -> Bool) -> Utf8 t -> Bool
143−startsWithChar isGood bytes@(Utf8 ba#) =
144− if isEmpty bytes then
145− False
146− else
147− let
148− !w# = indexWord8Array# ba# 0#
149− !char
150− | isTrue# (ltWord# w# 0xC0##) = C# (chr# (word2Int# w#))
151− | isTrue# (ltWord# w# 0xE0##) = chr2 ba# 0# w#
152− | isTrue# (ltWord# w# 0xF0##) = chr3 ba# 0# w#
153− | True = chr4 ba# 0# w#
154− in
155− isGood char
156−
157−
158−
159−-- ENDS WITH WORD
160−
161−
162−endsWithWord8 :: Word8 -> Utf8 t -> Bool
163−endsWithWord8 (W8# w#) (Utf8 ba#) =
164− let len# = sizeofByteArray# ba# in
165− isTrue# (len# ># 0#)
166− &&
167− isTrue# (eqWord# w# (indexWord8Array# ba# (len# -# 1#)))
168−
169−
170−
171−-- SPLIT
172−
173−
174−split :: Word8 -> Utf8 t -> [Utf8 t]
175−split (W8# divider#) str@(Utf8 ba#) =
176− splitHelp str 0 (findDividers divider# ba# 0# (sizeofByteArray# ba#) [])
177−
178−
179−splitHelp :: Utf8 t -> Int -> [Int] -> [Utf8 t]
180−splitHelp str start offsets =
181− case offsets of
182− [] ->
183− [ unsafeSlice str start (size str) ]
184−
185− offset : offsets ->
186− unsafeSlice str start offset : splitHelp str (offset + 1) offsets
187−
188−
189−findDividers :: Word# -> ByteArray# -> Int# -> Int# -> [Int] -> [Int]
190−findDividers divider# ba# !offset# len# revOffsets =
191− if isTrue# (offset# <# len#) then
192− findDividers divider# ba# (offset# +# 1#) len# $
193− if isTrue# (eqWord# divider# (indexWord8Array# ba# offset#))
194− then I# offset# : revOffsets
195− else revOffsets
196− else
197− reverse revOffsets
198−
199−
200−unsafeSlice :: Utf8 t -> Int -> Int -> Utf8 t
201−unsafeSlice str start end =
202− let !len = end - start in
203− if len == 0 then
204− empty
205− else
206− runST $
207− do mba <- newByteArray len
208− copy str start mba 0 len
209− freeze mba
210−
211−
212−
213−-- JOIN
214−
215−
216−join :: Word8 -> [Utf8 t] -> Utf8 t
217−join sep strings =
218− case strings of
219− [] ->
220− empty
221−
222− str:strs ->
223− runST $
224− do let !len = List.foldl' (\w s -> w + 1 + size s) (size str) strs
225− mba <- newByteArray len
226− joinHelp sep mba 0 str strs
227− freeze mba
228−
229−
230−joinHelp :: Word8 -> MBA s -> Int -> Utf8 t -> [Utf8 t] -> ST s ()
231−joinHelp sep mba offset str strings =
232− let
233− !len = size str
234− in
235− case strings of
236− [] ->
237− copy str 0 mba offset len
238−
239− s:ss ->
240− do copy str 0 mba offset len
241− let !dotOffset = offset + len
242− writeWord8 mba dotOffset sep
243− let !newOffset = dotOffset + 1
244− joinHelp sep mba newOffset s ss
245−
246−
247−
248−-- EQUAL
249−
250−
251−instance Eq (Utf8 t) where
252− (==) (Utf8 ba1#) (Utf8 ba2#) =
253− let
254− !len1# = sizeofByteArray# ba1#
255− !len2# = sizeofByteArray# ba2#
256− in
257− isTrue# (len1# ==# len2#)
258− &&
259− isTrue# (0# ==# compareByteArrays# ba1# 0# ba2# 0# len1#)
260−
261−
262−
263−-- COMPARE
264−--
265−-- TODO: is it fine to sort by length and only compare bytes on length ties?
266−--
267−
268−instance Ord (Utf8 t) where
269− compare (Utf8 ba1#) (Utf8 ba2#) =
270− let
271− !len1# = sizeofByteArray# ba1#
272− !len2# = sizeofByteArray# ba2#
273− !len# = if isTrue# (len1# <# len2#) then len1# else len2#
274− !cmp# = compareByteArrays# ba1# 0# ba2# 0# len#
275− in
276− case () of
277− _ | isTrue# (cmp# <# 0#) -> LT
278− | isTrue# (cmp# ># 0#) -> GT
279− | isTrue# (len1# <# len2#) -> LT
280− | isTrue# (len1# ># len2#) -> GT
281− | True -> EQ
282−
283−
284−
285−-- FROM STRING
286−
287−
288−fromChars :: [Char] -> Utf8 t
289−fromChars chars =
290− runST
291− (
292− do mba <- newByteArray (sum (map getWidth chars))
293− writeChars mba 0 chars
294− )
295−
296−
297−writeChars :: MBA s -> Int -> [Char] -> ST s (Utf8 t)
298−writeChars !mba !offset chars =
299− case chars of
300− [] ->
301− freeze mba
302−
303− char : chars
304− | n < 0x80 ->
305− do writeWord8 mba (offset ) (fromIntegral n)
306− writeChars mba (offset + 1) chars
307−
308− | n < 0x800 ->
309− do writeWord8 mba (offset ) (fromIntegral ((shiftR n 6 ) + 0xC0))
310− writeWord8 mba (offset + 1) (fromIntegral (( n .&. 0x3F) + 0x80))
311− writeChars mba (offset + 2) chars
312−
313− | n < 0x10000 ->
314− do writeWord8 mba (offset ) (fromIntegral ((shiftR n 12 ) + 0xE0))
315− writeWord8 mba (offset + 1) (fromIntegral ((shiftR n 6 .&. 0x3F) + 0x80))
316− writeWord8 mba (offset + 2) (fromIntegral (( n .&. 0x3F) + 0x80))
317− writeChars mba (offset + 3) chars
318−
319− | otherwise ->
320− do writeWord8 mba (offset ) (fromIntegral ((shiftR n 18 ) + 0xF0))
321− writeWord8 mba (offset + 1) (fromIntegral ((shiftR n 12 .&. 0x3F) + 0x80))
322− writeWord8 mba (offset + 2) (fromIntegral ((shiftR n 6 .&. 0x3F) + 0x80))
323− writeWord8 mba (offset + 3) (fromIntegral (( n .&. 0x3F) + 0x80))
324− writeChars mba (offset + 4) chars
325−
326− where
327− n = Char.ord char
328−
329−
330−{-# INLINE getWidth #-}
331−getWidth :: Char -> Int
332−getWidth char
333− | code < 0x80 = 1
334− | code < 0x800 = 2
335− | code < 0x10000 = 3
336− | otherwise = 4
337− where
338− code = Char.ord char
339−
340−
341−
342−-- TO CHARS
343−
344−
345−toChars :: Utf8 t -> [Char]
346−toChars (Utf8 ba#) =
347− toCharsHelp ba# 0# (sizeofByteArray# ba#)
348−
349−
350−toCharsHelp :: ByteArray# -> Int# -> Int# -> [Char]
351−toCharsHelp ba# offset# len# =
352− if isTrue# (offset# >=# len#) then
353− []
354− else
355− let
356− !w# = indexWord8Array# ba# offset#
357− !(# char, width# #)
358− | isTrue# (ltWord# w# 0xC0##) = (# C# (chr# (word2Int# w#)), 1# #)
359− | isTrue# (ltWord# w# 0xE0##) = (# chr2 ba# offset# w#, 2# #)
360− | isTrue# (ltWord# w# 0xF0##) = (# chr3 ba# offset# w#, 3# #)
361− | True = (# chr4 ba# offset# w#, 4# #)
362−
363− !newOffset# = offset# +# width#
364− in
365− char : toCharsHelp ba# newOffset# len#
366−
367−
368−{-# INLINE chr2 #-}
369−chr2 :: ByteArray# -> Int# -> Word# -> Char
370−chr2 ba# offset# firstWord# =
371− let
372− !i1# = word2Int# firstWord#
373− !i2# = word2Int# (indexWord8Array# ba# (offset# +# 1#))
374− !c1# = uncheckedIShiftL# (i1# -# 0xC0#) 6#
375− !c2# = i2# -# 0x80#
376− in
377− C# (chr# (c1# +# c2#))
378−
379−
380−{-# INLINE chr3 #-}
381−chr3 :: ByteArray# -> Int# -> Word# -> Char
382−chr3 ba# offset# firstWord# =
383− let
384− !i1# = word2Int# firstWord#
385− !i2# = word2Int# (indexWord8Array# ba# (offset# +# 1#))
386− !i3# = word2Int# (indexWord8Array# ba# (offset# +# 2#))
387− !c1# = uncheckedIShiftL# (i1# -# 0xE0#) 12#
388− !c2# = uncheckedIShiftL# (i2# -# 0x80#) 6#
389− !c3# = i3# -# 0x80#
390− in
391− C# (chr# (c1# +# c2# +# c3#))
392−
393−
394−{-# INLINE chr4 #-}
395−chr4 :: ByteArray# -> Int# -> Word# -> Char
396−chr4 ba# offset# firstWord# =
397− let
398− !i1# = word2Int# firstWord#
399− !i2# = word2Int# (indexWord8Array# ba# (offset# +# 1#))
400− !i3# = word2Int# (indexWord8Array# ba# (offset# +# 2#))
401− !i4# = word2Int# (indexWord8Array# ba# (offset# +# 3#))
402− !c1# = uncheckedIShiftL# (i1# -# 0xF0#) 18#
403− !c2# = uncheckedIShiftL# (i2# -# 0x80#) 12#
404− !c3# = uncheckedIShiftL# (i3# -# 0x80#) 6#
405− !c4# = i4# -# 0x80#
406− in
407− C# (chr# (c1# +# c2# +# c3# +# c4#))
408−
409−
410−
411−-- TO BUILDER
412−
413−
414−{-# INLINE toBuilder #-}
415−toBuilder :: Utf8 t -> B.Builder
416−toBuilder =
417− \bytes -> B.builder (toBuilderHelp bytes)
418−
419−
420−{-# INLINE toBuilderHelp #-}
421−toBuilderHelp :: Utf8 t -> B.BuildStep a -> B.BuildStep a
422−toBuilderHelp !bytes@(Utf8 ba#) k =
423− go 0 (I# (sizeofByteArray# ba#))
424− where
425− go !offset !end !(B.BufferRange bOffset bEnd) =
426− let
427− !bLen = minusPtr bEnd bOffset
428− !len = end - offset
429− in
430− if len <= bLen then
431− do copyToPtr bytes offset bOffset len
432− let !br' = B.BufferRange (plusPtr bOffset len) bEnd
433− k br'
434− else
435− do copyToPtr bytes offset bOffset bLen
436− let !offset' = offset + bLen
437− return $ B.bufferFull 1 bEnd (go offset' end)
438−
439−
440−
441−-- TO ESCAPED BUILDER
442−
443−
444−{-# INLINE toEscapedBuilder #-}
445−toEscapedBuilder :: Word8 -> Word8 -> Utf8 t -> B.Builder
446−toEscapedBuilder before after =
447− \name -> B.builder (toEscapedBuilderHelp before after name)
448−
449−
450−{-# INLINE toEscapedBuilderHelp #-}
451−toEscapedBuilderHelp :: Word8 -> Word8 -> Utf8 t -> B.BuildStep a -> B.BuildStep a
452−toEscapedBuilderHelp before after !name@(Utf8 ba#) k =
453− go 0 (I# (sizeofByteArray# ba#))
454− where
455− go !offset !len !(B.BufferRange bOffset bEnd) =
456− let
457− !bLen = minusPtr bEnd bOffset
458− in
459− if len <= bLen then
460− do -- PERF test if writing word-by-word is faster
461− copyToPtr name offset bOffset len
462− escape before after bOffset name offset len 0
463− let !newBufferRange = B.BufferRange (plusPtr bOffset len) bEnd
464− k newBufferRange
465− else
466− do copyToPtr name offset bOffset bLen
467− escape before after bOffset name offset bLen 0
468− let !newOffset = offset + bLen
469− let !newLength = len - bLen
470− return $ B.bufferFull 1 bEnd (go newOffset newLength)
471−
472−
473−escape :: Word8 -> Word8 -> Ptr a -> Utf8 t -> Int -> Int -> Int -> IO ()
474−escape before@(W8# before#) after ptr name@(Utf8 ba#) offset@(I# offset#) len@(I# len#) i@(I# i#) =
475− if isTrue# (i# <# len#) then
476− if isTrue# (eqWord# before# (indexWord8Array# ba# (offset# +# i#)))
477− then
478− do writeWordToPtr ptr i after
479− escape before after ptr name offset len (i + 1)
480− else
481− do escape before after ptr name offset len (i + 1)
482−
483− else
484− return ()
485−
486−
487−
488−-- FROM PTR
489−
490−
491−fromPtr :: Ptr Word8 -> Ptr Word8 -> Utf8 t
492−fromPtr pos end =
493− unsafeDupablePerformIO (stToIO (
494− do let !len = minusPtr end pos
495− mba <- newByteArray len
496− copyFromPtr pos mba 0 len
497− freeze mba
498− ))
499−
500−
501−
502−-- FROM SNIPPET
503−
504−
505−fromSnippet :: P.Snippet -> Utf8 t
506−fromSnippet (P.Snippet fptr off len _ _) =
507− unsafeDupablePerformIO (stToIO (
508− do mba <- newByteArray len
509− let !pos = plusPtr (unsafeForeignPtrToPtr fptr) off
510− copyFromPtr pos mba 0 len
511− freeze mba
512− ))
513−
514−
515−
516−-- BINARY
517−
518−
519−putUnder256 :: Utf8 t -> Put
520−putUnder256 bytes =
521− do putWord8 (fromIntegral (size bytes))
522− putBuilder (toBuilder bytes)
523−
524−
525−getUnder256 :: Get (Utf8 t)
526−getUnder256 =
527− do word <- getWord8
528− let !n = fromIntegral word
529− readN n (copyFromByteString n)
530−
531−
532−putVeryLong :: Utf8 t -> Put
533−putVeryLong bytes =
534− do put (size bytes)
535− putBuilder (toBuilder bytes)
536−
537−
538−getVeryLong :: Get (Utf8 t)
539−getVeryLong =
540− do n <- get
541− if n > 0
542− then readN n (copyFromByteString n)
543− else return empty
544−
545−
546−
547−-- COPY FROM BYTESTRING
548−
549−
550−{-# INLINE copyFromByteString #-}
551−copyFromByteString :: Int -> B.ByteString -> Utf8 t
552−copyFromByteString len (B.PS fptr offset _) =
553− unsafeDupablePerformIO
554− (
555− do mba <- stToIO (newByteArray len)
556− stToIO (copyFromPtr (unsafeForeignPtrToPtr fptr `plusPtr` offset) mba 0 len)
557− touchForeignPtr fptr
558− stToIO (freeze mba)
559− )
560−
561−
562−
563−-- PRIMITIVES
564−
565−
566−data MBA s =
567− MBA# (MutableByteArray# s)
568−
569−
570−newByteArray :: Int -> ST s (MBA s) -- PERF see if newPinnedByteArray for len > 256 is positive
571−newByteArray (I# len#) =
572− ST $ \s ->
573− case newByteArray# len# s of
574− (# s, mba# #) -> (# s, MBA# mba# #)
575−
576−
577−freeze :: MBA s -> ST s (Utf8 t)
578−freeze (MBA# mba#) =
579− ST $ \s ->
580− case unsafeFreezeByteArray# mba# s of
581− (# s, ba# #) -> (# s, Utf8 ba# #)
582−
583−
584−copy :: Utf8 t -> Int -> MBA s -> Int -> Int -> ST s ()
585−copy (Utf8 ba#) (I# offset#) (MBA# mba#) (I# i#) (I# len#) =
586− ST $ \s ->
587− case copyByteArray# ba# offset# mba# i# len# s of
588− s -> (# s, () #)
589−
590−
591−copyFromPtr :: Ptr a -> MBA RealWorld -> Int -> Int -> ST RealWorld ()
592−copyFromPtr (Ptr src#) (MBA# mba#) (I# offset#) (I# len#) =
593− ST $ \s ->
594− case copyAddrToByteArray# src# mba# offset# len# s of
595− s -> (# s, () #)
596−
597−
598−copyToPtr :: Utf8 t -> Int -> Ptr a -> Int -> IO ()
599−copyToPtr (Utf8 ba#) (I# offset#) (Ptr mba#) (I# len#) =
600− IO $ \s ->
601− case copyByteArrayToAddr# ba# offset# mba# len# s of
602− s -> (# s, () #)
603−
604−
605−{-# INLINE writeWord8 #-}
606−writeWord8 :: MBA s -> Int -> Word8 -> ST s ()
607−writeWord8 (MBA# mba#) (I# offset#) (W8# w#) =
608− ST $ \s ->
609− case writeWord8Array# mba# offset# w# s of
610− s -> (# s, () #)
611−
612−
613−{-# INLINE writeWordToPtr #-}
614−writeWordToPtr :: Ptr a -> Int -> Word8 -> IO ()
615−writeWordToPtr (Ptr addr#) (I# offset#) (W8# word#) =
616− IO $ \s ->
617− case writeWord8OffAddr# addr# offset# word# s of
618− s -> (# s, () #)
compiler/src/Elm/Compiler/Imports.hsdeleted−62
@@ -1,62 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Elm.Compiler.Imports
4− ( defaults
5− )
6− where
7−
8−
9−import qualified Data.Name as Name
10−
11−import qualified AST.Source as Src
12−import qualified Elm.ModuleName as ModuleName
13−import qualified Reporting.Annotation as A
14−
15−
16−
17−-- DEFAULTS
18−
19−
20−defaults :: [Src.Import]
21−defaults =
22− [ import_ ModuleName.basics Nothing Src.Open
23− , import_ ModuleName.debug Nothing closed
24− , import_ ModuleName.list Nothing (operator "::")
25− , import_ ModuleName.maybe Nothing (typeOpen Name.maybe)
26− , import_ ModuleName.result Nothing (typeOpen Name.result)
27− , import_ ModuleName.string Nothing (typeClosed Name.string)
28− , import_ ModuleName.char Nothing (typeClosed Name.char)
29− , import_ ModuleName.tuple Nothing closed
30− , import_ ModuleName.platform Nothing (typeClosed Name.program)
31− , import_ ModuleName.cmd (Just Name.cmd) (typeClosed Name.cmd)
32− , import_ ModuleName.sub (Just Name.sub) (typeClosed Name.sub)
33− ]
34−
35−
36−import_ :: ModuleName.Canonical -> Maybe Name.Name -> Src.Exposing -> Src.Import
37−import_ (ModuleName.Canonical _ name) maybeAlias exposing =
38− Src.Import (A.At A.zero name) maybeAlias exposing
39−
40−
41−
42−-- EXPOSING
43−
44−
45−closed :: Src.Exposing
46−closed =
47− Src.Explicit []
48−
49−
50−typeOpen :: Name.Name -> Src.Exposing
51−typeOpen name =
52− Src.Explicit [ Src.Upper (A.At A.zero name) (Src.Public A.zero) ]
53−
54−
55−typeClosed :: Name.Name -> Src.Exposing
56−typeClosed name =
57− Src.Explicit [ Src.Upper (A.At A.zero name) Src.Private ]
58−
59−
60−operator :: Name.Name -> Src.Exposing
61−operator op =
62− Src.Explicit [ Src.Operator A.zero op ]
compiler/src/Elm/Compiler/Type.hsdeleted−194
@@ -1,194 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Elm.Compiler.Type
4− ( Type(..)
5− , RT.Context(..)
6− , toDoc
7− , DebugMetadata(..)
8− , Alias(..)
9− , Union(..)
10− , encode
11− , decoder
12− , encodeMetadata
13− )
14− where
15−
16−
17−import qualified Data.Name as Name
18−
19−import qualified AST.Source as Src
20−import qualified Json.Decode as D
21−import qualified Json.Encode as E
22−import Json.Encode ((==>))
23−import qualified Json.String as Json
24−import qualified Parse.Primitives as P
25−import qualified Parse.Type as Type
26−import qualified Reporting.Annotation as A
27−import qualified Reporting.Doc as D
28−import qualified Reporting.Render.Type as RT
29−import qualified Reporting.Render.Type.Localizer as L
30−
31−
32−
33−-- TYPES
34−
35−
36−data Type
37− = Lambda Type Type
38− | Var Name.Name
39− | Type Name.Name [Type]
40− | Record [(Name.Name, Type)] (Maybe Name.Name)
41− | Unit
42− | Tuple Type Type [Type]
43−
44−
45−data DebugMetadata =
46− DebugMetadata
47− { _message :: Type
48− , _aliases :: [Alias]
49− , _unions :: [Union]
50− }
51−
52−
53−data Alias = Alias Name.Name [Name.Name] Type
54−data Union = Union Name.Name [Name.Name] [(Name.Name, [Type])]
55−
56−
57−
58−-- TO DOC
59−
60−
61−toDoc :: L.Localizer -> RT.Context -> Type -> D.Doc
62−toDoc localizer context tipe =
63− case tipe of
64− Lambda _ _ ->
65− let
66− a:b:cs =
67− map (toDoc localizer RT.Func) (collectLambdas tipe)
68− in
69− RT.lambda context a b cs
70−
71− Var name ->
72− D.fromName name
73−
74− Unit ->
75− "()"
76−
77− Tuple a b cs ->
78− RT.tuple
79− (toDoc localizer RT.None a)
80− (toDoc localizer RT.None b)
81− (map (toDoc localizer RT.None) cs)
82−
83− Type name args ->
84− RT.apply
85− context
86− (D.fromName name)
87− (map (toDoc localizer RT.App) args)
88−
89− Record fields ext ->
90− RT.record
91− (map (entryToDoc localizer) fields)
92− (fmap D.fromName ext)
93−
94−
95−entryToDoc :: L.Localizer -> (Name.Name, Type) -> (D.Doc, D.Doc)
96−entryToDoc localizer (field, fieldType) =
97− ( D.fromName field, toDoc localizer RT.None fieldType )
98−
99−
100−collectLambdas :: Type -> [Type]
101−collectLambdas tipe =
102− case tipe of
103− Lambda arg body ->
104− arg : collectLambdas body
105−
106− _ ->
107− [tipe]
108−
109−
110−
111−-- JSON for TYPE
112−
113−
114−encode :: Type -> E.Value
115−encode tipe =
116− E.chars $ D.toLine (toDoc L.empty RT.None tipe)
117−
118−
119−decoder :: D.Decoder () Type
120−decoder =
121− let
122− parser =
123− P.specialize (\_ _ _ -> ()) (fromRawType . fst <$> Type.expression)
124− in
125− D.customString parser (\_ _ -> ())
126−
127−
128−fromRawType :: Src.Type -> Type
129−fromRawType (A.At _ astType) =
130− case astType of
131− Src.TLambda t1 t2 ->
132− Lambda (fromRawType t1) (fromRawType t2)
133−
134− Src.TVar x ->
135− Var x
136−
137− Src.TUnit ->
138− Unit
139−
140− Src.TTuple a b cs ->
141− Tuple
142− (fromRawType a)
143− (fromRawType b)
144− (map fromRawType cs)
145−
146− Src.TType _ name args ->
147− Type name (map fromRawType args)
148−
149− Src.TTypeQual _ _ name args ->
150− Type name (map fromRawType args)
151−
152− Src.TRecord fields ext ->
153− let fromField (A.At _ field, tipe) = (field, fromRawType tipe) in
154− Record
155− (map fromField fields)
156− (fmap A.toValue ext)
157−
158−
159−
160−-- JSON for PROGRAM
161−
162−
163−encodeMetadata :: DebugMetadata -> E.Value
164−encodeMetadata (DebugMetadata msg aliases unions) =
165− E.object
166− [ "message" ==> encode msg
167− , "aliases" ==> E.object (map toTypeAliasField aliases)
168− , "unions" ==> E.object (map toCustomTypeField unions)
169− ]
170−
171−
172−toTypeAliasField :: Alias -> ( Json.String, E.Value )
173−toTypeAliasField (Alias name args tipe) =
174− ( Json.fromName name
175− , E.object
176− [ "args" ==> E.list E.name args
177− , "type" ==> encode tipe
178− ]
179− )
180−
181−
182−toCustomTypeField :: Union -> ( Json.String, E.Value )
183−toCustomTypeField (Union name args constructors) =
184− ( Json.fromName name
185− , E.object
186− [ "args" ==> E.list E.name args
187− , "tags" ==> E.object (map toVariantObject constructors)
188− ]
189− )
190−
191−
192−toVariantObject :: (Name.Name, [Type]) -> ( Json.String, E.Value )
193−toVariantObject (name, args) =
194− ( Json.fromName name, E.list encode args )
compiler/src/Elm/Constraint.hsdeleted−260
@@ -1,260 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Elm.Constraint
4− ( Constraint
5− , exactly
6− , anything
7− , toChars
8− , satisfies
9− , check
10− , intersect
11− , goodElm
12− , defaultElm
13− , untilNextMajor
14− , untilNextMinor
15− , expand
16− --
17− , Error(..)
18− , decoder
19− , encode
20− )
21− where
22−
23−
24−import Control.Monad (liftM4)
25−import Data.Binary (Binary, get, put, getWord8, putWord8)
26−
27−import qualified Elm.Version as V
28−import qualified Json.Decode as D
29−import qualified Json.Encode as E
30−import qualified Parse.Primitives as P
31−import Parse.Primitives (Row, Col)
32−
33−
34−
35−-- CONSTRAINTS
36−
37−
38−data Constraint
39− = Range V.Version Op Op V.Version
40− deriving (Eq)
41−
42−
43−data Op
44− = Less
45− | LessOrEqual
46− deriving (Eq)
47−
48−
49−
50−-- COMMON CONSTRAINTS
51−
52−
53−exactly :: V.Version -> Constraint
54−exactly version =
55− Range version LessOrEqual LessOrEqual version
56−
57−
58−anything :: Constraint
59−anything =
60− Range V.one LessOrEqual LessOrEqual V.max
61−
62−
63−
64−-- TO CHARS
65−
66−
67−toChars :: Constraint -> [Char]
68−toChars constraint =
69− case constraint of
70− Range lower lowerOp upperOp upper ->
71− V.toChars lower ++ opToChars lowerOp ++ "v" ++ opToChars upperOp ++ V.toChars upper
72−
73−
74−opToChars :: Op -> [Char]
75−opToChars op =
76− case op of
77− Less -> " < "
78− LessOrEqual -> " <= "
79−
80−
81−
82−-- IS SATISFIED
83−
84−
85−satisfies :: Constraint -> V.Version -> Bool
86−satisfies constraint version =
87− case constraint of
88− Range lower lowerOp upperOp upper ->
89− isLess lowerOp lower version
90− &&
91− isLess upperOp version upper
92−
93−
94−isLess :: (Ord a) => Op -> (a -> a -> Bool)
95−isLess op =
96− case op of
97− Less ->
98− (<)
99−
100− LessOrEqual ->
101− (<=)
102−
103−
104−check :: Constraint -> V.Version -> Ordering
105−check constraint version =
106− case constraint of
107− Range lower lowerOp upperOp upper ->
108− if not (isLess lowerOp lower version) then
109− LT
110−
111− else if not (isLess upperOp version upper) then
112− GT
113−
114− else
115− EQ
116−
117−
118−
119−-- INTERSECT
120−
121−
122−intersect :: Constraint -> Constraint -> Maybe Constraint
123−intersect (Range lo lop hop hi) (Range lo_ lop_ hop_ hi_) =
124− let
125− (newLo, newLop) =
126− case compare lo lo_ of
127− LT -> (lo_, lop_)
128− EQ -> (lo, if elem Less [lop,lop_] then Less else LessOrEqual)
129− GT -> (lo, lop)
130−
131− (newHi, newHop) =
132− case compare hi hi_ of
133− LT -> (hi, hop)
134− EQ -> (hi, if elem Less [hop, hop_] then Less else LessOrEqual)
135− GT -> (hi_, hop_)
136− in
137− if newLo <= newHi then
138− Just (Range newLo newLop newHop newHi)
139− else
140− Nothing
141−
142−
143−
144−-- ELM CONSTRAINT
145−
146−
147−goodElm :: Constraint -> Bool
148−goodElm constraint =
149− satisfies constraint V.compiler
150−
151−
152−defaultElm :: Constraint
153−defaultElm =
154− if V._major V.compiler > 0
155− then untilNextMajor V.compiler
156− else untilNextMinor V.compiler
157−
158−
159−
160−-- CREATE CONSTRAINTS
161−
162−
163−untilNextMajor :: V.Version -> Constraint
164−untilNextMajor version =
165− Range version LessOrEqual Less (V.bumpMajor version)
166−
167−
168−untilNextMinor :: V.Version -> Constraint
169−untilNextMinor version =
170− Range version LessOrEqual Less (V.bumpMinor version)
171−
172−
173−expand :: Constraint -> V.Version -> Constraint
174−expand constraint@(Range lower lowerOp upperOp upper) version
175− | version < lower =
176− Range version LessOrEqual upperOp upper
177−
178− | version > upper =
179− Range lower lowerOp Less (V.bumpMajor version)
180−
181− | otherwise =
182− constraint
183−
184−
185−
186−-- JSON
187−
188−
189−encode :: Constraint -> E.Value
190−encode constraint =
191− E.chars (toChars constraint)
192−
193−
194−decoder :: D.Decoder Error Constraint
195−decoder =
196− D.customString parser BadFormat
197−
198−
199−
200−-- BINARY
201−
202−
203−instance Binary Constraint where
204− get = liftM4 Range get get get get
205− put (Range a b c d) = put a >> put b >> put c >> put d
206−
207−
208−instance Binary Op where
209− put op =
210− case op of
211− Less -> putWord8 0
212− LessOrEqual -> putWord8 1
213−
214− get =
215− do n <- getWord8
216− case n of
217− 0 -> return Less
218− 1 -> return LessOrEqual
219− _ -> fail "binary encoding of Op was corrupted"
220−
221−
222−
223−-- PARSER
224−
225−
226−data Error
227− = BadFormat Row Col
228− | InvalidRange V.Version V.Version
229−
230−
231−parser :: P.Parser Error Constraint
232−parser =
233− do lower <- parseVersion
234− P.word1 0x20 {- -} BadFormat
235− loOp <- parseOp
236− P.word1 0x20 {- -} BadFormat
237− P.word1 0x76 {-v-} BadFormat
238− P.word1 0x20 {- -} BadFormat
239− hiOp <- parseOp
240− P.word1 0x20 {- -} BadFormat
241− higher <- parseVersion
242− P.Parser $ \state@(P.State _ _ _ _ row col) _ eok _ eerr ->
243− if lower < higher
244− then eok (Range lower loOp hiOp higher) state
245− else eerr row col (\_ _ -> InvalidRange lower higher)
246−
247−
248−parseVersion :: P.Parser Error V.Version
249−parseVersion =
250− P.specialize (\(r,c) _ _ -> BadFormat r c) V.parser
251−
252−
253−parseOp :: P.Parser Error Op
254−parseOp =
255− do P.word1 0x3C {-<-} BadFormat
256− P.oneOfWithFallback
257− [ do P.word1 0x3D {-=-} BadFormat
258− return LessOrEqual
259− ]
260− Less
compiler/src/Elm/Docs.hsdeleted−587
@@ -1,587 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, MultiWayIf, OverloadedStrings, UnboxedTuples #-}
3−module Elm.Docs
4− ( Documentation
5− , Module(..)
6− , fromModule
7− , Union(..)
8− , Alias(..)
9− , Value(..)
10− , Binop(..)
11− , Binop.Associativity(..)
12− , Binop.Precedence(..)
13− , Error(..)
14− , decoder
15− , encode
16− )
17− where
18−
19−
20−import qualified Data.Coerce as Coerce
21−import qualified Data.List as List
22−import Data.Map ((!))
23−import qualified Data.Map as Map
24−import qualified Data.Map.Merge.Strict as Map
25−import qualified Data.Name as Name
26−import qualified Data.NonEmptyList as NE
27−import qualified Data.OneOrMore as OneOrMore
28−import Data.Word (Word8)
29−import Foreign.Ptr (Ptr, plusPtr)
30−
31−import qualified AST.Canonical as Can
32−import qualified AST.Source as Src
33−import qualified AST.Utils.Binop as Binop
34−import qualified Elm.Compiler.Type as Type
35−import qualified Elm.Compiler.Type.Extract as Extract
36−import qualified Elm.ModuleName as ModuleName
37−import qualified Json.Decode as D
38−import qualified Json.Encode as E
39−import Json.Encode ((==>))
40−import qualified Json.String as Json
41−import Parse.Primitives (Row, Col, word1)
42−import qualified Parse.Primitives as P
43−import qualified Parse.Space as Space
44−import qualified Parse.Symbol as Symbol
45−import qualified Parse.Variable as Var
46−import qualified Reporting.Annotation as A
47−import qualified Reporting.Error.Docs as E
48−import qualified Reporting.Result as Result
49−
50−
51−
52−-- DOCUMENTATION
53−
54−
55−type Documentation =
56− Map.Map Name.Name Module
57−
58−
59−data Module =
60− Module
61− { _name :: Name.Name
62− , _comment :: Comment
63− , _unions :: Map.Map Name.Name Union
64− , _aliases :: Map.Map Name.Name Alias
65− , _values :: Map.Map Name.Name Value
66− , _binops :: Map.Map Name.Name Binop
67− }
68−
69−type Comment = Json.String
70−
71−data Alias = Alias Comment [Name.Name] Type.Type
72−data Union = Union Comment [Name.Name] [(Name.Name, [Type.Type])]
73−data Value = Value Comment Type.Type
74−data Binop = Binop Comment Type.Type Binop.Associativity Binop.Precedence
75−
76−
77−
78−-- JSON
79−
80−
81−encode :: Documentation -> E.Value
82−encode docs =
83− E.list encodeModule (Map.elems docs)
84−
85−
86−encodeModule :: Module -> E.Value
87−encodeModule (Module name comment unions aliases values binops) =
88− E.object $
89− [ "name" ==> ModuleName.encode name
90− , "comment" ==> E.string comment
91− , "unions" ==> E.list encodeUnion (Map.toList unions)
92− , "aliases" ==> E.list encodeAlias (Map.toList aliases)
93− , "values" ==> E.list encodeValue (Map.toList values)
94− , "binops" ==> E.list encodeBinop (Map.toList binops)
95− ]
96−
97−
98−data Error
99− = BadAssociativity
100− | BadModuleName
101− | BadType
102−
103−
104−decoder :: D.Decoder Error Documentation
105−decoder =
106− toDict <$> D.list moduleDecoder
107−
108−
109−toDict :: [Module] -> Documentation
110−toDict modules =
111− Map.fromList (map toDictHelp modules)
112−
113−
114−toDictHelp :: Module -> (Name.Name, Module)
115−toDictHelp modul@(Module name _ _ _ _ _) =
116− (name, modul)
117−
118−
119−moduleDecoder :: D.Decoder Error Module
120−moduleDecoder =
121− Module
122− <$> D.field "name" moduleNameDecoder
123− <*> D.field "comment" D.string
124− <*> D.field "unions" (dictDecoder union)
125− <*> D.field "aliases" (dictDecoder alias)
126− <*> D.field "values" (dictDecoder value)
127− <*> D.field "binops" (dictDecoder binop)
128−
129−
130−dictDecoder :: D.Decoder Error a -> D.Decoder Error (Map.Map Name.Name a)
131−dictDecoder entryDecoder =
132− Map.fromList <$> D.list (named entryDecoder)
133−
134−
135−named :: D.Decoder Error a -> D.Decoder Error (Name.Name, a)
136−named entryDecoder =
137− (,)
138− <$> D.field "name" nameDecoder
139− <*> entryDecoder
140−
141−
142−nameDecoder :: D.Decoder e Name.Name
143−nameDecoder =
144− fmap Coerce.coerce D.string
145−
146−
147−moduleNameDecoder :: D.Decoder Error ModuleName.Raw
148−moduleNameDecoder =
149− D.mapError (const BadModuleName) ModuleName.decoder
150−
151−
152−typeDecoder :: D.Decoder Error Type.Type
153−typeDecoder =
154− D.mapError (const BadType) Type.decoder
155−
156−
157−
158−-- UNION JSON
159−
160−
161−encodeUnion :: (Name.Name, Union) -> E.Value
162−encodeUnion (name, Union comment args cases) =
163− E.object
164− [ "name" ==> E.name name
165− , "comment" ==> E.string comment
166− , "args" ==> E.list E.name args
167− , "cases" ==> E.list encodeCase cases
168− ]
169−
170−
171−union :: D.Decoder Error Union
172−union =
173− Union
174− <$> D.field "comment" D.string
175− <*> D.field "args" (D.list nameDecoder)
176− <*> D.field "cases" (D.list caseDecoder)
177−
178−
179−encodeCase :: ( Name.Name, [Type.Type] ) -> E.Value
180−encodeCase ( tag, args ) =
181− E.list id [ E.name tag, E.list Type.encode args ]
182−
183−
184−caseDecoder :: D.Decoder Error ( Name.Name, [Type.Type] )
185−caseDecoder =
186− D.pair nameDecoder (D.list typeDecoder)
187−
188−
189−
190−-- ALIAS JSON
191−
192−
193−encodeAlias :: (Name.Name, Alias) -> E.Value
194−encodeAlias ( name, Alias comment args tipe) =
195− E.object
196− [ "name" ==> E.name name
197− , "comment" ==> E.string comment
198− , "args" ==> E.list E.name args
199− , "type" ==> Type.encode tipe
200− ]
201−
202−
203−alias :: D.Decoder Error Alias
204−alias =
205− Alias
206− <$> D.field "comment" D.string
207− <*> D.field "args" (D.list nameDecoder)
208− <*> D.field "type" typeDecoder
209−
210−
211−
212−-- VALUE JSON
213−
214−
215−encodeValue :: (Name.Name, Value) -> E.Value
216−encodeValue (name, Value comment tipe) =
217− E.object
218− [ "name" ==> E.name name
219− , "comment" ==> E.string comment
220− , "type" ==> Type.encode tipe
221− ]
222−
223−
224−value :: D.Decoder Error Value
225−value =
226− Value
227− <$> D.field "comment" D.string
228− <*> D.field "type" typeDecoder
229−
230−
231−
232−-- BINOP JSON
233−
234−
235−encodeBinop :: (Name.Name, Binop) -> E.Value
236−encodeBinop (name, Binop comment tipe assoc prec) =
237− E.object
238− [ "name" ==> E.name name
239− , "comment" ==> E.string comment
240− , "type" ==> Type.encode tipe
241− , "associativity" ==> encodeAssoc assoc
242− , "precedence" ==> encodePrec prec
243− ]
244−
245−
246−binop :: D.Decoder Error Binop
247−binop =
248− Binop
249− <$> D.field "comment" D.string
250− <*> D.field "type" typeDecoder
251− <*> D.field "associativity" assocDecoder
252− <*> D.field "precedence" precDecoder
253−
254−
255−
256−-- ASSOCIATIVITY JSON
257−
258−
259−encodeAssoc :: Binop.Associativity -> E.Value
260−encodeAssoc assoc =
261− case assoc of
262− Binop.Left -> E.chars "left"
263− Binop.Non -> E.chars "non"
264− Binop.Right -> E.chars "right"
265−
266−
267−assocDecoder :: D.Decoder Error Binop.Associativity
268−assocDecoder =
269− let
270− left = Json.fromChars "left"
271− non = Json.fromChars "non"
272− right = Json.fromChars "right"
273− in
274− do str <- D.string
275− if | str == left -> return Binop.Left
276− | str == non -> return Binop.Non
277− | str == right -> return Binop.Right
278− | otherwise -> D.failure BadAssociativity
279−
280−
281−
282−-- PRECEDENCE JSON
283−
284−
285−encodePrec :: Binop.Precedence -> E.Value
286−encodePrec (Binop.Precedence n) =
287− E.int n
288−
289−
290−precDecoder :: D.Decoder Error Binop.Precedence
291−precDecoder =
292− Binop.Precedence <$> D.int
293−
294−
295−
296−-- FROM MODULE
297−
298−
299−fromModule :: Can.Module -> Either E.Error Module
300−fromModule modul@(Can.Module _ exports docs _ _ _ _ _) =
301− case exports of
302− Can.ExportEverything region ->
303− Left (E.ImplicitExposing region)
304−
305− Can.Export exportDict ->
306− case docs of
307− Src.NoDocs region ->
308− Left (E.NoDocs region)
309−
310− Src.YesDocs overview comments ->
311− do names <- parseOverview overview
312− checkNames exportDict names
313− checkDefs exportDict overview (Map.fromList comments) modul
314−
315−
316−
317−-- PARSE OVERVIEW
318−
319−
320−parseOverview :: Src.Comment -> Either E.Error [A.Located Name.Name]
321−parseOverview (Src.Comment snippet) =
322− case P.fromSnippet (chompOverview []) E.BadEnd snippet of
323− Left err ->
324− Left (E.SyntaxProblem err)
325−
326− Right names ->
327− Right names
328−
329−
330−type Parser a =
331− P.Parser E.SyntaxProblem a
332−
333−
334−chompOverview :: [A.Located Name.Name] -> Parser [A.Located Name.Name]
335−chompOverview names =
336− do isDocs <- chompUntilDocs
337− if isDocs
338− then
339− do Space.chomp E.Space
340− chompOverview =<< chompDocs names
341− else
342− return names
343−
344−
345−chompDocs :: [A.Located Name.Name] -> Parser [A.Located Name.Name]
346−chompDocs names =
347− do name <-
348− P.addLocation $
349− P.oneOf E.Name
350− [ Var.lower E.Name
351− , Var.upper E.Name
352− , chompOperator
353− ]
354−
355− Space.chomp E.Space
356−
357− P.oneOfWithFallback
358− [ do pos <- P.getPosition
359− Space.checkIndent pos E.Comma
360− word1 0x2C {-,-} E.Comma
361− Space.chomp E.Space
362− chompDocs (name:names)
363− ]
364− (name:names)
365−
366−
367−chompOperator :: Parser Name.Name
368−chompOperator =
369− do word1 0x28 {-(-} E.Op
370− op <- Symbol.operator E.Op E.OpBad
371− word1 0x29 {-)-} E.Op
372− return op
373−
374−
375−-- TODO add rule that @docs must be after newline in 0.20
376−--
377−chompUntilDocs :: Parser Bool
378−chompUntilDocs =
379− P.Parser $ \(P.State src pos end indent row col) cok _ _ _ ->
380− let
381− (# isDocs, newPos, newRow, newCol #) = untilDocs pos end row col
382− !newState = P.State src newPos end indent newRow newCol
383− in
384− cok isDocs newState
385−
386−
387−untilDocs :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# Bool, Ptr Word8, Row, Col #)
388−untilDocs pos end row col =
389− if pos >= end then
390− (# False, pos, row, col #)
391− else
392− let !word = P.unsafeIndex pos in
393− if word == 0x0A {-\n-} then
394− untilDocs (plusPtr pos 1) end (row + 1) 1
395− else
396− let !pos5 = plusPtr pos 5 in
397− if pos5 <= end
398− && P.unsafeIndex ( pos ) == 0x40 {-@-}
399− && P.unsafeIndex (plusPtr pos 1) == 0x64 {-d-}
400− && P.unsafeIndex (plusPtr pos 2) == 0x6F {-o-}
401− && P.unsafeIndex (plusPtr pos 3) == 0x63 {-c-}
402− && P.unsafeIndex (plusPtr pos 4) == 0x73 {-s-}
403− && Var.getInnerWidth pos5 end == 0
404− then
405− (# True, pos5, row, col + 5 #)
406− else
407− let !newPos = plusPtr pos (P.getCharWidth word) in
408− untilDocs newPos end row (col + 1)
409−
410−
411−
412−-- CHECK NAMES
413−
414−
415−checkNames :: Map.Map Name.Name (A.Located Can.Export) -> [A.Located Name.Name] -> Either E.Error ()
416−checkNames exports names =
417− let
418− docs = List.foldl' addName Map.empty names
419− loneDoc = Map.traverseMissing onlyInDocs
420− loneExport = Map.traverseMissing onlyInExports
421− checkBoth = Map.zipWithAMatched (\n _ r -> isUnique n r)
422− in
423− case Result.run (Map.mergeA loneExport loneDoc checkBoth exports docs) of
424− (_, Right _) -> Right ()
425− (_, Left es) -> Left (E.NameProblems (OneOrMore.destruct NE.List es))
426−
427−
428−type DocNameRegions =
429− Map.Map Name.Name (OneOrMore.OneOrMore A.Region)
430−
431−
432−addName :: DocNameRegions -> A.Located Name.Name -> DocNameRegions
433−addName dict (A.At region name) =
434− Map.insertWith OneOrMore.more name (OneOrMore.one region) dict
435−
436−
437−isUnique :: Name.Name -> OneOrMore.OneOrMore A.Region -> Result.Result i w E.NameProblem A.Region
438−isUnique name regions =
439− case regions of
440− OneOrMore.One region ->
441− Result.ok region
442−
443− OneOrMore.More left right ->
444− let (r1, r2) = OneOrMore.getFirstTwo left right in
445− Result.throw (E.NameDuplicate name r1 r2)
446−
447−
448−onlyInDocs :: Name.Name -> OneOrMore.OneOrMore A.Region -> Result.Result i w E.NameProblem a
449−onlyInDocs name regions =
450− do region <- isUnique name regions
451− Result.throw $ E.NameOnlyInDocs name region
452−
453−
454−onlyInExports :: Name.Name -> A.Located Can.Export -> Result.Result i w E.NameProblem a
455−onlyInExports name (A.At region _) =
456− Result.throw $ E.NameOnlyInExports name region
457−
458−
459−
460−-- CHECK DEFS
461−
462−
463−checkDefs :: Map.Map Name.Name (A.Located Can.Export) -> Src.Comment -> Map.Map Name.Name Src.Comment -> Can.Module -> Either E.Error Module
464−checkDefs exportDict overview comments (Can.Module name _ _ decls unions aliases infixes effects) =
465− let
466− types = gatherTypes decls Map.empty
467− info = Info comments types unions aliases infixes effects
468− in
469− case Result.run (Map.traverseWithKey (checkExport info) exportDict) of
470− (_, Left problems ) -> Left $ E.DefProblems (OneOrMore.destruct NE.List problems)
471− (_, Right inserters) -> Right $ foldr ($) (emptyModule name overview) inserters
472−
473−
474−emptyModule :: ModuleName.Canonical -> Src.Comment -> Module
475−emptyModule (ModuleName.Canonical _ name) (Src.Comment overview) =
476− Module name (Json.fromComment overview) Map.empty Map.empty Map.empty Map.empty
477−
478−
479−data Info =
480− Info
481− { _iComments :: Map.Map Name.Name Src.Comment
482− , _iValues :: Map.Map Name.Name (Either A.Region Can.Type)
483− , _iUnions :: Map.Map Name.Name Can.Union
484− , _iAliases :: Map.Map Name.Name Can.Alias
485− , _iBinops :: Map.Map Name.Name Can.Binop
486− , _iEffects :: Can.Effects
487− }
488−
489−
490−checkExport :: Info -> Name.Name -> A.Located Can.Export -> Result.Result i w E.DefProblem (Module -> Module)
491−checkExport info name (A.At region export) =
492− case export of
493− Can.ExportValue ->
494− do tipe <- getType name info
495− comment <- getComment region name info
496− Result.ok $ \m ->
497− m { _values = Map.insert name (Value comment tipe) (_values m) }
498−
499− Can.ExportBinop ->
500− do let (Can.Binop_ assoc prec realName) = _iBinops info ! name
501− tipe <- getType realName info
502− comment <- getComment region realName info
503− Result.ok $ \m ->
504− m { _binops = Map.insert name (Binop comment tipe assoc prec) (_binops m) }
505−
506− Can.ExportAlias ->
507− do let (Can.Alias tvars tipe) = _iAliases info ! name
508− comment <- getComment region name info
509− Result.ok $ \m ->
510− m { _aliases = Map.insert name (Alias comment tvars (Extract.fromType tipe)) (_aliases m) }
511−
512− Can.ExportUnionOpen ->
513− do let (Can.Union tvars ctors _ _) = _iUnions info ! name
514− comment <- getComment region name info
515− Result.ok $ \m ->
516− m { _unions = Map.insert name (Union comment tvars (map dector ctors)) (_unions m) }
517−
518− Can.ExportUnionClosed ->
519− do let (Can.Union tvars _ _ _) = _iUnions info ! name
520− comment <- getComment region name info
521− Result.ok $ \m ->
522− m { _unions = Map.insert name (Union comment tvars []) (_unions m) }
523−
524− Can.ExportPort ->
525− do tipe <- getType name info
526− comment <- getComment region name info
527− Result.ok $ \m ->
528− m { _values = Map.insert name (Value comment tipe) (_values m) }
529−
530−
531−getComment :: A.Region -> Name.Name -> Info -> Result.Result i w E.DefProblem Comment
532−getComment region name info =
533− case Map.lookup name (_iComments info) of
534− Nothing ->
535− Result.throw (E.NoComment name region)
536−
537− Just (Src.Comment snippet) ->
538− Result.ok (Json.fromComment snippet)
539−
540−
541−getType :: Name.Name -> Info -> Result.Result i w E.DefProblem Type.Type
542−getType name info =
543− case _iValues info ! name of
544− Left region ->
545− Result.throw (E.NoAnnotation name region)
546−
547− Right tipe ->
548− Result.ok (Extract.fromType tipe)
549−
550−
551−dector :: Can.Ctor -> (Name.Name, [Type.Type])
552−dector (Can.Ctor name _ _ args) =
553− ( name, map Extract.fromType args )
554−
555−
556−
557−-- GATHER TYPES
558−
559−
560−type Types =
561− Map.Map Name.Name (Either A.Region Can.Type)
562−
563−
564−gatherTypes :: Can.Decls -> Types -> Types
565−gatherTypes decls types =
566− case decls of
567− Can.Declare def subDecls ->
568− gatherTypes subDecls (addDef types def)
569−
570− Can.DeclareRec def defs subDecls ->
571− gatherTypes subDecls (List.foldl' addDef (addDef types def) defs)
572−
573− Can.SaveTheEnvironment ->
574− types
575−
576−
577−addDef :: Types -> Can.Def -> Types
578−addDef types def =
579− case def of
580− Can.Def (A.At region name) _ _ ->
581− Map.insert name (Left region) types
582−
583− Can.TypedDef (A.At _ name) _ typedArgs _ resultType ->
584− let
585− tipe = foldr Can.TLambda resultType (map snd typedArgs)
586− in
587− Map.insert name (Right tipe) types
compiler/src/Elm/Float.hsdeleted−51
@@ -1,51 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE EmptyDataDecls, FlexibleInstances #-}
3−module Elm.Float
4− ( Float
5− , fromPtr
6− , toBuilder
7− )
8− where
9−
10−
11−import Prelude hiding (Float)
12−import Data.Binary (Binary, get, put)
13−import qualified Data.ByteString.Builder as B
14−import qualified Data.Utf8 as Utf8
15−import Data.Word (Word8)
16−import Foreign.Ptr (Ptr)
17−
18−
19−
20−-- FLOATS
21−
22−
23−type Float =
24− Utf8.Utf8 ELM_FLOAT
25−
26−
27−data ELM_FLOAT
28−
29−
30−
31−-- HELPERS
32−
33−
34−fromPtr :: Ptr Word8 -> Ptr Word8 -> Float
35−fromPtr =
36− Utf8.fromPtr
37−
38−
39−{-# INLINE toBuilder #-}
40−toBuilder :: Float -> B.Builder
41−toBuilder =
42− Utf8.toBuilder
43−
44−
45−
46−-- BINARY
47−
48−
49−instance Binary (Utf8.Utf8 ELM_FLOAT) where
50− get = Utf8.getUnder256
51− put = Utf8.putUnder256
compiler/src/Elm/Interface.hsdeleted−254
@@ -1,254 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Elm.Interface
3− ( Interface(..)
4− , Union(..)
5− , Alias(..)
6− , Binop(..)
7− , fromModule
8− , toPublicUnion
9− , toPublicAlias
10− , DependencyInterface(..)
11− , public
12− , private
13− , privatize
14− , extractUnion
15− , extractAlias
16− )
17− where
18−
19−
20−import Control.Monad (liftM, liftM3, liftM4, liftM5)
21−import Data.Binary
22−import Data.Map.Strict ((!))
23−import qualified Data.Map.Strict as Map
24−import qualified Data.Map.Merge.Strict as Map
25−import qualified Data.Name as Name
26−
27−import qualified AST.Canonical as Can
28−import qualified AST.Utils.Binop as Binop
29−import qualified Elm.Package as Pkg
30−import qualified Reporting.Annotation as A
31−
32−
33−
34−-- INTERFACE
35−
36−
37−data Interface =
38− Interface
39− { _home :: Pkg.Name
40− , _values :: Map.Map Name.Name Can.Annotation
41− , _unions :: Map.Map Name.Name Union
42− , _aliases :: Map.Map Name.Name Alias
43− , _binops :: Map.Map Name.Name Binop
44− }
45− deriving (Eq)
46−
47−
48−data Union
49− = OpenUnion Can.Union
50− | ClosedUnion Can.Union
51− | PrivateUnion Can.Union
52− deriving (Eq)
53−
54−
55−data Alias
56− = PublicAlias Can.Alias
57− | PrivateAlias Can.Alias
58− deriving (Eq)
59−
60−
61−data Binop =
62− Binop
63− { _op_name :: Name.Name
64− , _op_annotation :: Can.Annotation
65− , _op_associativity :: Binop.Associativity
66− , _op_precedence :: Binop.Precedence
67− }
68− deriving (Eq)
69−
70−
71−
72−-- FROM MODULE
73−
74−
75−fromModule :: Pkg.Name -> Can.Module -> Map.Map Name.Name Can.Annotation -> Interface
76−fromModule home (Can.Module _ exports _ _ unions aliases binops _) annotations =
77− Interface
78− { _home = home
79− , _values = restrict exports annotations
80− , _unions = restrictUnions exports unions
81− , _aliases = restrictAliases exports aliases
82− , _binops = restrict exports (Map.map (toOp annotations) binops)
83− }
84−
85−
86−restrict :: Can.Exports -> Map.Map Name.Name a -> Map.Map Name.Name a
87−restrict exports dict =
88− case exports of
89− Can.ExportEverything _ ->
90− dict
91−
92− Can.Export explicitExports ->
93− Map.intersection dict explicitExports
94−
95−
96−toOp :: Map.Map Name.Name Can.Annotation -> Can.Binop -> Binop
97−toOp types (Can.Binop_ associativity precedence name) =
98− Binop name (types ! name) associativity precedence
99−
100−
101−restrictUnions :: Can.Exports -> Map.Map Name.Name Can.Union -> Map.Map Name.Name Union
102−restrictUnions exports unions =
103− case exports of
104− Can.ExportEverything _ ->
105− Map.map OpenUnion unions
106−
107− Can.Export explicitExports ->
108− Map.merge onLeft onRight onBoth explicitExports unions
109− where
110− onLeft = Map.dropMissing
111− onRight = Map.mapMissing (\_ union -> PrivateUnion union)
112− onBoth = Map.zipWithMatched $ \_ (A.At _ export) union ->
113− case export of
114− Can.ExportUnionOpen -> OpenUnion union
115− Can.ExportUnionClosed -> ClosedUnion union
116− _ -> error "impossible exports discovered in restrictUnions"
117−
118−
119−restrictAliases :: Can.Exports -> Map.Map Name.Name Can.Alias -> Map.Map Name.Name Alias
120−restrictAliases exports aliases =
121− case exports of
122− Can.ExportEverything _ ->
123− Map.map PublicAlias aliases
124−
125− Can.Export explicitExports ->
126− Map.merge onLeft onRight onBoth explicitExports aliases
127− where
128− onLeft = Map.dropMissing
129− onRight = Map.mapMissing (\_ a -> PrivateAlias a)
130− onBoth = Map.zipWithMatched (\_ _ a -> PublicAlias a)
131−
132−
133−
134−-- TO PUBLIC
135−
136−
137−toPublicUnion :: Union -> Maybe Can.Union
138−toPublicUnion iUnion =
139− case iUnion of
140− OpenUnion union -> Just union
141− ClosedUnion (Can.Union vars _ _ opts) -> Just (Can.Union vars [] 0 opts)
142− PrivateUnion _ -> Nothing
143−
144−
145−toPublicAlias :: Alias -> Maybe Can.Alias
146−toPublicAlias iAlias =
147− case iAlias of
148− PublicAlias alias -> Just alias
149− PrivateAlias _ -> Nothing
150−
151−
152−
153−-- DEPENDENCY INTERFACE
154−
155−
156−data DependencyInterface
157− = Public Interface
158− | Private
159− Pkg.Name
160− (Map.Map Name.Name Can.Union)
161− (Map.Map Name.Name Can.Alias)
162−
163−
164−public :: Interface -> DependencyInterface
165−public =
166− Public
167−
168−
169−private :: Interface -> DependencyInterface
170−private (Interface pkg _ unions aliases _) =
171− Private pkg (Map.map extractUnion unions) (Map.map extractAlias aliases)
172−
173−
174−extractUnion :: Union -> Can.Union
175−extractUnion iUnion =
176− case iUnion of
177− OpenUnion union -> union
178− ClosedUnion union -> union
179− PrivateUnion union -> union
180−
181−
182−extractAlias :: Alias -> Can.Alias
183−extractAlias iAlias =
184− case iAlias of
185− PublicAlias alias -> alias
186− PrivateAlias alias -> alias
187−
188−
189−privatize :: DependencyInterface -> DependencyInterface
190−privatize di =
191− case di of
192− Public i -> private i
193− Private _ _ _ -> di
194−
195−
196−
197−-- BINARY
198−
199−
200−instance Binary Interface where
201− get = liftM5 Interface get get get get get
202− put (Interface a b c d e) = put a >> put b >> put c >> put d >> put e
203−
204−
205−instance Binary Union where
206− put union =
207− case union of
208− OpenUnion u -> putWord8 0 >> put u
209− ClosedUnion u -> putWord8 1 >> put u
210− PrivateUnion u -> putWord8 2 >> put u
211−
212− get =
213− do n <- getWord8
214− case n of
215− 0 -> liftM OpenUnion get
216− 1 -> liftM ClosedUnion get
217− 2 -> liftM PrivateUnion get
218− _ -> fail "binary encoding of Union was corrupted"
219−
220−
221−instance Binary Alias where
222− put union =
223− case union of
224− PublicAlias a -> putWord8 0 >> put a
225− PrivateAlias a -> putWord8 1 >> put a
226−
227− get =
228− do n <- getWord8
229− case n of
230− 0 -> liftM PublicAlias get
231− 1 -> liftM PrivateAlias get
232− _ -> fail "binary encoding of Alias was corrupted"
233−
234−
235−instance Binary Binop where
236− get =
237− liftM4 Binop get get get get
238−
239− put (Binop a b c d) =
240− put a >> put b >> put c >> put d
241−
242−
243−instance Binary DependencyInterface where
244− put union =
245− case union of
246− Public a -> putWord8 0 >> put a
247− Private a b c -> putWord8 1 >> put a >> put b >> put c
248−
249− get =
250− do n <- getWord8
251− case n of
252− 0 -> liftM Public get
253− 1 -> liftM3 Private get get get
254− _ -> fail "binary encoding of DependencyInterface was corrupted"
compiler/src/Elm/Kernel.hsdeleted−365
@@ -1,365 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, EmptyDataDecls, OverloadedStrings, UnboxedTuples #-}
3−module Elm.Kernel
4− ( Content(..)
5− , Chunk(..)
6− , fromByteString
7− , countFields
8− )
9− where
10−
11−
12−import Control.Monad (liftM, liftM2)
13−import Data.Binary (Binary, get, put, getWord8, putWord8)
14−import qualified Data.ByteString.Internal as B
15−import qualified Data.List as List
16−import qualified Data.Map as Map
17−import qualified Data.Name as Name
18−import Data.Word (Word8)
19−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
20−import Foreign.ForeignPtr (ForeignPtr)
21−import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
22−
23−import qualified AST.Source as Src
24−import qualified Elm.ModuleName as ModuleName
25−import qualified Elm.Package as Pkg
26−import qualified Parse.Module as Module
27−import qualified Parse.Space as Space
28−import qualified Parse.Variable as Var
29−import Parse.Primitives hiding (fromByteString)
30−import qualified Parse.Primitives as P
31−import qualified Reporting.Annotation as A
32−
33−
34−
35−-- CHUNK
36−
37−
38−data Chunk
39− = JS B.ByteString
40− | ElmVar ModuleName.Canonical Name.Name
41− | JsVar Name.Name Name.Name
42− | ElmField Name.Name
43− | JsField Int
44− | JsEnum Int
45− | Debug
46− | Prod
47−
48−
49−
50−-- COUNT FIELDS
51−
52−
53−countFields :: [Chunk] -> Map.Map Name.Name Int
54−countFields chunks =
55− foldr addField Map.empty chunks
56−
57−
58−addField :: Chunk -> Map.Map Name.Name Int -> Map.Map Name.Name Int
59−addField chunk fields =
60− case chunk of
61− JS _ -> fields
62− ElmVar _ _ -> fields
63− JsVar _ _ -> fields
64− ElmField f -> Map.insertWith (+) f 1 fields
65− JsField _ -> fields
66− JsEnum _ -> fields
67− Debug -> fields
68− Prod -> fields
69−
70−
71−
72−-- FROM FILE
73−
74−
75−data Content =
76− Content [Src.Import] [Chunk]
77−
78−
79−type Foreigns =
80− Map.Map ModuleName.Raw Pkg.Name
81−
82−
83−fromByteString :: Pkg.Name -> Foreigns -> B.ByteString -> Maybe Content
84−fromByteString pkg foreigns bytes =
85− case P.fromByteString (parser pkg foreigns) toError bytes of
86− Right content ->
87− Just content
88−
89− Left () ->
90− Nothing
91−
92−
93−parser :: Pkg.Name -> Foreigns -> Parser () Content
94−parser pkg foreigns =
95− do word2 0x2F 0x2A {-/*-} toError
96− Space.chomp ignoreError
97− Space.checkFreshLine toError
98− imports <- specialize ignoreError (Module.chompImports [])
99− word2 0x2A 0x2F {-*/-} toError
100− chunks <- parseChunks (toVarTable pkg foreigns imports) Map.empty Map.empty
101− return (Content imports chunks)
102−
103−
104−toError :: Row -> Col -> ()
105−toError _ _ =
106− ()
107−
108−
109−ignoreError :: a -> Row -> Col -> ()
110−ignoreError _ _ _ =
111− ()
112−
113−
114−
115−-- PARSE CHUNKS
116−
117−
118−parseChunks :: VarTable -> Enums -> Fields -> Parser () [Chunk]
119−parseChunks vtable enums fields =
120− P.Parser $ \(P.State src pos end indent row col) cok _ cerr _ ->
121− let
122− (# chunks, newPos, newRow, newCol #) =
123− chompChunks vtable enums fields src pos end row col pos []
124− in
125− if newPos == end then
126− cok chunks (P.State src newPos end indent newRow newCol)
127− else
128− cerr row col toError
129−
130−
131−chompChunks :: VarTable -> Enums -> Fields -> ForeignPtr Word8 -> Ptr Word8 -> Ptr Word8 -> Row -> Col -> Ptr Word8 -> [Chunk] -> (# [Chunk], Ptr Word8, Row, Col #)
132−chompChunks vs es fs src pos end row col lastPos revChunks =
133− if pos >= end then
134− let !js = toByteString src lastPos end in
135− (# reverse (JS js : revChunks), pos, row, col #)
136−
137− else
138− let !word = unsafeIndex pos in
139− if word == 0x5F {-_-} then
140− let
141− !pos1 = plusPtr pos 1
142− !pos3 = plusPtr pos 3
143− in
144− if pos3 <= end && unsafeIndex pos1 == 0x5F {-_-} then
145− let !js = toByteString src lastPos pos in
146− chompTag vs es fs src pos3 end row (col + 3) (JS js : revChunks)
147− else
148− chompChunks vs es fs src pos1 end row (col + 1) lastPos revChunks
149−
150− else if word == 0x0A {-\n-} then
151− chompChunks vs es fs src (plusPtr pos 1) end (row + 1) 1 lastPos revChunks
152−
153− else
154− let
155− !newPos = plusPtr pos (getCharWidth word)
156− in
157− chompChunks vs es fs src newPos end row (col + 1) lastPos revChunks
158−
159−
160−toByteString :: ForeignPtr Word8 -> Ptr Word8 -> Ptr Word8 -> B.ByteString
161−toByteString src pos end =
162− let
163− !off = minusPtr pos (unsafeForeignPtrToPtr src)
164− !len = minusPtr end pos
165− in
166− B.PS src off len
167−
168−
169−
170−-- relies on external checks in chompChunks
171−chompTag :: VarTable -> Enums -> Fields -> ForeignPtr Word8 -> Ptr Word8 -> Ptr Word8 -> Row -> Col -> [Chunk] -> (# [Chunk], Ptr Word8, Row, Col #)
172−chompTag vs es fs src pos end row col revChunks =
173− let
174− (# newPos, newCol #) = Var.chompInnerChars pos end col
175− !tagPos = plusPtr pos (-1)
176− !word = unsafeIndex tagPos
177− in
178− if word == 0x24 {-$-} then
179− let
180− !name = Name.fromPtr pos newPos
181− in
182− chompChunks vs es fs src newPos end row newCol newPos $
183− ElmField name : revChunks
184− else
185− let
186− !name = Name.fromPtr tagPos newPos
187− in
188− if 0x30 {-0-} <= word && word <= 0x39 {-9-} then
189− let
190− (enum, newEnums) =
191− lookupEnum (word - 0x30) name es
192− in
193− chompChunks vs newEnums fs src newPos end row newCol newPos $
194− JsEnum enum : revChunks
195−
196− else if 0x61 {-a-} <= word && word <= 0x7A {-z-} then
197− let
198− (field, newFields) =
199− lookupField name fs
200− in
201− chompChunks vs es newFields src newPos end row newCol newPos $
202− JsField field : revChunks
203−
204− else if name == "DEBUG" then
205− chompChunks vs es fs src newPos end row newCol newPos (Debug : revChunks)
206−
207− else if name == "PROD" then
208− chompChunks vs es fs src newPos end row newCol newPos (Prod : revChunks)
209−
210− else
211− case Map.lookup name vs of
212− Just chunk ->
213− chompChunks vs es fs src newPos end row newCol newPos (chunk : revChunks)
214−
215− Nothing ->
216− (# revChunks, pos, row, col #)
217−
218−
219−
220−-- FIELDS
221−
222−
223−type Fields =
224− Map.Map Name.Name Int
225−
226−
227−lookupField :: Name.Name -> Fields -> (Int, Fields)
228−lookupField name fields =
229− case Map.lookup name fields of
230− Just n ->
231− ( n, fields )
232−
233− Nothing ->
234− let n = Map.size fields in
235− ( n, Map.insert name n fields )
236−
237−
238−
239−-- ENUMS
240−
241−
242−type Enums =
243− Map.Map Word8 (Map.Map Name.Name Int)
244−
245−
246−lookupEnum :: Word8 -> Name.Name -> Enums -> (Int, Enums)
247−lookupEnum word var allEnums =
248− let
249− enums =
250− Map.findWithDefault Map.empty word allEnums
251− in
252− case Map.lookup var enums of
253− Just n ->
254− ( n, allEnums )
255−
256− Nothing ->
257− let n = Map.size enums in
258− ( n, Map.insert word (Map.insert var n enums) allEnums )
259−
260−
261−
262−-- PROCESS IMPORTS
263−
264−
265−type VarTable =
266− Map.Map Name.Name Chunk
267−
268−
269−toVarTable :: Pkg.Name -> Foreigns -> [Src.Import] -> VarTable
270−toVarTable pkg foreigns imports =
271− List.foldl' (addImport pkg foreigns) Map.empty imports
272−
273−
274−addImport :: Pkg.Name -> Foreigns -> VarTable -> Src.Import -> VarTable
275−addImport pkg foreigns vtable (Src.Import (A.At _ importName) maybeAlias exposing) =
276− if Name.isKernel importName then
277− case maybeAlias of
278− Just _ ->
279− error ("cannot use `as` with kernel import of: " ++ Name.toChars importName)
280−
281− Nothing ->
282− let
283− home = Name.getKernel importName
284− add table name =
285− Map.insert (Name.sepBy 0x5F {-_-} home name) (JsVar home name) table
286− in
287− List.foldl' add vtable (toNames exposing)
288−
289− else
290− let
291− home = ModuleName.Canonical (Map.findWithDefault pkg importName foreigns) importName
292− prefix = toPrefix importName maybeAlias
293− add table name =
294− Map.insert (Name.sepBy 0x5F {-_-} prefix name) (ElmVar home name) table
295− in
296− List.foldl' add vtable (toNames exposing)
297−
298−
299−toPrefix :: Name.Name -> Maybe Name.Name -> Name.Name
300−toPrefix home maybeAlias =
301− case maybeAlias of
302− Just alias ->
303− alias
304−
305− Nothing ->
306− if Name.hasDot home then
307− error ("kernel imports with dots need an alias: " ++ show (Name.toChars home))
308− else
309− home
310−
311−
312−toNames :: Src.Exposing -> [Name.Name]
313−toNames exposing =
314− case exposing of
315− Src.Open ->
316− error "cannot have `exposing (..)` in kernel code."
317−
318− Src.Explicit exposedList ->
319− map toName exposedList
320−
321−
322−toName :: Src.Exposed -> Name.Name
323−toName exposed =
324− case exposed of
325− Src.Lower (A.At _ name) ->
326− name
327−
328− Src.Upper (A.At _ name) Src.Private ->
329− name
330−
331− Src.Upper _ (Src.Public _) ->
332− error "cannot have Maybe(..) syntax in kernel code header"
333−
334− Src.Operator _ _ ->
335− error "cannot use binops in kernel code"
336−
337−
338−
339−-- BINARY
340−
341−
342−instance Binary Chunk where
343− put chunk =
344− case chunk of
345− JS a -> putWord8 0 >> put a
346− ElmVar a b -> putWord8 1 >> put a >> put b
347− JsVar a b -> putWord8 2 >> put a >> put b
348− ElmField a -> putWord8 3 >> put a
349− JsField a -> putWord8 4 >> put a
350− JsEnum a -> putWord8 5 >> put a
351− Debug -> putWord8 6
352− Prod -> putWord8 7
353−
354− get =
355− do word <- getWord8
356− case word of
357− 0 -> liftM JS get
358− 1 -> liftM2 ElmVar get get
359− 2 -> liftM2 JsVar get get
360− 3 -> liftM ElmField get
361− 4 -> liftM JsField get
362− 5 -> liftM JsEnum get
363− 6 -> return Debug
364− 7 -> return Prod
365− _ -> error "problem deserializing Elm.Kernel.Chunk"
compiler/src/Elm/Licenses.hsdeleted−185
@@ -1,185 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Elm.Licenses
4− ( License
5− , bsd3
6− , encode
7− , decoder
8− )
9− where
10−
11−
12−import qualified Data.Map as Map
13−import qualified Data.Utf8 as Utf8
14−
15−import qualified Json.Decode as D
16−import qualified Json.Encode as E
17−import qualified Json.String as Json
18−import qualified Reporting.Suggest as Suggest
19−
20−
21−
22−-- LICENCES
23−
24−
25−newtype License =
26− License Json.String
27−
28−
29−bsd3 :: License
30−bsd3 =
31− License (Json.fromChars "BSD-3-Clause")
32−
33−
34−encode :: License -> E.Value
35−encode (License code) =
36− E.string code
37−
38−
39−decoder :: (Json.String -> [Json.String] -> e) -> D.Decoder e License
40−decoder toError =
41− do str <- D.string
42− case check str of
43− Right license ->
44− return license
45−
46− Left suggestions ->
47− D.failure (toError str suggestions)
48−
49−
50−
51−-- CHECK
52−
53−
54−check :: Json.String -> Either [Json.String] License
55−check givenCode =
56− if Map.member givenCode osiApprovedSpdxLicenses then
57− Right (License givenCode)
58−
59− else
60− let
61− pairs =
62− map (\code -> (code, Json.toChars code)) (Map.keys osiApprovedSpdxLicenses)
63− ++
64− Map.toList osiApprovedSpdxLicenses
65− in
66− Left $ map fst $ take 4 $
67− Suggest.sort (Utf8.toChars givenCode) snd pairs
68−
69−
70−
71−-- LIST OF LICENCES
72−
73−
74−(==>) :: [Char] -> [Char] -> (Json.String, [Char])
75−(==>) code fullName =
76− ( Json.fromChars code, fullName )
77−
78−
79−--
80−-- OSI approved licenses in SPDX format.
81−-- <https://spdx.org/licenses/>
82−--
83−osiApprovedSpdxLicenses :: Map.Map Json.String [Char]
84−osiApprovedSpdxLicenses =
85− Map.fromList
86− [ "0BSD" ==> "BSD Zero Clause License"
87− , "AAL" ==> "Attribution Assurance License"
88− , "AFL-1.1" ==> "Academic Free License v1.1"
89− , "AFL-1.2" ==> "Academic Free License v1.2"
90− , "AFL-2.0" ==> "Academic Free License v2.0"
91− , "AFL-2.1" ==> "Academic Free License v2.1"
92− , "AFL-3.0" ==> "Academic Free License v3.0"
93− , "AGPL-3.0" ==> "GNU Affero General Public License v3.0"
94− , "Apache-1.1" ==> "Apache License 1.1"
95− , "Apache-2.0" ==> "Apache License 2.0"
96− , "APL-1.0" ==> "Adaptive Public License 1.0"
97− , "APSL-1.0" ==> "Apple Public Source License 1.0"
98− , "APSL-1.1" ==> "Apple Public Source License 1.1"
99− , "APSL-1.2" ==> "Apple Public Source License 1.2"
100− , "APSL-2.0" ==> "Apple Public Source License 2.0"
101− , "Artistic-1.0" ==> "Artistic License 1.0"
102− , "Artistic-1.0-cl8" ==> "Artistic License 1.0 w/clause 8"
103− , "Artistic-1.0-Perl" ==> "Artistic License 1.0 (Perl)"
104− , "Artistic-2.0" ==> "Artistic License 2.0"
105− , "BSD-2-Clause" ==> "BSD 2-clause \"Simplified\" License"
106− , "BSD-3-Clause" ==> "BSD 3-clause \"New\" or \"Revised\" License"
107− , "BSL-1.0" ==> "Boost Software License 1.0"
108− , "CATOSL-1.1" ==> "Computer Associates Trusted Open Source License 1.1"
109− , "CDDL-1.0" ==> "Common Development and Distribution License 1.0"
110− , "CECILL-2.1" ==> "CeCILL Free Software License Agreement v2.1"
111− , "CNRI-Python" ==> "CNRI Python License"
112− , "CPAL-1.0" ==> "Common Public Attribution License 1.0"
113− , "CPL-1.0" ==> "Common Public License 1.0"
114− , "CUA-OPL-1.0" ==> "CUA Office Public License v1.0"
115− , "ECL-1.0" ==> "Educational Community License v1.0"
116− , "ECL-2.0" ==> "Educational Community License v2.0"
117− , "EFL-1.0" ==> "Eiffel Forum License v1.0"
118− , "EFL-2.0" ==> "Eiffel Forum License v2.0"
119− , "Entessa" ==> "Entessa Public License v1.0"
120− , "EPL-1.0" ==> "Eclipse Public License 1.0"
121− , "EUDatagrid" ==> "EU DataGrid Software License"
122− , "EUPL-1.1" ==> "European Union Public License 1.1"
123− , "Fair" ==> "Fair License"
124− , "Frameworx-1.0" ==> "Frameworx Open License 1.0"
125− , "GPL-2.0" ==> "GNU General Public License v2.0 only"
126− , "GPL-3.0" ==> "GNU General Public License v3.0 only"
127− , "HPND" ==> "Historic Permission Notice and Disclaimer"
128− , "Intel" ==> "Intel Open Source License"
129− , "IPA" ==> "IPA Font License"
130− , "IPL-1.0" ==> "IBM Public License v1.0"
131− , "ISC" ==> "ISC License"
132− , "LGPL-2.0" ==> "GNU Library General Public License v2 only"
133− , "LGPL-2.1" ==> "GNU Lesser General Public License v2.1 only"
134− , "LGPL-3.0" ==> "GNU Lesser General Public License v3.0 only"
135− , "LiLiQ-P-1.1" ==> "Licence Libre du Québec – Permissive version 1.1"
136− , "LiLiQ-R-1.1" ==> "Licence Libre du Québec – Réciprocité version 1.1"
137− , "LiLiQ-Rplus-1.1" ==> "Licence Libre du Québec – Réciprocité forte version 1.1"
138− , "LPL-1.0" ==> "Lucent Public License Version 1.0"
139− , "LPL-1.02" ==> "Lucent Public License v1.02"
140− , "LPPL-1.3c" ==> "LaTeX Project Public License v1.3c"
141− , "MirOS" ==> "MirOS Licence"
142− , "MIT" ==> "MIT License"
143− , "Motosoto" ==> "Motosoto License"
144− , "MPL-1.0" ==> "Mozilla Public License 1.0"
145− , "MPL-1.1" ==> "Mozilla Public License 1.1"
146− , "MPL-2.0" ==> "Mozilla Public License 2.0"
147− , "MPL-2.0-no-copyleft-exception" ==> "Mozilla Public License 2.0 (no copyleft exception)"
148− , "MS-PL" ==> "Microsoft Public License"
149− , "MS-RL" ==> "Microsoft Reciprocal License"
150− , "Multics" ==> "Multics License"
151− , "NASA-1.3" ==> "NASA Open Source Agreement 1.3"
152− , "Naumen" ==> "Naumen Public License"
153− , "NCSA" ==> "University of Illinois/NCSA Open Source License"
154− , "NGPL" ==> "Nethack General Public License"
155− , "Nokia" ==> "Nokia Open Source License"
156− , "NPOSL-3.0" ==> "Non-Profit Open Software License 3.0"
157− , "NTP" ==> "NTP License"
158− , "OCLC-2.0" ==> "OCLC Research Public License 2.0"
159− , "OFL-1.1" ==> "SIL Open Font License 1.1"
160− , "OGTSL" ==> "Open Group Test Suite License"
161− , "OSET-PL-2.1" ==> "OSET Public License version 2.1"
162− , "OSL-1.0" ==> "Open Software License 1.0"
163− , "OSL-2.0" ==> "Open Software License 2.0"
164− , "OSL-2.1" ==> "Open Software License 2.1"
165− , "OSL-3.0" ==> "Open Software License 3.0"
166− , "PHP-3.0" ==> "PHP License v3.0"
167− , "PostgreSQL" ==> "PostgreSQL License"
168− , "Python-2.0" ==> "Python License 2.0"
169− , "QPL-1.0" ==> "Q Public License 1.0"
170− , "RPL-1.1" ==> "Reciprocal Public License 1.1"
171− , "RPL-1.5" ==> "Reciprocal Public License 1.5"
172− , "RPSL-1.0" ==> "RealNetworks Public Source License v1.0"
173− , "RSCPL" ==> "Ricoh Source Code Public License"
174− , "SimPL-2.0" ==> "Simple Public License 2.0"
175− , "SISSL" ==> "Sun Industry Standards Source License v1.1"
176− , "Sleepycat" ==> "Sleepycat License"
177− , "SPL-1.0" ==> "Sun Public License v1.0"
178− , "UPL-1.0" ==> "Universal Permissive License v1.0"
179− , "VSL-1.0" ==> "Vovida Software License v1.0"
180− , "W3C" ==> "W3C Software Notice and License (2002-12-31)"
181− , "Watcom-1.0" ==> "Sybase Open Watcom Public License 1.0"
182− , "Xnet" ==> "X.Net License"
183− , "Zlib" ==> "zlib License"
184− , "ZPL-2.0" ==> "Zope Public License 2.0"
185− ]
compiler/src/Elm/Magnitude.hsdeleted−24
@@ -1,24 +0,0 @@
1−module Elm.Magnitude
2− ( Magnitude(..)
3− , toChars
4− )
5− where
6−
7−
8−
9−-- MAGNITUDE
10−
11−
12−data Magnitude
13− = PATCH
14− | MINOR
15− | MAJOR
16− deriving (Eq, Ord)
17−
18−
19−toChars :: Magnitude -> String
20−toChars magnitude =
21− case magnitude of
22− PATCH -> "PATCH"
23− MINOR -> "MINOR"
24− MAJOR -> "MAJOR"
compiler/src/Elm/ModuleName.hsdeleted−283
@@ -1,283 +0,0 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings, UnboxedTuples #-}
2−module Elm.ModuleName
3− ( Raw
4− , toChars
5− , toFilePath
6− , toHyphenPath
7− --
8− , encode
9− , decoder
10− , parser
11− --
12− , Canonical(..)
13− , basics, char, string
14− , maybe, result, list, array, dict, tuple
15− , platform, cmd, sub
16− , debug
17− , virtualDom
18− , jsonDecode, jsonEncode
19− , webgl, texture, vector2, vector3, vector4, matrix4
20− )
21− where
22−
23−
24−import Control.Monad (liftM2)
25−import Data.Binary (Binary(..))
26−import qualified Data.Name as Name
27−import qualified Data.Utf8 as Utf8
28−import Data.Word (Word8)
29−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
30−import Prelude hiding (maybe)
31−import qualified System.FilePath as FP
32−
33−import qualified Elm.Package as Pkg
34−import qualified Json.Decode as D
35−import qualified Json.Encode as E
36−import qualified Parse.Variable as Var
37−import qualified Parse.Primitives as P
38−import Parse.Primitives (Row, Col)
39−
40−
41−
42−-- RAW
43−
44−
45−type Raw = Name.Name
46−
47−
48−toChars :: Raw -> String
49−toChars =
50− Name.toChars
51−
52−
53−toFilePath :: Raw -> FilePath
54−toFilePath name =
55− map (\c -> if c == '.' then FP.pathSeparator else c) (Name.toChars name)
56−
57−
58−toHyphenPath :: Raw -> FilePath
59−toHyphenPath name =
60− map (\c -> if c == '.' then '-' else c) (Name.toChars name)
61−
62−
63−
64−-- JSON
65−
66−
67−encode :: Raw -> E.Value
68−encode =
69− E.name
70−
71−
72−decoder :: D.Decoder (Row, Col) Raw
73−decoder =
74− D.customString parser (,)
75−
76−
77−
78−-- PARSER
79−
80−
81−parser :: P.Parser (Row, Col) Raw
82−parser =
83− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
84− let
85− (# isGood, newPos, newCol #) = chompStart pos end col
86− in
87− if isGood && minusPtr newPos pos < 256 then
88− let !newState = P.State src newPos end indent row newCol in
89− cok (Utf8.fromPtr pos newPos) newState
90−
91− else if col == newCol then
92− eerr row newCol (,)
93−
94− else
95− cerr row newCol (,)
96−
97−
98−chompStart :: Ptr Word8 -> Ptr Word8 -> Col -> (# Bool, Ptr Word8, Col #)
99−chompStart pos end col =
100− let
101− !width = Var.getUpperWidth pos end
102− in
103− if width == 0 then
104− (# False, pos, col #)
105− else
106− chompInner (plusPtr pos width) end (col + 1)
107−
108−
109−chompInner :: Ptr Word8 -> Ptr Word8 -> Col -> (# Bool, Ptr Word8, Col #)
110−chompInner pos end col =
111− if pos >= end then
112− (# True, pos, col #)
113− else
114− let
115− !word = P.unsafeIndex pos
116− !width = Var.getInnerWidthHelp pos end word
117− in
118− if width == 0 then
119− if word == 0x2E {-.-} then
120− chompStart (plusPtr pos 1) end (col + 1)
121− else
122− (# True, pos, col #)
123− else
124− chompInner (plusPtr pos width) end (col + 1)
125−
126−
127−
128−-- CANONICAL
129−
130−
131−data Canonical =
132− Canonical
133− { _package :: !Pkg.Name
134− , _module :: !Name.Name
135− }
136−
137−
138−
139−-- INSTANCES
140−
141−
142−instance Eq Canonical where
143− (==) (Canonical pkg1 name1) (Canonical pkg2 name2) =
144− name1 == name2 && pkg1 == pkg2
145−
146−
147−instance Ord Canonical where
148− compare (Canonical pkg1 name1) (Canonical pkg2 name2) =
149− case compare name1 name2 of
150− LT -> LT
151− EQ -> compare pkg1 pkg2
152− GT -> GT
153−
154−
155−instance Binary Canonical where
156− put (Canonical a b) = put a >> put b
157− get = liftM2 Canonical get get
158−
159−
160−
161−-- CORE
162−
163−
164−{-# NOINLINE basics #-}
165−basics :: Canonical
166−basics = Canonical Pkg.core Name.basics
167−
168−
169−{-# NOINLINE char #-}
170−char :: Canonical
171−char = Canonical Pkg.core Name.char
172−
173−
174−{-# NOINLINE string #-}
175−string :: Canonical
176−string = Canonical Pkg.core Name.string
177−
178−
179−{-# NOINLINE maybe #-}
180−maybe :: Canonical
181−maybe = Canonical Pkg.core Name.maybe
182−
183−
184−{-# NOINLINE result #-}
185−result :: Canonical
186−result = Canonical Pkg.core Name.result
187−
188−
189−{-# NOINLINE list #-}
190−list :: Canonical
191−list = Canonical Pkg.core Name.list
192−
193−
194−{-# NOINLINE array #-}
195−array :: Canonical
196−array = Canonical Pkg.core Name.array
197−
198−
199−{-# NOINLINE dict #-}
200−dict :: Canonical
201−dict = Canonical Pkg.core Name.dict
202−
203−
204−{-# NOINLINE tuple #-}
205−tuple :: Canonical
206−tuple = Canonical Pkg.core Name.tuple
207−
208−
209−{-# NOINLINE platform #-}
210−platform :: Canonical
211−platform = Canonical Pkg.core Name.platform
212−
213−
214−{-# NOINLINE cmd #-}
215−cmd :: Canonical
216−cmd = Canonical Pkg.core "Platform.Cmd"
217−
218−
219−{-# NOINLINE sub #-}
220−sub :: Canonical
221−sub = Canonical Pkg.core "Platform.Sub"
222−
223−
224−{-# NOINLINE debug #-}
225−debug :: Canonical
226−debug = Canonical Pkg.core Name.debug
227−
228−
229−
230−-- HTML
231−
232−
233−{-# NOINLINE virtualDom #-}
234−virtualDom :: Canonical
235−virtualDom = Canonical Pkg.virtualDom Name.virtualDom
236−
237−
238−
239−-- JSON
240−
241−
242−{-# NOINLINE jsonDecode #-}
243−jsonDecode :: Canonical
244−jsonDecode = Canonical Pkg.json "Json.Decode"
245−
246−
247−{-# NOINLINE jsonEncode #-}
248−jsonEncode :: Canonical
249−jsonEncode = Canonical Pkg.json "Json.Encode"
250−
251−
252−
253−-- WEBGL
254−
255−
256−{-# NOINLINE webgl #-}
257−webgl :: Canonical
258−webgl = Canonical Pkg.webgl "WebGL"
259−
260−
261−{-# NOINLINE texture #-}
262−texture :: Canonical
263−texture = Canonical Pkg.webgl "WebGL.Texture"
264−
265−
266−{-# NOINLINE vector2 #-}
267−vector2 :: Canonical
268−vector2 = Canonical Pkg.linearAlgebra "Math.Vector2"
269−
270−
271−{-# NOINLINE vector3 #-}
272−vector3 :: Canonical
273−vector3 = Canonical Pkg.linearAlgebra "Math.Vector3"
274−
275−
276−{-# NOINLINE vector4 #-}
277−vector4 :: Canonical
278−vector4 = Canonical Pkg.linearAlgebra "Math.Vector4"
279−
280−
281−{-# NOINLINE matrix4 #-}
282−matrix4 :: Canonical
283−matrix4 = Canonical Pkg.linearAlgebra "Math.Matrix4"
compiler/src/Elm/Package.hsdeleted−374
@@ -1,374 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, EmptyDataDecls, FlexibleInstances, UnboxedTuples #-}
3−module Elm.Package
4− ( Name(..)
5− , Author
6− , Project
7− , Canonical(..)
8− , isKernel
9− , toChars
10− , toUrl
11− , toFilePath
12− , toJsonString
13− --
14− , dummyName, kernel, core
15− , browser, virtualDom, html
16− , json, http, url
17− , webgl, linearAlgebra
18− --
19− , suggestions
20− , nearbyNames
21− --
22− , decoder
23− , encode
24− , keyDecoder
25− --
26− , parser
27− )
28− where
29−
30−
31−import Control.Monad (liftM2)
32−import Data.Binary (Binary, get, put)
33−import qualified Data.Coerce as Coerce
34−import qualified Data.List as List
35−import qualified Data.Map as Map
36−import qualified Data.Name as Name
37−import Data.Monoid ((<>))
38−import qualified Data.Utf8 as Utf8
39−import Data.Word (Word8)
40−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
41−import System.FilePath ((</>))
42−
43−import qualified Elm.Version as V
44−import qualified Json.Decode as D
45−import qualified Json.Encode as E
46−import qualified Json.String as Json
47−import qualified Parse.Primitives as P
48−import Parse.Primitives (Row, Col)
49−import qualified Reporting.Suggest as Suggest
50−
51−
52−
53−-- PACKGE NAMES
54−
55−
56−data Name =
57− Name
58− { _author :: !Author
59− , _project :: !Project
60− }
61− deriving (Ord)
62−
63−
64−type Author = Utf8.Utf8 AUTHOR
65−type Project = Utf8.Utf8 PROJECT
66−
67−data AUTHOR
68−data PROJECT
69−
70−
71−data Canonical =
72− Canonical
73− { _name :: !Name
74− , _version :: !V.Version
75− }
76− deriving (Ord)
77−
78−
79−
80−-- HELPERS
81−
82−
83−isKernel :: Name -> Bool
84−isKernel (Name author _) =
85− author == elm || author == elm_explorations
86−
87−
88−toChars :: Name -> String
89−toChars (Name author project) =
90− Utf8.toChars author <> "/" <> Utf8.toChars project
91−
92−
93−toUrl :: Name -> String
94−toUrl (Name author project) =
95− Utf8.toChars author ++ "/" ++ Utf8.toChars project
96−
97−
98−toFilePath :: Name -> FilePath
99−toFilePath (Name author project) =
100− Utf8.toChars author </> Utf8.toChars project
101−
102−
103−toJsonString :: Name -> Json.String
104−toJsonString (Name author project) =
105− Utf8.join 0x2F {-/-} [ Coerce.coerce author, Coerce.coerce project ]
106−
107−
108−
109−-- COMMON PACKAGE NAMES
110−
111−
112−toName :: Author -> [Char] -> Name
113−toName author project =
114− Name author (Utf8.fromChars project)
115−
116−
117−{-# NOINLINE dummyName #-}
118−dummyName :: Name
119−dummyName =
120− toName (Utf8.fromChars "author") "project"
121−
122−
123−{-# NOINLINE kernel #-}
124−kernel :: Name
125−kernel =
126− toName elm "kernel"
127−
128−
129−{-# NOINLINE core #-}
130−core :: Name
131−core =
132− toName elm "core"
133−
134−
135−{-# NOINLINE browser #-}
136−browser :: Name
137−browser =
138− toName elm "browser"
139−
140−
141−{-# NOINLINE virtualDom #-}
142−virtualDom :: Name
143−virtualDom =
144− toName elm "virtual-dom"
145−
146−
147−{-# NOINLINE html #-}
148−html :: Name
149−html =
150− toName elm "html"
151−
152−
153−{-# NOINLINE json #-}
154−json :: Name
155−json =
156− toName elm "json"
157−
158−
159−{-# NOINLINE http #-}
160−http :: Name
161−http =
162− toName elm "http"
163−
164−
165−{-# NOINLINE url #-}
166−url :: Name
167−url =
168− toName elm "url"
169−
170−
171−{-# NOINLINE webgl #-}
172−webgl :: Name
173−webgl =
174− toName elm_explorations "webgl"
175−
176−
177−{-# NOINLINE linearAlgebra #-}
178−linearAlgebra :: Name
179−linearAlgebra =
180− toName elm_explorations "linear-algebra"
181−
182−
183−{-# NOINLINE elm #-}
184−elm :: Author
185−elm =
186− Utf8.fromChars "elm"
187−
188−
189−{-# NOINLINE elm_explorations #-}
190−elm_explorations :: Author
191−elm_explorations =
192− Utf8.fromChars "elm-explorations"
193−
194−
195−
196−-- PACKAGE SUGGESTIONS
197−
198−
199−suggestions :: Map.Map Name.Name Name
200−suggestions =
201− let
202− random = toName elm "random"
203− time = toName elm "time"
204− file = toName elm "file"
205− in
206− Map.fromList
207− [ "Browser" ==> browser
208− , "File" ==> file
209− , "File.Download" ==> file
210− , "File.Select" ==> file
211− , "Html" ==> html
212− , "Html.Attributes" ==> html
213− , "Html.Events" ==> html
214− , "Http" ==> http
215− , "Json.Decode" ==> json
216− , "Json.Encode" ==> json
217− , "Random" ==> random
218− , "Time" ==> time
219− , "Url.Parser" ==> url
220− , "Url" ==> url
221− ]
222−
223−
224−(==>) :: [Char] -> Name -> (Name.Name, Name)
225−(==>) moduleName package =
226− ( Utf8.fromChars moduleName, package )
227−
228−
229−
230−-- NEARBY NAMES
231−
232−
233−nearbyNames :: Name -> [Name] -> [Name]
234−nearbyNames (Name author1 project1) possibleNames =
235− let
236− authorDist = authorDistance (Utf8.toChars author1)
237− projectDist = projectDistance (Utf8.toChars project1)
238−
239− nameDistance (Name author2 project2) =
240− authorDist author2 + projectDist project2
241− in
242− take 4 $ List.sortOn nameDistance possibleNames
243−
244−
245−authorDistance :: [Char] -> Author -> Int
246−authorDistance given possibility =
247− if possibility == elm || possibility == elm_explorations
248− then 0
249− else abs (Suggest.distance given (Utf8.toChars possibility))
250−
251−
252−projectDistance :: [Char] -> Project -> Int
253−projectDistance given possibility =
254− abs (Suggest.distance given (Utf8.toChars possibility))
255−
256−
257−
258−-- INSTANCES
259−
260−
261−instance Eq Name where
262− (==) (Name author1 project1) (Name author2 project2) =
263− project1 == project2 && author1 == author2
264−
265−
266−instance Eq Canonical where
267− (==) (Canonical package1 version1) (Canonical package2 version2) =
268− version1 == version2 && package1 == package2
269−
270−
271−
272−-- BINARY
273−
274−
275−instance Binary Name where -- PERF try storing as a Word16
276− get = liftM2 Name Utf8.getUnder256 Utf8.getUnder256
277− put (Name a b) = Utf8.putUnder256 a >> Utf8.putUnder256 b
278−
279−
280−instance Binary Canonical where
281− get = liftM2 Canonical get get
282− put (Canonical a b) = put a >> put b
283−
284−
285−
286−-- JSON
287−
288−
289−decoder :: D.Decoder (Row, Col) Name
290−decoder =
291− D.customString parser (,)
292−
293−
294−encode :: Name -> E.Value
295−encode name =
296− E.chars (toChars name)
297−
298−
299−keyDecoder :: (Row -> Col -> x) -> D.KeyDecoder x Name
300−keyDecoder toError =
301− let
302− keyParser =
303− P.specialize (\(r,c) _ _ -> toError r c) parser
304− in
305− D.KeyDecoder keyParser toError
306−
307−
308−
309−-- PARSER
310−
311−
312−parser :: P.Parser (Row, Col) Name
313−parser =
314− do author <- parseName isAlphaOrDigit isAlphaOrDigit
315− P.word1 0x2F {-/-} (,)
316− project <- parseName isLower isLowerOrDigit
317− return (Name author project)
318−
319−
320−parseName :: (Word8 -> Bool) -> (Word8 -> Bool) -> P.Parser (Row, Col) (Utf8.Utf8 t)
321−parseName isGoodStart isGoodInner =
322− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
323− if pos >= end then
324− eerr row col (,)
325− else
326− let !word = P.unsafeIndex pos in
327− if not (isGoodStart word) then
328− eerr row col (,)
329− else
330− let
331− (# isGood, newPos #) = chompName isGoodInner (plusPtr pos 1) end False
332− !len = fromIntegral (minusPtr newPos pos)
333− !newCol = col + len
334− in
335− if isGood && len < 256 then
336− let !newState = P.State src newPos end indent row newCol in
337− cok (Utf8.fromPtr pos newPos) newState
338− else
339− cerr row newCol (,)
340−
341−
342−isLower :: Word8 -> Bool
343−isLower word =
344− 0x61 {-a-} <= word && word <= 0x7A {-z-}
345−
346−
347−isLowerOrDigit :: Word8 -> Bool
348−isLowerOrDigit word =
349− 0x61 {-a-} <= word && word <= 0x7A {-z-}
350− || 0x30 {-0-} <= word && word <= 0x39 {-9-}
351−
352−
353−isAlphaOrDigit :: Word8 -> Bool
354−isAlphaOrDigit word =
355− 0x61 {-a-} <= word && word <= 0x7A {-z-}
356− || 0x41 {-A-} <= word && word <= 0x5A {-Z-}
357− || 0x30 {-0-} <= word && word <= 0x39 {-9-}
358−
359−
360−chompName :: (Word8 -> Bool) -> Ptr Word8 -> Ptr Word8 -> Bool -> (# Bool, Ptr Word8 #)
361−chompName isGoodChar pos end prevWasDash =
362− if pos >= end then
363− (# not prevWasDash, pos #)
364− else
365− let !word = P.unsafeIndex pos in
366− if isGoodChar word then
367− chompName isGoodChar (plusPtr pos 1) end False
368− else if word == 0x2D {---} then
369− if prevWasDash then
370− (# False, pos #)
371− else
372− chompName isGoodChar (plusPtr pos 1) end True
373− else
374− (# True, pos #)
compiler/src/Elm/String.hsdeleted−133
@@ -1,133 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}
2−{-# LANGUAGE BangPatterns, EmptyDataDecls, FlexibleInstances #-}
3−module Elm.String
4− ( String
5− , toChars
6− , toBuilder
7− , Chunk(..)
8− , fromChunks
9− )
10− where
11−
12−
13−import Prelude hiding (String)
14−import Data.Binary (Binary, get, put)
15−import Data.Bits ((.&.), shiftR)
16−import qualified Data.ByteString.Builder as B
17−import qualified Data.Utf8 as Utf8
18−import Data.Utf8 (MBA, newByteArray, copyFromPtr, freeze, writeWord8)
19−import GHC.Exts (RealWorld, Ptr)
20−import GHC.IO (stToIO, unsafeDupablePerformIO)
21−import GHC.ST (ST)
22−import GHC.Word (Word8)
23−
24−
25−
26−-- STRINGS
27−
28−
29−type String =
30− Utf8.Utf8 ELM_STRING
31−
32−
33−data ELM_STRING
34−
35−
36−
37−-- HELPERS
38−
39−
40−toChars :: String -> [Char]
41−toChars =
42− Utf8.toChars
43−
44−
45−{-# INLINE toBuilder #-}
46−toBuilder :: String -> B.Builder
47−toBuilder =
48− Utf8.toBuilder
49−
50−
51−
52−-- FROM CHUNKS
53−
54−
55−data Chunk
56− = Slice (Ptr Word8) Int
57− | Escape Word8
58− | CodePoint Int
59−
60−
61−fromChunks :: [Chunk] -> String
62−fromChunks chunks =
63− unsafeDupablePerformIO (stToIO (
64− do let !len = sum (map chunkToWidth chunks)
65− mba <- newByteArray len
66− writeChunks mba 0 chunks
67− freeze mba
68− ))
69−
70−
71−chunkToWidth :: Chunk -> Int
72−chunkToWidth chunk =
73− case chunk of
74− Slice _ len -> len
75− Escape _ -> 2
76− CodePoint c -> if c < 0xFFFF then 6 else 12
77−
78−
79−writeChunks :: MBA RealWorld -> Int -> [Chunk] -> ST RealWorld ()
80−writeChunks mba offset chunks =
81− case chunks of
82− [] ->
83− return ()
84−
85− chunk : chunks ->
86− case chunk of
87− Slice ptr len ->
88− do copyFromPtr ptr mba offset len
89− let !newOffset = offset + len
90− writeChunks mba newOffset chunks
91−
92− Escape word ->
93− do writeWord8 mba offset 0x5C {- \ -}
94− writeWord8 mba (offset + 1) word
95− let !newOffset = offset + 2
96− writeChunks mba newOffset chunks
97−
98− CodePoint code ->
99− if code < 0xFFFF then
100− do writeCode mba offset code
101− let !newOffset = offset + 6
102− writeChunks mba newOffset chunks
103− else
104− do let (hi,lo) = divMod (code - 0x10000) 0x400
105− writeCode mba (offset ) (hi + 0xD800)
106− writeCode mba (offset + 6) (lo + 0xDC00)
107− let !newOffset = offset + 12
108− writeChunks mba newOffset chunks
109−
110−
111−writeCode :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
112−writeCode mba offset code =
113− do writeWord8 mba offset 0x5C {- \ -}
114− writeWord8 mba (offset + 1) 0x75 {- u -}
115− writeHex mba (offset + 2) (shiftR code 12)
116− writeHex mba (offset + 3) (shiftR code 8)
117− writeHex mba (offset + 4) (shiftR code 4)
118− writeHex mba (offset + 5) code
119−
120−
121−writeHex :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
122−writeHex mba !offset !bits =
123− do let !n = fromIntegral bits .&. 0x0F
124− writeWord8 mba offset (if n < 10 then 0x30 + n else 0x37 + n)
125−
126−
127−
128−-- BINARY
129−
130−
131−instance Binary (Utf8.Utf8 ELM_STRING) where
132− get = Utf8.getVeryLong
133− put = Utf8.putVeryLong
compiler/src/Elm/Version.hsdeleted−196
@@ -1,196 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, UnboxedTuples #-}
3−module Elm.Version
4− ( Version(..)
5− , one
6− , max
7− , compiler
8− , bumpPatch
9− , bumpMinor
10− , bumpMajor
11− , toChars
12− --
13− , decoder
14− , encode
15− --
16− , parser
17− )
18− where
19−
20−
21−import Prelude hiding (max)
22−import Control.Monad (liftM3)
23−import Data.Binary (Binary, get, put, getWord8, putWord8)
24−import qualified Data.Version as Version
25−import Data.Word (Word8, Word16)
26−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
27−import qualified Paths_elm
28−
29−import qualified Json.Decode as D
30−import qualified Json.Encode as E
31−import qualified Parse.Primitives as P
32−import Parse.Primitives (Row, Col)
33−
34−
35−
36−-- VERSION
37−
38−
39−data Version =
40− Version
41− { _major :: {-# UNPACK #-} !Word16
42− , _minor :: {-# UNPACK #-} !Word16
43− , _patch :: {-# UNPACK #-} !Word16
44− }
45− deriving (Eq, Ord)
46−
47−
48−one :: Version
49−one =
50− Version 1 0 0
51−
52−
53−max :: Version
54−max =
55− Version maxBound 0 0
56−
57−
58−compiler :: Version
59−compiler =
60− case map fromIntegral (Version.versionBranch Paths_elm.version) of
61− major : minor : patch : _ ->
62− Version major minor patch
63−
64− [major, minor] ->
65− Version major minor 0
66−
67− [major] ->
68− Version major 0 0
69−
70− [] ->
71− error "could not detect version of elm-compiler you are using"
72−
73−
74−
75−-- BUMP
76−
77−
78−bumpPatch :: Version -> Version
79−bumpPatch (Version major minor patch) =
80− Version major minor (patch + 1)
81−
82−
83−bumpMinor :: Version -> Version
84−bumpMinor (Version major minor _patch) =
85− Version major (minor + 1) 0
86−
87−
88−bumpMajor :: Version -> Version
89−bumpMajor (Version major _minor _patch) =
90− Version (major + 1) 0 0
91−
92−
93−
94−-- TO CHARS
95−
96−
97−toChars :: Version -> [Char]
98−toChars (Version major minor patch) =
99− show major ++ '.' : show minor ++ '.' : show patch
100−
101−
102−
103−-- JSON
104−
105−
106−decoder :: D.Decoder (Row, Col) Version
107−decoder =
108− D.customString parser (,)
109−
110−
111−encode :: Version -> E.Value
112−encode version =
113− E.chars (toChars version)
114−
115−
116−
117−-- BINARY
118−
119−
120−instance Binary Version where
121− get =
122− do word <- getWord8
123− if word == 255
124− then liftM3 Version get get get
125− else
126− do minor <- getWord8
127− patch <- getWord8
128− return (Version (fromIntegral word) (fromIntegral minor) (fromIntegral patch))
129−
130− put (Version major minor patch) =
131− if major < 255 && minor < 256 && patch < 256 then
132− do putWord8 (fromIntegral major)
133− putWord8 (fromIntegral minor)
134− putWord8 (fromIntegral patch)
135− else
136− do putWord8 255
137− put major
138− put minor
139− put patch
140−
141−
142−
143−-- PARSER
144−
145−
146−parser :: P.Parser (Row, Col) Version
147−parser =
148− do major <- numberParser
149− P.word1 0x2E {-.-} (,)
150− minor <- numberParser
151− P.word1 0x2E {-.-} (,)
152− patch <- numberParser
153− return (Version major minor patch)
154−
155−
156−numberParser :: P.Parser (Row, Col) Word16
157−numberParser =
158− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
159− if pos >= end then
160− eerr row col (,)
161− else
162− let !word = P.unsafeIndex pos in
163− if word == 0x30 {-0-} then
164−
165− let
166− !newState = P.State src (plusPtr pos 1) end indent row (col + 1)
167− in
168− cok 0 newState
169−
170− else if isDigit word then
171−
172− let
173− (# total, newPos #) = chompWord16 (plusPtr pos 1) end (fromIntegral (word - 0x30))
174− !newState = P.State src newPos end indent row (col + fromIntegral (minusPtr newPos pos))
175− in
176− cok total newState
177−
178− else
179− eerr row col (,)
180−
181−
182−chompWord16 :: Ptr Word8 -> Ptr Word8 -> Word16 -> (# Word16, Ptr Word8 #)
183−chompWord16 pos end total =
184− if pos >= end then
185− (# total, pos #)
186− else
187− let !word = P.unsafeIndex pos in
188− if isDigit word then
189− chompWord16 (plusPtr pos 1) end (10 * total + fromIntegral (word - 0x30))
190− else
191− (# total, pos #)
192−
193−
194−isDigit :: Word8 -> Bool
195−isDigit word =
196− 0x30 {-0-} <= word && word <= 0x39 {-9-}
compiler/src/Generate/Html.hsdeleted−54
@@ -1,54 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE QuasiQuotes #-}
3−module Generate.Html
4− ( sandwich
5− )
6− where
7−
8−
9−import qualified Data.ByteString.Builder as B
10−import Data.Monoid ((<>))
11−import qualified Data.Name as Name
12−import Text.RawString.QQ (r)
13−
14−
15−
16−-- SANDWICH
17−
18−
19−sandwich :: Name.Name -> B.Builder -> B.Builder
20−sandwich moduleName javascript =
21− let name = Name.toBuilder moduleName in
22− [r|<!DOCTYPE HTML>
23−<html>
24−<head>
25− <meta charset="UTF-8">
26− <title>|] <> name <> [r|</title>
27− <style>body { padding: 0; margin: 0; }</style>
28−</head>
29−
30−<body>
31−
32−<pre id="elm"></pre>
33−
34−<script>
35−try {
36−|] <> javascript <> [r|
37−
38− var app = Elm.|] <> name <> [r|.init({ node: document.getElementById("elm") });
39−}
40−catch (e)
41−{
42− // display initialization errors (e.g. bad flags, infinite recursion)
43− var header = document.createElement("h1");
44− header.style.fontFamily = "monospace";
45− header.innerText = "Initialization Error";
46− var pre = document.getElementById("elm");
47− document.body.insertBefore(header, pre);
48− pre.innerText = e;
49− throw e;
50−}
51−</script>
52−
53−</body>
54−</html>|]
compiler/src/Generate/JavaScript.hsdeleted−590
@@ -1,590 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Generate.JavaScript
3− ( generate
4− , generateForRepl
5− , generateForReplEndpoint
6− )
7− where
8−
9−
10−import Prelude hiding (cycle, print)
11−import qualified Data.ByteString.Builder as B
12−import Data.Monoid ((<>))
13−import qualified Data.List as List
14−import Data.Map ((!))
15−import qualified Data.Map as Map
16−import qualified Data.Name as Name
17−import qualified Data.Set as Set
18−import qualified Data.Utf8 as Utf8
19−
20−import qualified AST.Canonical as Can
21−import qualified AST.Optimized as Opt
22−import qualified Data.Index as Index
23−import qualified Elm.Kernel as K
24−import qualified Elm.ModuleName as ModuleName
25−import qualified Generate.JavaScript.Builder as JS
26−import qualified Generate.JavaScript.Expression as Expr
27−import qualified Generate.JavaScript.Functions as Functions
28−import qualified Generate.JavaScript.Name as JsName
29−import qualified Generate.Mode as Mode
30−import qualified Reporting.Doc as D
31−import qualified Reporting.Render.Type as RT
32−import qualified Reporting.Render.Type.Localizer as L
33−
34−
35−
36−-- GENERATE
37−
38−
39−type Graph = Map.Map Opt.Global Opt.Node
40−type Mains = Map.Map ModuleName.Canonical Opt.Main
41−
42−
43−generate :: Mode.Mode -> Opt.GlobalGraph -> Mains -> B.Builder
44−generate mode (Opt.GlobalGraph graph _) mains =
45− let
46− state = Map.foldrWithKey (addMain mode graph) emptyState mains
47− in
48− "(function(scope){\n'use strict';"
49− <> Functions.functions
50− <> perfNote mode
51− <> stateToBuilder state
52− <> toMainExports mode mains
53− <> "}(this));"
54−
55−
56−addMain :: Mode.Mode -> Graph -> ModuleName.Canonical -> Opt.Main -> State -> State
57−addMain mode graph home _ state =
58− addGlobal mode graph state (Opt.Global home "main")
59−
60−
61−perfNote :: Mode.Mode -> B.Builder
62−perfNote mode =
63− case mode of
64− Mode.Prod _ ->
65− ""
66−
67− Mode.Dev Nothing ->
68− "console.warn('Compiled in DEV mode. Follow the advice at "
69− <> B.stringUtf8 (D.makeNakedLink "optimize")
70− <> " for better performance and smaller assets.');"
71−
72− Mode.Dev (Just _) ->
73− "console.warn('Compiled in DEBUG mode. Follow the advice at "
74− <> B.stringUtf8 (D.makeNakedLink "optimize")
75− <> " for better performance and smaller assets.');"
76−
77−
78−
79−-- GENERATE FOR REPL
80−
81−
82−generateForRepl :: Bool -> L.Localizer -> Opt.GlobalGraph -> ModuleName.Canonical -> Name.Name -> Can.Annotation -> B.Builder
83−generateForRepl ansi localizer (Opt.GlobalGraph graph _) home name (Can.Forall _ tipe) =
84− let
85− mode = Mode.Dev Nothing
86− debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
87− evalState = addGlobal mode graph debugState (Opt.Global home name)
88− in
89− "process.on('uncaughtException', function(err) { process.stderr.write(err.toString() + '\\n'); process.exit(1); });"
90− <> Functions.functions
91− <> stateToBuilder evalState
92− <> print ansi localizer home name tipe
93−
94−
95−print :: Bool -> L.Localizer -> ModuleName.Canonical -> Name.Name -> Can.Type -> B.Builder
96−print ansi localizer home name tipe =
97− let
98− value = JsName.toBuilder (JsName.fromGlobal home name)
99− toString = JsName.toBuilder (JsName.fromKernel Name.debug "toAnsiString")
100− tipeDoc = RT.canToDoc localizer RT.None tipe
101− bool = if ansi then "true" else "false"
102− in
103− "var _value = " <> toString <> "(" <> bool <> ", " <> value <> ");\n\
104− \var _type = " <> B.stringUtf8 (show (D.toString tipeDoc)) <> ";\n\
105− \function _print(t) { console.log(_value + (" <> bool <> " ? '\x1b[90m' + t + '\x1b[0m' : t)); }\n\
106− \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
107− \ _print('\\n : ' + _type.split('\\n').join('\\n '));\n\
108− \} else {\n\
109− \ _print(' : ' + _type);\n\
110− \}\n"
111−
112−
113−
114−-- GENERATE FOR REPL ENDPOINT
115−
116−
117−generateForReplEndpoint :: L.Localizer -> Opt.GlobalGraph -> ModuleName.Canonical -> Maybe Name.Name -> Can.Annotation -> B.Builder
118−generateForReplEndpoint localizer (Opt.GlobalGraph graph _) home maybeName (Can.Forall _ tipe) =
119− let
120− name = maybe Name.replValueToPrint id maybeName
121− mode = Mode.Dev Nothing
122− debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
123− evalState = addGlobal mode graph debugState (Opt.Global home name)
124− in
125− Functions.functions
126− <> stateToBuilder evalState
127− <> postMessage localizer home maybeName tipe
128−
129−
130−postMessage :: L.Localizer -> ModuleName.Canonical -> Maybe Name.Name -> Can.Type -> B.Builder
131−postMessage localizer home maybeName tipe =
132− let
133− name = maybe Name.replValueToPrint id maybeName
134− value = JsName.toBuilder (JsName.fromGlobal home name)
135− toString = JsName.toBuilder (JsName.fromKernel Name.debug "toAnsiString")
136− tipeDoc = RT.canToDoc localizer RT.None tipe
137− toName n = "\"" <> Name.toBuilder n <> "\""
138− in
139− "self.postMessage({\n\
140− \ name: " <> maybe "null" toName maybeName <> ",\n\
141− \ value: " <> toString <> "(true, " <> value <> "),\n\
142− \ type: " <> B.stringUtf8 (show (D.toString tipeDoc)) <> "\n\
143− \});\n"
144−
145−
146−
147−-- GRAPH TRAVERSAL STATE
148−
149−
150−data State =
151− State
152− { _revKernels :: [B.Builder]
153− , _revBuilders :: [B.Builder]
154− , _seenGlobals :: Set.Set Opt.Global
155− }
156−
157−
158−emptyState :: State
159−emptyState =
160− State mempty [] Set.empty
161−
162−
163−stateToBuilder :: State -> B.Builder
164−stateToBuilder (State revKernels revBuilders _) =
165− prependBuilders revKernels (prependBuilders revBuilders mempty)
166−
167−
168−prependBuilders :: [B.Builder] -> B.Builder -> B.Builder
169−prependBuilders revBuilders monolith =
170− List.foldl' (\m b -> b <> m) monolith revBuilders
171−
172−
173−
174−-- ADD DEPENDENCIES
175−
176−
177−addGlobal :: Mode.Mode -> Graph -> State -> Opt.Global -> State
178−addGlobal mode graph state@(State revKernels builders seen) global =
179− if Set.member global seen then
180− state
181− else
182− addGlobalHelp mode graph global $
183− State revKernels builders (Set.insert global seen)
184−
185−
186−addGlobalHelp :: Mode.Mode -> Graph -> Opt.Global -> State -> State
187−addGlobalHelp mode graph global state =
188− let
189− addDeps deps someState =
190− Set.foldl' (addGlobal mode graph) someState deps
191− in
192− case graph ! global of
193− Opt.Define expr deps ->
194− addStmt (addDeps deps state) (
195− var global (Expr.generate mode expr)
196− )
197−
198− Opt.DefineTailFunc argNames body deps ->
199− addStmt (addDeps deps state) (
200− let (Opt.Global _ name) = global in
201− var global (Expr.generateTailDef mode name argNames body)
202− )
203−
204− Opt.Ctor index arity ->
205− addStmt state (
206− var global (Expr.generateCtor mode global index arity)
207− )
208−
209− Opt.Link linkedGlobal ->
210− addGlobal mode graph state linkedGlobal
211−
212− Opt.Cycle names values functions deps ->
213− addStmt (addDeps deps state) (
214− generateCycle mode global names values functions
215− )
216−
217− Opt.Manager effectsType ->
218− generateManager mode graph global effectsType state
219−
220− Opt.Kernel chunks deps ->
221− if isDebugger global && not (Mode.isDebug mode) then
222− state
223− else
224− addKernel (addDeps deps state) (generateKernel mode chunks)
225−
226− Opt.Enum index ->
227− addStmt state (
228− generateEnum mode global index
229− )
230−
231− Opt.Box ->
232− addStmt (addGlobal mode graph state identity) (
233− generateBox mode global
234− )
235−
236− Opt.PortIncoming decoder deps ->
237− addStmt (addDeps deps state) (
238− generatePort mode global "incomingPort" decoder
239− )
240−
241− Opt.PortOutgoing encoder deps ->
242− addStmt (addDeps deps state) (
243− generatePort mode global "outgoingPort" encoder
244− )
245−
246−
247−addStmt :: State -> JS.Stmt -> State
248−addStmt state stmt =
249− addBuilder state (JS.stmtToBuilder stmt)
250−
251−
252−addBuilder :: State -> B.Builder -> State
253−addBuilder (State revKernels revBuilders seen) builder =
254− State revKernels (builder:revBuilders) seen
255−
256−
257−addKernel :: State -> B.Builder -> State
258−addKernel (State revKernels revBuilders seen) kernel =
259− State (kernel:revKernels) revBuilders seen
260−
261−
262−var :: Opt.Global -> Expr.Code -> JS.Stmt
263−var (Opt.Global home name) code =
264− JS.Var (JsName.fromGlobal home name) (Expr.codeToExpr code)
265−
266−
267−isDebugger :: Opt.Global -> Bool
268−isDebugger (Opt.Global (ModuleName.Canonical _ home) _) =
269− home == Name.debugger
270−
271−
272−
273−-- GENERATE CYCLES
274−
275−
276−generateCycle :: Mode.Mode -> Opt.Global -> [Name.Name] -> [(Name.Name, Opt.Expr)] -> [Opt.Def] -> JS.Stmt
277−generateCycle mode (Opt.Global home _) names values functions =
278− JS.Block
279− [ JS.Block $ map (generateCycleFunc mode home) functions
280− , JS.Block $ map (generateSafeCycle mode home) values
281− , case map (generateRealCycle home) values of
282− [] ->
283− JS.EmptyStmt
284−
285− realBlock@(_:_) ->
286− case mode of
287− Mode.Prod _ ->
288− JS.Block realBlock
289−
290− Mode.Dev _ ->
291− JS.Try (JS.Block realBlock) JsName.dollar $ JS.Throw $ JS.String $
292− "Some top-level definitions from `" <> Name.toBuilder (ModuleName._module home) <> "` are causing infinite recursion:\\n"
293− <> drawCycle names
294− <> "\\n\\nThese errors are very tricky, so read "
295− <> B.stringUtf8 (D.makeNakedLink "bad-recursion")
296− <> " to learn how to fix it!"
297− ]
298−
299−
300−generateCycleFunc :: Mode.Mode -> ModuleName.Canonical -> Opt.Def -> JS.Stmt
301−generateCycleFunc mode home def =
302− case def of
303− Opt.Def name expr ->
304− JS.Var (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generate mode expr))
305−
306− Opt.TailDef name args expr ->
307− JS.Var (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generateTailDef mode name args expr))
308−
309−
310−generateSafeCycle :: Mode.Mode -> ModuleName.Canonical -> (Name.Name, Opt.Expr) -> JS.Stmt
311−generateSafeCycle mode home (name, expr) =
312− JS.FunctionStmt (JsName.fromCycle home name) [] $
313− Expr.codeToStmtList (Expr.generate mode expr)
314−
315−
316−generateRealCycle :: ModuleName.Canonical -> (Name.Name, expr) -> JS.Stmt
317−generateRealCycle home (name, _) =
318− let
319− safeName = JsName.fromCycle home name
320− realName = JsName.fromGlobal home name
321− in
322− JS.Block
323− [ JS.Var realName (JS.Call (JS.Ref safeName) [])
324− , JS.ExprStmt $ JS.Assign (JS.LRef safeName) $
325− JS.Function Nothing [] [ JS.Return (JS.Ref realName) ]
326− ]
327−
328−
329−drawCycle :: [Name.Name] -> B.Builder
330−drawCycle names =
331− let
332− topLine = "\\n ┌─────┐"
333− nameLine name = "\\n │ " <> Name.toBuilder name
334− midLine = "\\n │ ↓"
335− bottomLine = "\\n └─────┘"
336− in
337− mconcat (topLine : List.intersperse midLine (map nameLine names) ++ [ bottomLine ])
338−
339−
340−
341−-- GENERATE KERNEL
342−
343−
344−generateKernel :: Mode.Mode -> [K.Chunk] -> B.Builder
345−generateKernel mode chunks =
346− List.foldr (addChunk mode) mempty chunks
347−
348−
349−addChunk :: Mode.Mode -> K.Chunk -> B.Builder -> B.Builder
350−addChunk mode chunk builder =
351− case chunk of
352− K.JS javascript ->
353− B.byteString javascript <> builder
354−
355− K.ElmVar home name ->
356− JsName.toBuilder (JsName.fromGlobal home name) <> builder
357−
358− K.JsVar home name ->
359− JsName.toBuilder (JsName.fromKernel home name) <> builder
360−
361− K.ElmField name ->
362− JsName.toBuilder (Expr.generateField mode name) <> builder
363−
364− K.JsField int ->
365− JsName.toBuilder (JsName.fromInt int) <> builder
366−
367− K.JsEnum int ->
368− B.intDec int <> builder
369−
370− K.Debug ->
371− case mode of
372− Mode.Dev _ ->
373− builder
374−
375− Mode.Prod _ ->
376− "_UNUSED" <> builder
377−
378− K.Prod ->
379− case mode of
380− Mode.Dev _ ->
381− "_UNUSED" <> builder
382−
383− Mode.Prod _ ->
384− builder
385−
386−
387−
388−-- GENERATE ENUM
389−
390−
391−generateEnum :: Mode.Mode -> Opt.Global -> Index.ZeroBased -> JS.Stmt
392−generateEnum mode global@(Opt.Global home name) index =
393− JS.Var (JsName.fromGlobal home name) $
394− case mode of
395− Mode.Dev _ ->
396− Expr.codeToExpr (Expr.generateCtor mode global index 0)
397−
398− Mode.Prod _ ->
399− JS.Int (Index.toMachine index)
400−
401−
402−
403−-- GENERATE BOX
404−
405−
406−generateBox :: Mode.Mode -> Opt.Global -> JS.Stmt
407−generateBox mode global@(Opt.Global home name) =
408− JS.Var (JsName.fromGlobal home name) $
409− case mode of
410− Mode.Dev _ ->
411− Expr.codeToExpr (Expr.generateCtor mode global Index.first 1)
412−
413− Mode.Prod _ ->
414− JS.Ref (JsName.fromGlobal ModuleName.basics Name.identity)
415−
416−
417−{-# NOINLINE identity #-}
418−identity :: Opt.Global
419−identity =
420− Opt.Global ModuleName.basics Name.identity
421−
422−
423−
424−-- GENERATE PORTS
425−
426−
427−generatePort :: Mode.Mode -> Opt.Global -> Name.Name -> Opt.Expr -> JS.Stmt
428−generatePort mode (Opt.Global home name) makePort converter =
429− JS.Var (JsName.fromGlobal home name) $
430− JS.Call (JS.Ref (JsName.fromKernel Name.platform makePort))
431− [ JS.String (Name.toBuilder name)
432− , Expr.codeToExpr (Expr.generate mode converter)
433− ]
434−
435−
436−
437−-- GENERATE MANAGER
438−
439−
440−generateManager :: Mode.Mode -> Graph -> Opt.Global -> Opt.EffectsType -> State -> State
441−generateManager mode graph (Opt.Global home@(ModuleName.Canonical _ moduleName) _) effectsType state =
442− let
443− managerLVar =
444− JS.LBracket
445− (JS.Ref (JsName.fromKernel Name.platform "effectManagers"))
446− (JS.String (Name.toBuilder moduleName))
447−
448− (deps, args, stmts) =
449− generateManagerHelp home effectsType
450−
451− createManager =
452− JS.ExprStmt $ JS.Assign managerLVar $
453− JS.Call (JS.Ref (JsName.fromKernel Name.platform "createManager")) args
454− in
455− addStmt (List.foldl' (addGlobal mode graph) state deps) $
456− JS.Block (createManager : stmts)
457−
458−
459−generateLeaf :: ModuleName.Canonical -> Name.Name -> JS.Stmt
460−generateLeaf home@(ModuleName.Canonical _ moduleName) name =
461− JS.Var (JsName.fromGlobal home name) $
462− JS.Call leaf [ JS.String (Name.toBuilder moduleName) ]
463−
464−
465−
466−{-# NOINLINE leaf #-}
467−leaf :: JS.Expr
468−leaf =
469− JS.Ref (JsName.fromKernel Name.platform "leaf")
470−
471−
472−generateManagerHelp :: ModuleName.Canonical -> Opt.EffectsType -> ([Opt.Global], [JS.Expr], [JS.Stmt])
473−generateManagerHelp home effectsType =
474− let
475− dep name = Opt.Global home name
476− ref name = JS.Ref (JsName.fromGlobal home name)
477− in
478− case effectsType of
479− Opt.Cmd ->
480− ( [ dep "init", dep "onEffects", dep "onSelfMsg", dep "cmdMap" ]
481− , [ ref "init", ref "onEffects", ref "onSelfMsg", ref "cmdMap" ]
482− , [ generateLeaf home "command" ]
483− )
484−
485− Opt.Sub ->
486− ( [ dep "init", dep "onEffects", dep "onSelfMsg", dep "subMap" ]
487− , [ ref "init", ref "onEffects", ref "onSelfMsg", JS.Int 0, ref "subMap" ]
488− , [ generateLeaf home "subscription" ]
489− )
490−
491− Opt.Fx ->
492− ( [ dep "init", dep "onEffects", dep "onSelfMsg", dep "cmdMap", dep "subMap" ]
493− , [ ref "init", ref "onEffects", ref "onSelfMsg", ref "cmdMap", ref "subMap" ]
494− , [ generateLeaf home "command"
495− , generateLeaf home "subscription"
496− ]
497− )
498−
499−
500−
501−-- MAIN EXPORTS
502−
503−
504−toMainExports :: Mode.Mode -> Mains -> B.Builder
505−toMainExports mode mains =
506− let
507− export = JsName.fromKernel Name.platform "export"
508− exports = generateExports mode (Map.foldrWithKey addToTrie emptyTrie mains)
509− in
510− JsName.toBuilder export <> "(" <> exports <> ");"
511−
512−
513−generateExports :: Mode.Mode -> Trie -> B.Builder
514−generateExports mode (Trie maybeMain subs) =
515− let
516− starter end =
517− case maybeMain of
518− Nothing ->
519− "{"
520−
521− Just (home, main) ->
522− "{'init':"
523− <> JS.exprToBuilder (Expr.generateMain mode home main)
524− <> end
525− in
526− case Map.toList subs of
527− [] ->
528− starter "" <> "}"
529−
530− (name, subTrie) : otherSubTries ->
531− starter "," <>
532− "'" <> Utf8.toBuilder name <> "':"
533− <> generateExports mode subTrie
534− <> List.foldl' (addSubTrie mode) "}" otherSubTries
535−
536−
537−addSubTrie :: Mode.Mode -> B.Builder -> (Name.Name, Trie) -> B.Builder
538−addSubTrie mode end (name, trie) =
539− ",'" <> Utf8.toBuilder name <> "':" <> generateExports mode trie <> end
540−
541−
542−
543−-- BUILD TRIES
544−
545−
546−data Trie =
547− Trie
548− { _main :: Maybe (ModuleName.Canonical, Opt.Main)
549− , _subs :: Map.Map Name.Name Trie
550− }
551−
552−
553−emptyTrie :: Trie
554−emptyTrie =
555− Trie Nothing Map.empty
556−
557−
558−addToTrie :: ModuleName.Canonical -> Opt.Main -> Trie -> Trie
559−addToTrie home@(ModuleName.Canonical _ moduleName) main trie =
560− merge trie $ segmentsToTrie home (Name.splitDots moduleName) main
561−
562−
563−segmentsToTrie :: ModuleName.Canonical -> [Name.Name] -> Opt.Main -> Trie
564−segmentsToTrie home segments main =
565− case segments of
566− [] ->
567− Trie (Just (home, main)) Map.empty
568−
569− segment : otherSegments ->
570− Trie Nothing (Map.singleton segment (segmentsToTrie home otherSegments main))
571−
572−
573−merge :: Trie -> Trie -> Trie
574−merge (Trie main1 subs1) (Trie main2 subs2) =
575− Trie
576− (checkedMerge main1 main2)
577− (Map.unionWith merge subs1 subs2)
578−
579−
580−checkedMerge :: Maybe a -> Maybe a -> Maybe a
581−checkedMerge a b =
582− case (a, b) of
583− (Nothing, main) ->
584− main
585−
586− (main, Nothing) ->
587− main
588−
589− (Just _, Just _) ->
590− error "cannot have two modules with the same name"
compiler/src/Generate/JavaScript/Builder.hsdeleted−530
@@ -1,530 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Generate.JavaScript.Builder
4− ( stmtToBuilder
5− , exprToBuilder
6− , Expr(..), LValue(..)
7− , Stmt(..), Case(..)
8− , InfixOp(..), PrefixOp(..)
9− )
10− where
11−
12−-- Based on the language-ecmascript package.
13−-- https://hackage.haskell.org/package/language-ecmascript
14−-- They did the hard work of reading the spec to figure out
15−-- how all the types should fit together.
16−
17−import Prelude hiding (lines)
18−import qualified Data.List as List
19−import qualified Data.ByteString as BS
20−import Data.ByteString.Builder as B
21−import Data.Monoid ((<>))
22−import qualified Generate.JavaScript.Name as Name
23−import Generate.JavaScript.Name (Name)
24−import qualified Json.Encode as Json
25−
26−
27−
28−-- EXPRESSIONS
29−
30−
31−-- NOTE: I tried making this create a B.Builder directly.
32−--
33−-- The hope was that it'd allocate less and speed things up, but it seemed
34−-- to be neutral for perf.
35−--
36−-- The downside is that Generate.JavaScript.Expression inspects the
37−-- structure of Expr and Stmt on some occassions to try to strip out
38−-- unnecessary closures. I think these closures are already avoided
39−-- by other logic in code gen these days, but I am not 100% certain.
40−--
41−-- For this to be worth it, I think it would be necessary to avoid
42−-- returning tuples when generating expressions.
43−--
44−data Expr
45− = String Builder
46− | Float Builder
47− | Int Int
48− | Bool Bool
49− | Null
50− | Json Json.Value
51− | Array [Expr]
52− | Object [(Name, Expr)]
53− | Ref Name
54− | Access Expr Name -- foo.bar
55− | Index Expr Expr -- foo[bar]
56− | Prefix PrefixOp Expr
57− | Infix InfixOp Expr Expr
58− | If Expr Expr Expr
59− | Assign LValue Expr
60− | Call Expr [Expr]
61− | Function (Maybe Name) [Name] [Stmt]
62−
63−
64−data LValue
65− = LRef Name
66− | LDot Expr Name
67− | LBracket Expr Expr
68−
69−
70−
71−-- STATEMENTS
72−
73−
74−data Stmt
75− = Block [Stmt]
76− | EmptyStmt
77− | ExprStmt Expr
78− | IfStmt Expr Stmt Stmt
79− | Switch Expr [Case]
80− | While Expr Stmt
81− | Break (Maybe Name)
82− | Continue (Maybe Name)
83− | Labelled Name Stmt
84− | Try Stmt Name Stmt
85− | Throw Expr
86− | Return Expr
87− | Var Name Expr
88− | Vars [(Name, Expr)]
89− | FunctionStmt Name [Name] [Stmt]
90−
91−
92−data Case
93− = Case Expr [Stmt]
94− | Default [Stmt]
95−
96−
97−
98−-- OPERATORS
99−
100−
101−data InfixOp
102− = OpAdd -- +
103− | OpSub -- -
104− | OpMul -- *
105− | OpDiv -- /
106− | OpMod -- %
107− | OpEq -- ===
108− | OpNe -- !==
109− | OpLt -- <
110− | OpLe -- <=
111− | OpGt -- >
112− | OpGe -- >=
113− | OpAnd -- &&
114− | OpOr -- ||
115− | OpBitwiseAnd -- &
116− | OpBitwiseXor -- ^
117− | OpBitwiseOr -- |
118− | OpLShift -- <<
119− | OpSpRShift -- >>
120− | OpZfRShift -- >>>
121−
122−
123−data PrefixOp
124− = PrefixNot -- !
125− | PrefixNegate -- -
126− | PrefixComplement -- ~
127−
128−
129−
130−-- ENCODE
131−
132−
133−stmtToBuilder :: Stmt -> Builder
134−stmtToBuilder stmts =
135− fromStmt levelZero stmts
136−
137−
138−exprToBuilder :: Expr -> Builder
139−exprToBuilder expr =
140− snd $ fromExpr levelZero Whatever expr
141−
142−
143−
144−-- INDENT LEVEL
145−
146−
147−data Level =
148− Level Builder Level
149−
150−
151−levelZero :: Level
152−levelZero =
153− Level mempty (makeLevel 1 (BS.replicate 16 0x09 {-\t-}))
154−
155−
156−makeLevel :: Int -> BS.ByteString -> Level
157−makeLevel level oldTabs =
158− let
159− tabs =
160− if level <= BS.length oldTabs
161− then oldTabs
162− else BS.replicate (BS.length oldTabs * 2) 0x09 {-\t-}
163− in
164− Level (B.byteString (BS.take level tabs)) (makeLevel (level + 1) tabs)
165−
166−
167−
168−-- HELPERS
169−
170−
171−commaSep :: [Builder] -> Builder
172−commaSep builders =
173− mconcat (List.intersperse ", " builders)
174−
175−
176−commaNewlineSep :: Level -> [Builder] -> Builder
177−commaNewlineSep (Level _ (Level deeperIndent _)) builders =
178− mconcat (List.intersperse (",\n" <> deeperIndent) builders)
179−
180−
181−
182−-- STATEMENTS
183−
184−
185−fromStmtBlock :: Level -> [Stmt] -> Builder
186−fromStmtBlock level stmts =
187− mconcat (map (fromStmt level) stmts)
188−
189−
190−fromStmt :: Level -> Stmt -> Builder
191−fromStmt level@(Level indent nextLevel) statement =
192− case statement of
193− Block stmts ->
194− fromStmtBlock level stmts
195−
196− EmptyStmt ->
197− mempty
198−
199− ExprStmt expr ->
200− indent <> snd (fromExpr level Whatever expr) <> ";\n"
201−
202− IfStmt condition thenStmt elseStmt ->
203− mconcat
204− [ indent, "if (", snd (fromExpr level Whatever condition), ") {\n"
205− , fromStmt nextLevel thenStmt
206− , indent, "} else {\n"
207− , fromStmt nextLevel elseStmt
208− , indent, "}\n"
209− ]
210−
211− Switch expr clauses ->
212− mconcat
213− [ indent, "switch (", snd (fromExpr level Whatever expr), ") {\n"
214− , mconcat (map (fromClause nextLevel) clauses)
215− , indent, "}\n"
216− ]
217−
218− While expr stmt ->
219− mconcat
220− [ indent, "while (", snd (fromExpr level Whatever expr), ") {\n"
221− , fromStmt nextLevel stmt
222− , indent, "}\n"
223− ]
224−
225− Break Nothing ->
226− indent <> "break;\n"
227−
228− Break (Just label) ->
229− indent <> "break " <> Name.toBuilder label <> ";\n"
230−
231− Continue Nothing ->
232− indent <> "continue;\n"
233−
234− Continue (Just label) ->
235− indent <> "continue " <> Name.toBuilder label <> ";\n"
236−
237− Labelled label stmt ->
238− mconcat
239− [ indent, Name.toBuilder label, ":\n"
240− , fromStmt level stmt
241− ]
242−
243− Try tryStmt errorName catchStmt ->
244− mconcat
245− [ indent, "try {\n"
246− , fromStmt nextLevel tryStmt
247− , indent, "} catch (", Name.toBuilder errorName, ") {\n"
248− , fromStmt nextLevel catchStmt
249− , indent, "}\n"
250− ]
251−
252− Throw expr ->
253− indent <> "throw " <> snd (fromExpr level Whatever expr) <> ";"
254−
255− Return expr ->
256− indent <> "return " <> snd (fromExpr level Whatever expr) <> ";\n"
257−
258− Var name expr ->
259− indent <> "var " <> Name.toBuilder name <> " = " <> snd (fromExpr level Whatever expr) <> ";\n"
260−
261− Vars [] ->
262− mempty
263−
264− Vars vars ->
265− indent <> "var " <> commaNewlineSep level (map (varToBuilder level) vars) <> ";\n"
266−
267− FunctionStmt name args stmts ->
268− indent <> "function " <> Name.toBuilder name <> "(" <> commaSep (map Name.toBuilder args) <> ") {\n"
269− <>
270− fromStmtBlock nextLevel stmts
271− <>
272− indent <> "}\n"
273−
274−
275−
276−-- SWITCH CLAUSES
277−
278−
279−fromClause :: Level -> Case -> Builder
280−fromClause level@(Level indent nextLevel) clause =
281− case clause of
282− Case expr stmts ->
283− indent <> "case " <> snd (fromExpr level Whatever expr) <> ":\n"
284− <> fromStmtBlock nextLevel stmts
285−
286− Default stmts ->
287− indent <> "default:\n"
288− <> fromStmtBlock nextLevel stmts
289−
290−
291−
292−-- VAR DECLS
293−
294−
295−varToBuilder :: Level -> (Name, Expr) -> Builder
296−varToBuilder level (name, expr) =
297− Name.toBuilder name <> " = " <> snd (fromExpr level Whatever expr)
298−
299−
300−
301−-- EXPRESSIONS
302−
303−
304−data Lines = One | Many deriving (Eq)
305−
306−
307−merge :: Lines -> Lines -> Lines
308−merge a b =
309− if a == Many || b == Many then Many else One
310−
311−
312−linesMap :: (a -> (Lines, b)) -> [a] -> (Bool, [b])
313−linesMap func xs =
314− let
315− pairs = map func xs
316− in
317− ( any ((==) Many . fst) pairs
318− , map snd pairs
319− )
320−
321−
322−data Grouping = Atomic | Whatever
323−
324−
325−parensFor :: Grouping -> Builder -> Builder
326−parensFor grouping builder =
327− case grouping of
328− Atomic ->
329− "(" <> builder <> ")"
330−
331− Whatever ->
332− builder
333−
334−
335−fromExpr :: Level -> Grouping -> Expr -> (Lines, Builder)
336−fromExpr level@(Level indent nextLevel@(Level deeperIndent _)) grouping expression =
337− case expression of
338− String string ->
339− ( One, "'" <> string <> "'" )
340−
341− Float float ->
342− ( One, float )
343−
344− Int n ->
345− ( One, B.intDec n )
346−
347− Bool bool ->
348− ( One, if bool then "true" else "false" )
349−
350− Null ->
351− ( One, "null" )
352−
353− Json json ->
354− ( One, Json.encodeUgly json )
355−
356− Array exprs ->
357− (,) Many $
358− let
359− (anyMany, builders) = linesMap (fromExpr level Whatever) exprs
360− in
361− if anyMany then
362− "[\n"
363− <> deeperIndent
364− <> commaNewlineSep level builders
365− <> "\n" <> indent <> "]"
366− else
367− "[" <> commaSep builders <> "]"
368−
369− Object fields ->
370− (,) Many $
371− let
372− (anyMany, builders) = linesMap (fromField nextLevel) fields
373− in
374− if anyMany then
375− "{\n"
376− <> deeperIndent
377− <> commaNewlineSep level builders
378− <> "\n" <> indent <> "}"
379− else
380− "{" <> commaSep builders <> "}"
381−
382− Ref name ->
383− ( One, Name.toBuilder name )
384−
385− Access expr field ->
386− makeDot level expr field
387−
388− Index expr bracketedExpr ->
389− makeBracketed level expr bracketedExpr
390−
391− Prefix op expr ->
392− let
393− (lines, builder) = fromExpr level Atomic expr
394− in
395− ( lines
396− , parensFor grouping (fromPrefix op <> builder)
397− )
398−
399− Infix op leftExpr rightExpr ->
400− let
401− (leftLines , left ) = fromExpr level Atomic leftExpr
402− (rightLines, right) = fromExpr level Atomic rightExpr
403− in
404− ( merge leftLines rightLines
405− , parensFor grouping (left <> fromInfix op <> right)
406− )
407−
408− If condExpr thenExpr elseExpr ->
409− let
410− condB = snd (fromExpr level Atomic condExpr)
411− thenB = snd (fromExpr level Atomic thenExpr)
412− elseB = snd (fromExpr level Atomic elseExpr)
413− in
414− ( Many
415− , parensFor grouping (condB <> " ? " <> thenB <> " : " <> elseB)
416− )
417−
418− Assign lValue expr ->
419− let
420− (leftLines , left ) = fromLValue level lValue
421− (rightLines, right) = fromExpr level Whatever expr
422− in
423− ( merge leftLines rightLines
424− , parensFor grouping (left <> " = " <> right)
425− )
426−
427− Call function args ->
428− (,) Many $
429− let
430− (_ , funcB) = fromExpr level Atomic function
431− (anyMany, argsB) = linesMap (fromExpr nextLevel Whatever) args
432− in
433− if anyMany then
434− funcB <> "(\n" <> deeperIndent <> commaNewlineSep level argsB <> ")"
435− else
436− funcB <> "(" <> commaSep argsB <> ")"
437−
438− Function maybeName args stmts ->
439− (,) Many $
440− "function " <> maybe mempty Name.toBuilder maybeName <> "(" <> commaSep (map Name.toBuilder args) <> ") {\n"
441− <>
442− fromStmtBlock nextLevel stmts
443− <>
444− indent <> "}"
445−
446−
447−
448−-- FIELDS
449−
450−
451−fromField :: Level -> (Name, Expr) -> (Lines, Builder)
452−fromField level (field, expr) =
453− let
454− (lines, builder) = fromExpr level Whatever expr
455− in
456− ( lines
457− , Name.toBuilder field <> ": " <> builder
458− )
459−
460−
461−
462−-- VALUES
463−
464−
465−fromLValue :: Level -> LValue -> (Lines, Builder)
466−fromLValue level lValue =
467− case lValue of
468− LRef name ->
469− (One, Name.toBuilder name)
470−
471− LDot expr field ->
472− makeDot level expr field
473−
474− LBracket expr bracketedExpr ->
475− makeBracketed level expr bracketedExpr
476−
477−
478−makeDot :: Level -> Expr -> Name -> (Lines, Builder)
479−makeDot level expr field =
480− let
481− (lines, builder) = fromExpr level Atomic expr
482− in
483− (lines, builder <> "." <> Name.toBuilder field)
484−
485−
486−makeBracketed :: Level -> Expr -> Expr -> (Lines, Builder)
487−makeBracketed level expr bracketedExpr =
488− let
489− (lines , builder ) = fromExpr level Atomic expr
490− (bracketedLines, bracketedBuilder) = fromExpr level Whatever bracketedExpr
491− in
492− ( merge lines bracketedLines
493− , builder <> "[" <> bracketedBuilder <> "]"
494− )
495−
496−
497−
498−-- OPERATORS
499−
500−
501−fromPrefix :: PrefixOp -> Builder
502−fromPrefix op =
503− case op of
504− PrefixNot -> "!"
505− PrefixNegate -> "-"
506− PrefixComplement -> "~"
507−
508−
509−fromInfix :: InfixOp -> Builder
510−fromInfix op =
511− case op of
512− OpAdd -> " + "
513− OpSub -> " - "
514− OpMul -> " * "
515− OpDiv -> " / "
516− OpMod -> " % "
517− OpEq -> " === "
518− OpNe -> " !== "
519− OpLt -> " < "
520− OpLe -> " <= "
521− OpGt -> " > "
522− OpGe -> " >= "
523− OpAnd -> " && "
524− OpOr -> " || "
525− OpBitwiseAnd -> " & "
526− OpBitwiseXor -> " ^ "
527− OpBitwiseOr -> " | "
528− OpLShift -> " << "
529− OpSpRShift -> " >> "
530− OpZfRShift -> " >>> "
compiler/src/Generate/JavaScript/Functions.hsdeleted−95
@@ -1,95 +0,0 @@
1−{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
2−module Generate.JavaScript.Functions
3− ( functions
4− )
5− where
6−
7−
8−import qualified Data.ByteString.Builder as B
9−import Text.RawString.QQ (r)
10−
11−
12−
13−-- FUNCTIONS
14−
15−
16−functions :: B.Builder
17−functions = [r|
18−
19−function F(arity, fun, wrapper) {
20− wrapper.a = arity;
21− wrapper.f = fun;
22− return wrapper;
23−}
24−
25−function F2(fun) {
26− return F(2, fun, function(a) { return function(b) { return fun(a,b); }; })
27−}
28−function F3(fun) {
29− return F(3, fun, function(a) {
30− return function(b) { return function(c) { return fun(a, b, c); }; };
31− });
32−}
33−function F4(fun) {
34− return F(4, fun, function(a) { return function(b) { return function(c) {
35− return function(d) { return fun(a, b, c, d); }; }; };
36− });
37−}
38−function F5(fun) {
39− return F(5, fun, function(a) { return function(b) { return function(c) {
40− return function(d) { return function(e) { return fun(a, b, c, d, e); }; }; }; };
41− });
42−}
43−function F6(fun) {
44− return F(6, fun, function(a) { return function(b) { return function(c) {
45− return function(d) { return function(e) { return function(f) {
46− return fun(a, b, c, d, e, f); }; }; }; }; };
47− });
48−}
49−function F7(fun) {
50− return F(7, fun, function(a) { return function(b) { return function(c) {
51− return function(d) { return function(e) { return function(f) {
52− return function(g) { return fun(a, b, c, d, e, f, g); }; }; }; }; }; };
53− });
54−}
55−function F8(fun) {
56− return F(8, fun, function(a) { return function(b) { return function(c) {
57− return function(d) { return function(e) { return function(f) {
58− return function(g) { return function(h) {
59− return fun(a, b, c, d, e, f, g, h); }; }; }; }; }; }; };
60− });
61−}
62−function F9(fun) {
63− return F(9, fun, function(a) { return function(b) { return function(c) {
64− return function(d) { return function(e) { return function(f) {
65− return function(g) { return function(h) { return function(i) {
66− return fun(a, b, c, d, e, f, g, h, i); }; }; }; }; }; }; }; };
67− });
68−}
69−
70−function A2(fun, a, b) {
71− return fun.a === 2 ? fun.f(a, b) : fun(a)(b);
72−}
73−function A3(fun, a, b, c) {
74− return fun.a === 3 ? fun.f(a, b, c) : fun(a)(b)(c);
75−}
76−function A4(fun, a, b, c, d) {
77− return fun.a === 4 ? fun.f(a, b, c, d) : fun(a)(b)(c)(d);
78−}
79−function A5(fun, a, b, c, d, e) {
80− return fun.a === 5 ? fun.f(a, b, c, d, e) : fun(a)(b)(c)(d)(e);
81−}
82−function A6(fun, a, b, c, d, e, f) {
83− return fun.a === 6 ? fun.f(a, b, c, d, e, f) : fun(a)(b)(c)(d)(e)(f);
84−}
85−function A7(fun, a, b, c, d, e, f, g) {
86− return fun.a === 7 ? fun.f(a, b, c, d, e, f, g) : fun(a)(b)(c)(d)(e)(f)(g);
87−}
88−function A8(fun, a, b, c, d, e, f, g, h) {
89− return fun.a === 8 ? fun.f(a, b, c, d, e, f, g, h) : fun(a)(b)(c)(d)(e)(f)(g)(h);
90−}
91−function A9(fun, a, b, c, d, e, f, g, h, i) {
92− return fun.a === 9 ? fun.f(a, b, c, d, e, f, g, h, i) : fun(a)(b)(c)(d)(e)(f)(g)(h)(i);
93−}
94−
95−|]
compiler/src/Generate/Mode.hsdeleted−63
@@ -1,63 +0,0 @@
1−module Generate.Mode
2− ( Mode(..)
3− , isDebug
4− , ShortFieldNames
5− , shortenFieldNames
6− )
7− where
8−
9−
10−import qualified Data.List as List
11−import qualified Data.Map as Map
12−import qualified Data.Maybe as Maybe
13−import qualified Data.Name as Name
14−
15−import qualified AST.Optimized as Opt
16−import qualified Elm.Compiler.Type.Extract as Extract
17−import qualified Generate.JavaScript.Name as JsName
18−
19−
20−
21−-- MODE
22−
23−
24−data Mode
25− = Dev (Maybe Extract.Types)
26− | Prod ShortFieldNames
27−
28−
29−isDebug :: Mode -> Bool
30−isDebug mode =
31− case mode of
32− Dev mi -> Maybe.isJust mi
33− Prod _ -> False
34−
35−
36−
37−-- SHORTEN FIELD NAMES
38−
39−
40−type ShortFieldNames =
41− Map.Map Name.Name JsName.Name
42−
43−
44−shortenFieldNames :: Opt.GlobalGraph -> ShortFieldNames
45−shortenFieldNames (Opt.GlobalGraph _ frequencies) =
46− Map.foldr addToShortNames Map.empty $
47− Map.foldrWithKey addToBuckets Map.empty frequencies
48−
49−
50−addToBuckets :: Name.Name -> Int -> Map.Map Int [Name.Name] -> Map.Map Int [Name.Name]
51−addToBuckets field frequency buckets =
52− Map.insertWith (++) frequency [field] buckets
53−
54−
55−addToShortNames :: [Name.Name] -> ShortFieldNames -> ShortFieldNames
56−addToShortNames fields shortNames =
57− List.foldl' addField shortNames fields
58−
59−
60−addField :: ShortFieldNames -> Name.Name -> ShortFieldNames
61−addField shortNames field =
62− let rename = JsName.fromInt (Map.size shortNames) in
63− Map.insert field rename shortNames
compiler/src/Json/Decode.hsdeleted−799
@@ -1,799 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing #-}
2−{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings, UnboxedTuples #-}
3−module Json.Decode
4− ( fromByteString
5− , Decoder
6− , string
7− , customString
8− , bool
9− , int
10− , list
11− , nonEmptyList
12− , pair
13− --
14− , KeyDecoder(..)
15− , dict
16− , pairs
17− , field
18− --
19− , oneOf
20− , failure
21− , mapError
22− --
23− , Error(..)
24− , Problem(..)
25− , DecodeExpectation(..)
26− , ParseError(..)
27− , StringProblem(..)
28− )
29− where
30−
31−
32−import qualified Data.ByteString.Internal as B
33−import qualified Data.Map as Map
34−import qualified Data.NonEmptyList as NE
35−import Data.Word (Word8)
36−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
37−import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
38−
39−import qualified Json.String as Json
40−import qualified Parse.Keyword as K
41−import qualified Parse.Primitives as P
42−import Parse.Primitives (Row, Col)
43−import qualified Reporting.Annotation as A
44−
45−
46−
47−-- RUNNERS
48−
49−
50−fromByteString :: Decoder x a -> B.ByteString -> Either (Error x) a
51−fromByteString (Decoder decode) src =
52− case P.fromByteString pFile BadEnd src of
53− Right ast ->
54− decode ast Right (Left . DecodeProblem src)
55−
56− Left problem ->
57− Left (ParseProblem src problem)
58−
59−
60−
61−-- DECODERS
62−
63−
64−newtype Decoder x a =
65− Decoder
66− (
67− forall b.
68− AST
69− -> (a -> b)
70− -> (Problem x -> b)
71− -> b
72− )
73−
74−
75−
76−-- ERRORS
77−
78−
79−data Error x
80− = DecodeProblem B.ByteString (Problem x)
81− | ParseProblem B.ByteString ParseError
82−
83−
84−
85−-- DECODE PROBLEMS
86−
87−
88−data Problem x
89− = Field B.ByteString (Problem x)
90− | Index Int (Problem x)
91− | OneOf (Problem x) [Problem x]
92− | Failure A.Region x
93− | Expecting A.Region DecodeExpectation
94−
95−
96−data DecodeExpectation
97− = TObject
98− | TArray
99− | TString
100− | TBool
101− | TInt
102− | TObjectWith B.ByteString
103− | TArrayPair Int
104−
105−
106−
107−-- INSTANCES
108−
109−
110−instance Functor (Decoder x) where
111− {-# INLINE fmap #-}
112− fmap func (Decoder decodeA) =
113− Decoder $ \ast ok err ->
114− let
115− ok' a = ok (func a)
116− in
117− decodeA ast ok' err
118−
119−
120−instance Applicative (Decoder x) where
121− {-# INLINE pure #-}
122− pure = return
123−
124− {-# INLINE (<*>) #-}
125− (<*>) (Decoder decodeFunc) (Decoder decodeArg) =
126− Decoder $ \ast ok err ->
127− let
128− okF func =
129− let
130− okA arg = ok (func arg)
131− in
132− decodeArg ast okA err
133− in
134− decodeFunc ast okF err
135−
136−
137−instance Monad (Decoder x) where
138− {-# INLINE return #-}
139− return a =
140− Decoder $ \_ ok _ ->
141− ok a
142−
143− {-# INLINE (>>=) #-}
144− (>>=) (Decoder decodeA) callback =
145− Decoder $ \ast ok err ->
146− let
147− ok' a =
148− case callback a of
149− Decoder decodeB -> decodeB ast ok err
150− in
151− decodeA ast ok' err
152−
153−
154−
155−-- STRINGS
156−
157−
158−string :: Decoder x Json.String
159−string =
160− Decoder $ \(A.At region ast) ok err ->
161− case ast of
162− String snippet ->
163− ok (Json.fromSnippet snippet)
164−
165− _ ->
166− err (Expecting region TString)
167−
168−
169−customString :: P.Parser x a -> (Row -> Col -> x) -> Decoder x a
170−customString parser toBadEnd =
171− Decoder $ \(A.At region ast) ok err ->
172− case ast of
173− String snippet ->
174− case P.fromSnippet parser toBadEnd snippet of
175− Right a -> ok a
176− Left x -> err (Failure region x)
177−
178− _ ->
179− err (Expecting region TString)
180−
181−
182−
183−-- BOOL
184−
185−
186−bool :: Decoder x Bool
187−bool =
188− Decoder $ \(A.At region ast) ok err ->
189− case ast of
190− TRUE ->
191− ok True
192−
193− FALSE ->
194− ok False
195−
196− _ ->
197− err (Expecting region TBool)
198−
199−
200−
201−-- INT
202−
203−
204−int :: Decoder x Int
205−int =
206− Decoder $ \(A.At region ast) ok err ->
207− case ast of
208− Int n ->
209− ok n
210−
211− _ ->
212− err (Expecting region TInt)
213−
214−
215−
216−-- LISTS
217−
218−
219−list :: Decoder x a -> Decoder x [a]
220−list decoder =
221− Decoder $ \(A.At region ast) ok err ->
222− case ast of
223− Array asts ->
224− listHelp decoder ok err 0 asts []
225−
226− _ ->
227− err (Expecting region TArray)
228−
229−
230−listHelp :: Decoder x a -> ([a] -> b) -> (Problem x -> b) -> Int -> [AST] -> [a] -> b
231−listHelp decoder@(Decoder decodeA) ok err !i asts revs =
232− case asts of
233− [] ->
234− ok (reverse revs)
235−
236− ast:asts ->
237− let
238− ok' value = listHelp decoder ok err (i+1) asts (value:revs)
239− err' prob = err (Index i prob)
240− in
241− decodeA ast ok' err'
242−
243−
244−
245−-- NON-EMPTY LISTS
246−
247−
248−nonEmptyList :: Decoder x a -> x -> Decoder x (NE.List a)
249−nonEmptyList decoder x =
250− do values <- list decoder
251− case values of
252− v:vs -> return (NE.List v vs)
253− [] -> failure x
254−
255−
256−
257−-- PAIR
258−
259−
260−pair :: Decoder x a -> Decoder x b -> Decoder x (a,b)
261−pair (Decoder decodeA) (Decoder decodeB) =
262− Decoder $ \(A.At region ast) ok err ->
263− case ast of
264− Array vs ->
265− case vs of
266− [astA,astB] ->
267− let
268− err0 e = err (Index 0 e)
269− ok0 a =
270− let
271− err1 e = err (Index 1 e)
272− ok1 b = ok (a,b)
273− in
274− decodeB astB ok1 err1
275− in
276− decodeA astA ok0 err0
277−
278− _ ->
279− err (Expecting region (TArrayPair (length vs)))
280−
281− _ ->
282− err (Expecting region TArray)
283−
284−
285−
286−-- OBJECTS
287−
288−
289−data KeyDecoder x a =
290− KeyDecoder (P.Parser x a) (Row -> Col -> x)
291−
292−
293−dict :: (Ord k) => KeyDecoder x k -> Decoder x a -> Decoder x (Map.Map k a)
294−dict keyDecoder valueDecoder =
295− Map.fromList <$> pairs keyDecoder valueDecoder
296−
297−
298−pairs :: KeyDecoder x k -> Decoder x a -> Decoder x [(k, a)]
299−pairs keyDecoder valueDecoder =
300− Decoder $ \(A.At region ast) ok err ->
301− case ast of
302− Object kvs ->
303− pairsHelp keyDecoder valueDecoder ok err kvs []
304−
305− _ ->
306− err (Expecting region TObject)
307−
308−
309−pairsHelp :: KeyDecoder x k -> Decoder x a -> ([(k, a)] -> b) -> (Problem x -> b) -> [(P.Snippet, AST)] -> [(k, a)] -> b
310−pairsHelp keyDecoder@(KeyDecoder keyParser toBadEnd) valueDecoder@(Decoder decodeA) ok err kvs revs =
311− case kvs of
312− [] ->
313− ok (reverse revs)
314−
315− (snippet, ast) : kvs ->
316− case P.fromSnippet keyParser toBadEnd snippet of
317− Left x ->
318− err (Failure (snippetToRegion snippet) x)
319−
320− Right key ->
321− let
322− ok' value = pairsHelp keyDecoder valueDecoder ok err kvs ((key,value):revs)
323− err' prob =
324− let (P.Snippet fptr off len _ _) = snippet in
325− err (Field (B.PS fptr off len) prob)
326− in
327− decodeA ast ok' err'
328−
329−
330−snippetToRegion :: P.Snippet -> A.Region
331−snippetToRegion (P.Snippet _ _ len row col) =
332− A.Region (A.Position row col) (A.Position row (col + fromIntegral len))
333−
334−
335−
336−-- FIELDS
337−
338−
339−field :: B.ByteString -> Decoder x a -> Decoder x a
340−field key (Decoder decodeA) =
341− Decoder $ \(A.At region ast) ok err ->
342− case ast of
343− Object kvs ->
344− case findField key kvs of
345− Just value ->
346− let
347− err' prob =
348− err (Field key prob)
349− in
350− decodeA value ok err'
351−
352− Nothing ->
353− err (Expecting region (TObjectWith key))
354−
355− _ ->
356− err (Expecting region TObject)
357−
358−
359−findField :: B.ByteString -> [(P.Snippet, AST)] -> Maybe AST
360−findField key pairs =
361− case pairs of
362− [] ->
363− Nothing
364−
365− (P.Snippet fptr off len _ _, value) : remainingPairs ->
366− if key == B.PS fptr off len
367− then Just value
368− else findField key remainingPairs
369−
370−
371−
372−-- ONE OF
373−
374−
375−oneOf :: [Decoder x a] -> Decoder x a
376−oneOf decoders =
377− Decoder $ \ast ok err ->
378− case decoders of
379− Decoder decodeA : decoders ->
380− let
381− err' e =
382− oneOfHelp ast ok err decoders e []
383− in
384− decodeA ast ok err'
385−
386− [] ->
387− error "Ran into (Json.Decode.oneOf [])"
388−
389−
390−oneOfHelp :: AST -> (a -> b) -> (Problem x -> b) -> [Decoder x a] -> Problem x -> [Problem x] -> b
391−oneOfHelp ast ok err decoders p ps =
392− case decoders of
393− Decoder decodeA : decoders ->
394− let
395− err' p' =
396− oneOfHelp ast ok err decoders p' (p:ps)
397− in
398− decodeA ast ok err'
399−
400− [] ->
401− err (oneOfError [] p ps)
402−
403−
404−oneOfError :: [Problem x] -> Problem x -> [Problem x] -> Problem x
405−oneOfError problems prob ps =
406− case ps of
407− [] ->
408− OneOf prob problems
409−
410− p:ps ->
411− oneOfError (prob:problems) p ps
412−
413−
414−
415−-- FAILURE
416−
417−
418−failure :: x -> Decoder x a
419−failure x =
420− Decoder $ \(A.At region _) _ err ->
421− err (Failure region x)
422−
423−
424−
425−-- ERRORS
426−
427−
428−mapError :: (x -> y) -> Decoder x a -> Decoder y a
429−mapError func (Decoder decodeA) =
430− Decoder $ \ast ok err ->
431− let
432− err' prob = err (mapErrorHelp func prob)
433− in
434− decodeA ast ok err'
435−
436−
437−mapErrorHelp :: (x -> y) -> Problem x -> Problem y
438−mapErrorHelp func problem =
439− case problem of
440− Field k p -> Field k (mapErrorHelp func p)
441− Index i p -> Index i (mapErrorHelp func p)
442− OneOf p ps -> OneOf (mapErrorHelp func p) (map (mapErrorHelp func) ps)
443− Failure r x -> Failure r (func x)
444− Expecting r e -> Expecting r e
445−
446−
447−
448−-- AST
449−
450−
451−type AST =
452− A.Located AST_
453−
454−
455−data AST_
456− = Array [AST]
457− | Object [(P.Snippet, AST)]
458− | String P.Snippet
459− | Int Int
460− | TRUE
461− | FALSE
462− | NULL
463−
464−
465−
466−-- PARSE
467−
468−
469−type Parser a =
470− P.Parser ParseError a
471−
472−
473−data ParseError
474− = Start Row Col
475− | ObjectField Row Col
476− | ObjectColon Row Col
477− | ObjectEnd Row Col
478− | ArrayEnd Row Col
479− | StringProblem StringProblem Row Col
480− | NoLeadingZeros Row Col
481− | NoFloats Row Col
482− | BadEnd Row Col
483−
484−-- PIndex Int ParseError Row Col
485−-- PField Json.String ParseError Row Col
486−
487−
488−data StringProblem
489− = BadStringEnd
490− | BadStringControlChar
491− | BadStringEscapeChar
492− | BadStringEscapeHex
493−
494−
495−
496−-- PARSE AST
497−
498−
499−pFile :: Parser AST
500−pFile =
501− do spaces
502− value <- pValue
503− spaces
504− return value
505−
506−
507−pValue :: Parser AST
508−pValue =
509− P.addLocation $
510− P.oneOf Start
511− [ String <$> pString Start
512− , pObject
513− , pArray
514− , pInt
515− , K.k4 0x74 0x72 0x75 0x65 Start >> return TRUE
516− , K.k5 0x66 0x61 0x6C 0x73 0x65 Start >> return FALSE
517− , K.k4 0x6E 0x75 0x6C 0x6C Start >> return NULL
518− ]
519−
520−
521−
522−-- OBJECT
523−
524−
525−pObject :: Parser AST_
526−pObject =
527− do P.word1 0x7B {- { -} Start
528− spaces
529− P.oneOf ObjectField
530− [ do entry <- pField
531− spaces
532− pObjectHelp [entry]
533− , do P.word1 0x7D {-}-} ObjectEnd
534− return (Object [])
535− ]
536−
537−
538−pObjectHelp :: [(P.Snippet, AST)] -> Parser AST_
539−pObjectHelp revEntries =
540− P.oneOf ObjectEnd
541− [
542− do P.word1 0x2C {-,-} ObjectEnd
543− spaces
544− entry <- pField
545− spaces
546− pObjectHelp (entry:revEntries)
547− ,
548− do P.word1 0x7D {-}-} ObjectEnd
549− return (Object (reverse revEntries))
550− ]
551−
552−
553−pField :: Parser (P.Snippet, AST)
554−pField =
555− do key <- pString ObjectField
556− spaces
557− P.word1 0x3A {-:-} ObjectColon
558− spaces
559− value <- pValue
560− return (key, value)
561−
562−
563−
564−-- ARRAY
565−
566−
567−pArray :: Parser AST_
568−pArray =
569− do P.word1 0x5B {-[-} Start
570− spaces
571− P.oneOf Start
572− [ do entry <- pValue
573− spaces
574− pArrayHelp 1 [entry]
575− , do P.word1 0x5D {-]-} ArrayEnd
576− return (Array [])
577− ]
578−
579−
580−pArrayHelp :: Int -> [AST] -> Parser AST_
581−pArrayHelp !len revEntries =
582− P.oneOf ArrayEnd
583− [
584− do P.word1 0x2C {-,-} ArrayEnd
585− spaces
586− entry <- pValue
587− spaces
588− pArrayHelp (len + 1) (entry:revEntries)
589− ,
590− do P.word1 0x5D {-]-} ArrayEnd
591− return (Array (reverse revEntries))
592− ]
593−
594−
595−
596−-- STRING
597−
598−
599−pString :: (Row -> Col -> ParseError) -> Parser P.Snippet
600−pString start =
601− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
602− if pos < end && P.unsafeIndex pos == 0x22 {-"-} then
603−
604− let
605− !pos1 = plusPtr pos 1
606− !col1 = col + 1
607−
608− (# status, newPos, newRow, newCol #) =
609− pStringHelp pos1 end row col1
610− in
611− case status of
612− GoodString ->
613− let
614− !off = minusPtr pos1 (unsafeForeignPtrToPtr src)
615− !len = minusPtr newPos pos1 - 1
616− !snp = P.Snippet src off len row col1
617− !newState = P.State src newPos end indent newRow newCol
618− in
619− cok snp newState
620−
621− BadString problem ->
622− cerr newRow newCol (StringProblem problem)
623−
624− else
625− eerr row col start
626−
627−
628−data StringStatus
629− = GoodString
630− | BadString StringProblem
631−
632−
633−pStringHelp :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# StringStatus, Ptr Word8, Row, Col #)
634−pStringHelp pos end row col =
635− if pos >= end then
636− (# BadString BadStringEnd, pos, row, col #)
637−
638− else
639− case P.unsafeIndex pos of
640− 0x22 {-"-} ->
641− (# GoodString, plusPtr pos 1, row, col + 1 #)
642−
643− 0x0A {-\n-} ->
644− (# BadString BadStringEnd, pos, row, col #)
645−
646− 0x5C {-\-} ->
647− let !pos1 = plusPtr pos 1 in
648− if pos1 >= end then
649− (# BadString BadStringEnd, pos1, row + 1, col #)
650− else
651− case P.unsafeIndex pos1 of
652− 0x22 {-"-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
653− 0x5C {-\-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
654− 0x2F {-/-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
655− 0x62 {-b-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
656− 0x66 {-f-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
657− 0x6E {-n-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
658− 0x72 {-r-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
659− 0x74 {-t-} -> pStringHelp (plusPtr pos 2) end row (col + 2)
660− 0x75 {-u-} ->
661− let !pos6 = plusPtr pos 6 in
662− if pos6 <= end
663− && isHex (P.unsafeIndex (plusPtr pos 2))
664− && isHex (P.unsafeIndex (plusPtr pos 3))
665− && isHex (P.unsafeIndex (plusPtr pos 4))
666− && isHex (P.unsafeIndex (plusPtr pos 5))
667− then
668− pStringHelp pos6 end row (col + 6)
669− else
670− (# BadString BadStringEscapeHex, pos, row, col #)
671−
672− _ ->
673− (# BadString BadStringEscapeChar, pos, row, col #)
674−
675− word ->
676− if word < 0x20 then
677− (# BadString BadStringControlChar, pos, row, col #)
678− else
679− let !newPos = plusPtr pos (P.getCharWidth word) in
680− pStringHelp newPos end row (col + 1)
681−
682−
683−isHex :: Word8 -> Bool
684−isHex word =
685− 0x30 {-0-} <= word && word <= 0x39 {-9-}
686− || 0x61 {-a-} <= word && word <= 0x66 {-f-}
687− || 0x41 {-A-} <= word && word <= 0x46 {-F-}
688−
689−
690−
691−-- SPACES
692−
693−
694−spaces :: Parser ()
695−spaces =
696− P.Parser $ \state@(P.State src pos end indent row col) cok eok _ _ ->
697− let
698− (# newPos, newRow, newCol #) =
699− eatSpaces pos end row col
700− in
701− if pos == newPos then
702− eok () state
703− else
704− let
705− !newState =
706− P.State src newPos end indent newRow newCol
707− in
708− cok () newState
709−
710−
711−eatSpaces :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# Ptr Word8, Row, Col #)
712−eatSpaces pos end row col =
713− if pos >= end then
714− (# pos, row, col #)
715−
716− else
717− case P.unsafeIndex pos of
718− 0x20 {- -} -> eatSpaces (plusPtr pos 1) end row (col + 1)
719− 0x09 {-\t-} -> eatSpaces (plusPtr pos 1) end row (col + 1)
720− 0x0A {-\n-} -> eatSpaces (plusPtr pos 1) end (row + 1) 1
721− 0x0D {-\r-} -> eatSpaces (plusPtr pos 1) end row col
722− _ ->
723− (# pos, row, col #)
724−
725−
726−
727−-- INTS
728−
729−
730−pInt :: Parser AST_
731−pInt =
732− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
733− if pos >= end then
734− eerr row col Start
735−
736− else
737− let !word = P.unsafeIndex pos in
738− if not (isDecimalDigit word) then
739− eerr row col Start
740−
741− else if word == 0x30 {-0-} then
742−
743− let
744− !pos1 = plusPtr pos 1
745− !newState = P.State src pos1 end indent row (col + 1)
746− in
747− if pos1 < end then
748− let !word1 = P.unsafeIndex pos1 in
749− if isDecimalDigit word1 then
750− cerr row (col + 1) NoLeadingZeros
751− else if word1 == 0x2E {-.-} then
752− cerr row (col + 1) NoFloats
753− else
754− cok (Int 0) newState
755− else
756− cok (Int 0) newState
757−
758− else
759− let
760− (# status, n, newPos #) =
761− chompInt (plusPtr pos 1) end (fromIntegral (word - 0x30 {-0-}))
762−
763− !len = fromIntegral (minusPtr newPos pos)
764− in
765− case status of
766− GoodInt ->
767− let
768− !newState =
769− P.State src newPos end indent row (col + len)
770− in
771− cok (Int n) newState
772−
773− BadIntEnd ->
774− cerr row (col + len) NoFloats
775−
776−
777−data IntStatus = GoodInt | BadIntEnd
778−
779−
780−chompInt :: Ptr Word8 -> Ptr Word8 -> Int -> (# IntStatus, Int, Ptr Word8 #)
781−chompInt pos end n =
782− if pos < end then
783− let !word = P.unsafeIndex pos in
784− if isDecimalDigit word then
785− let !m = 10 * n + fromIntegral (word - 0x30 {-0-}) in
786− chompInt (plusPtr pos 1) end m
787− else if word == 0x2E {-.-} || word == 0x65 {-e-} || word == 0x45 {-E-} then
788− (# BadIntEnd, n, pos #)
789− else
790− (# GoodInt, n, pos #)
791−
792− else
793− (# GoodInt, n, pos #)
794−
795−
796−{-# INLINE isDecimalDigit #-}
797−isDecimalDigit :: Word8 -> Bool
798−isDecimalDigit word =
799− word <= 0x39 {-9-} && word >= 0x30 {-0-}
compiler/src/Json/String.hsdeleted−192
@@ -1,192 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}
2−{-# LANGUAGE BangPatterns, EmptyDataDecls #-}
3−module Json.String
4− ( String
5− , isEmpty
6− --
7− , fromPtr
8− , fromName
9− , fromChars
10− , fromSnippet
11− , fromComment
12− --
13− , toChars
14− , toBuilder
15− )
16− where
17−
18−
19−import Prelude hiding (String)
20−import qualified Data.ByteString.Builder as B
21−import qualified Data.Coerce as Coerce
22−import qualified Data.Name as Name
23−import qualified Data.Utf8 as Utf8
24−import Data.Utf8 (MBA, newByteArray, copyFromPtr, freeze, writeWord8)
25−import Data.Word (Word8)
26−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
27−import Foreign.ForeignPtr (withForeignPtr)
28−import GHC.Exts (RealWorld)
29−import GHC.IO (stToIO, unsafeDupablePerformIO, unsafePerformIO)
30−import GHC.ST (ST)
31−
32−import qualified Parse.Primitives as P
33−
34−
35−
36−-- JSON STRINGS
37−
38−
39−-- INVARIANT: any Json.String is appropriately escaped already
40−-- PERF: is this the right representation for Json.String? Maybe ByteString instead?
41−--
42−type String =
43− Utf8.Utf8 JSON_STRING
44−
45−
46−data JSON_STRING
47−
48−
49−isEmpty :: String -> Bool
50−isEmpty =
51− Utf8.isEmpty
52−
53−
54−
55−-- FROM
56−
57−
58−fromPtr :: Ptr Word8 -> Ptr Word8 -> String
59−fromPtr =
60− Utf8.fromPtr
61−
62−
63−fromChars :: [Char] -> String
64−fromChars =
65− Utf8.fromChars
66−
67−
68−fromSnippet :: P.Snippet -> String
69−fromSnippet =
70− Utf8.fromSnippet
71−
72−
73−fromName :: Name.Name -> String
74−fromName =
75− Coerce.coerce
76−
77−
78−
79−-- TO
80−
81−
82−toChars :: String -> [Char]
83−toChars =
84− Utf8.toChars
85−
86−
87−{-# INLINE toBuilder #-}
88−toBuilder :: String -> B.Builder
89−toBuilder =
90− Utf8.toBuilder
91−
92−
93−
94−-- FROM COMMENT
95−
96−
97−fromComment :: P.Snippet -> String
98−fromComment (P.Snippet fptr off len _ _) =
99− unsafePerformIO $ withForeignPtr fptr $ \ptr ->
100− let
101− !pos = plusPtr ptr off
102− !end = plusPtr pos len
103− !str = fromChunks (chompChunks pos end pos [])
104− in
105− return str
106−
107−
108−chompChunks :: Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> [Chunk] -> [Chunk]
109−chompChunks pos end start revChunks =
110− if pos >= end then
111− reverse (addSlice start end revChunks)
112− else
113− let
114− !word = P.unsafeIndex pos
115− in
116− case word of
117− 0x0A {-\n-} -> chompEscape 0x6E {-n-} pos end start revChunks
118− 0x22 {-"-} -> chompEscape 0x22 {-"-} pos end start revChunks
119− 0x5C {-\-} -> chompEscape 0x5C {-\-} pos end start revChunks
120− 0x0D {-\r-} ->
121− let
122− !newPos = plusPtr pos 1
123− in
124− chompChunks newPos end newPos (addSlice start pos revChunks)
125−
126− _ ->
127− let
128− !width = P.getCharWidth word
129− !newPos = plusPtr pos width
130− in
131− chompChunks newPos end start revChunks
132−
133−
134−chompEscape :: Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> [Chunk] -> [Chunk]
135−chompEscape escape pos end start revChunks =
136− let
137− !pos1 = plusPtr pos 1
138− in
139− chompChunks pos1 end pos1 (Escape escape : addSlice start pos revChunks)
140−
141−
142−addSlice :: Ptr Word8 -> Ptr Word8 -> [Chunk] -> [Chunk]
143−addSlice start end revChunks =
144− if start == end
145− then revChunks
146− else Slice start (minusPtr end start) : revChunks
147−
148−
149−
150−-- FROM CHUNKS
151−
152−
153−data Chunk
154− = Slice (Ptr Word8) Int
155− | Escape Word8
156−
157−
158−fromChunks :: [Chunk] -> String
159−fromChunks chunks =
160− unsafeDupablePerformIO (stToIO (
161− do let !len = sum (map chunkToWidth chunks)
162− mba <- newByteArray len
163− writeChunks mba 0 chunks
164− freeze mba
165− ))
166−
167−
168−chunkToWidth :: Chunk -> Int
169−chunkToWidth chunk =
170− case chunk of
171− Slice _ len -> len
172− Escape _ -> 2
173−
174−
175−writeChunks :: MBA RealWorld -> Int -> [Chunk] -> ST RealWorld ()
176−writeChunks mba offset chunks =
177− case chunks of
178− [] ->
179− return ()
180−
181− chunk : chunks ->
182− case chunk of
183− Slice ptr len ->
184− do copyFromPtr ptr mba offset len
185− let !newOffset = offset + len
186− writeChunks mba newOffset chunks
187−
188− Escape word ->
189− do writeWord8 mba offset 0x5C {- \ -}
190− writeWord8 mba (offset + 1) word
191− let !newOffset = offset + 2
192− writeChunks mba newOffset chunks
compiler/src/Nitpick/Debug.hsdeleted−87
@@ -1,87 +0,0 @@
1−module Nitpick.Debug
2− ( hasDebugUses
3− )
4− where
5−
6−
7−import qualified Data.Map.Utils as Map
8−
9−import qualified AST.Optimized as Opt
10−
11−
12−
13−-- HAS DEBUG USES
14−
15−
16−hasDebugUses :: Opt.LocalGraph -> Bool
17−hasDebugUses (Opt.LocalGraph _ graph _) =
18− Map.any nodeHasDebug graph
19−
20−
21−nodeHasDebug :: Opt.Node -> Bool
22−nodeHasDebug node =
23− case node of
24− Opt.Define expr _ -> hasDebug expr
25− Opt.DefineTailFunc _ expr _ -> hasDebug expr
26− Opt.Ctor _ _ -> False
27− Opt.Enum _ -> False
28− Opt.Box -> False
29− Opt.Link _ -> False
30− Opt.Cycle _ vs fs _ -> any (hasDebug . snd) vs || any defHasDebug fs
31− Opt.Manager _ -> False
32− Opt.Kernel _ _ -> False
33− Opt.PortIncoming expr _ -> hasDebug expr
34− Opt.PortOutgoing expr _ -> hasDebug expr
35−
36−
37−hasDebug :: Opt.Expr -> Bool
38−hasDebug expression =
39− case expression of
40− Opt.Bool _ -> False
41− Opt.Chr _ -> False
42− Opt.Str _ -> False
43− Opt.Int _ -> False
44− Opt.Float _ -> False
45− Opt.VarLocal _ -> False
46− Opt.VarGlobal _ -> False
47− Opt.VarEnum _ _ -> False
48− Opt.VarBox _ -> False
49− Opt.VarCycle _ _ -> False
50− Opt.VarDebug _ _ _ _ -> True
51− Opt.VarKernel _ _ -> False
52− Opt.List exprs -> any hasDebug exprs
53− Opt.Function _ expr -> hasDebug expr
54− Opt.Call e es -> hasDebug e || any hasDebug es
55− Opt.TailCall _ args -> any (hasDebug . snd) args
56− Opt.If conds finally -> any (\(c,e) -> hasDebug c || hasDebug e) conds || hasDebug finally
57− Opt.Let def body -> defHasDebug def || hasDebug body
58− Opt.Destruct _ expr -> hasDebug expr
59− Opt.Case _ _ d jumps -> deciderHasDebug d || any (hasDebug . snd) jumps
60− Opt.Accessor _ -> False
61− Opt.Access r _ -> hasDebug r
62− Opt.Update r fs -> hasDebug r || any hasDebug fs
63− Opt.Record fs -> any hasDebug fs
64− Opt.Unit -> False
65− Opt.Tuple a b c -> hasDebug a || hasDebug b || maybe False hasDebug c
66− Opt.Shader _ _ _ -> False
67−
68−
69−defHasDebug :: Opt.Def -> Bool
70−defHasDebug def =
71− case def of
72− Opt.Def _ expr -> hasDebug expr
73− Opt.TailDef _ _ expr -> hasDebug expr
74−
75−
76−deciderHasDebug :: Opt.Decider Opt.Choice -> Bool
77−deciderHasDebug decider =
78− case decider of
79− Opt.Leaf (Opt.Inline expr) -> hasDebug expr
80− Opt.Leaf (Opt.Jump _) -> False
81− Opt.Chain _ success failure -> deciderHasDebug success || deciderHasDebug failure
82− Opt.FanOut _ tests fallback -> any (deciderHasDebug . snd) tests || deciderHasDebug fallback
83−
84−
85−
86−-- TODO: FIND GLOBALLY UNUSED DEFINITIONS?
87−-- TODO: FIND PACKAGE USAGE STATS? (e.g. elm/core = 142, author/project = 2, etc.)
compiler/src/Parse/Declaration.hsdeleted−266
@@ -1,266 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Parse.Declaration
4− ( Decl(..)
5− , declaration
6− , infix_
7− )
8− where
9−
10−
11−import qualified Data.Name as Name
12−
13−import qualified AST.Source as Src
14−import qualified AST.Utils.Binop as Binop
15−import qualified Parse.Expression as Expr
16−import qualified Parse.Pattern as Pattern
17−import qualified Parse.Keyword as Keyword
18−import qualified Parse.Number as Number
19−import qualified Parse.Space as Space
20−import qualified Parse.Symbol as Symbol
21−import qualified Parse.Type as Type
22−import qualified Parse.Variable as Var
23−import Parse.Primitives hiding (State)
24−import qualified Parse.Primitives as P
25−import qualified Reporting.Annotation as A
26−import qualified Reporting.Error.Syntax as E
27−
28−
29−
30−-- DECLARATION
31−
32−
33−data Decl
34− = Value (Maybe Src.Comment) (A.Located Src.Value)
35− | Union (Maybe Src.Comment) (A.Located Src.Union)
36− | Alias (Maybe Src.Comment) (A.Located Src.Alias)
37− | Port (Maybe Src.Comment) Src.Port
38−
39−
40−declaration :: Space.Parser E.Decl Decl
41−declaration =
42− do maybeDocs <- chompDocComment
43− start <- getPosition
44− oneOf E.DeclStart
45− [ typeDecl maybeDocs start
46− , portDecl maybeDocs
47− , valueDecl maybeDocs start
48− ]
49−
50−
51−
52−-- DOC COMMENT
53−
54−
55−chompDocComment :: Parser E.Decl (Maybe Src.Comment)
56−chompDocComment =
57− oneOfWithFallback
58− [
59− do docComment <- Space.docComment E.DeclStart E.DeclSpace
60− Space.chomp E.DeclSpace
61− Space.checkFreshLine E.DeclFreshLineAfterDocComment
62− return (Just docComment)
63− ]
64− Nothing
65−
66−
67−
68−-- DEFINITION and ANNOTATION
69−
70−
71−{-# INLINE valueDecl #-}
72−valueDecl :: Maybe Src.Comment -> A.Position -> Space.Parser E.Decl Decl
73−valueDecl maybeDocs start =
74− do name <- Var.lower E.DeclStart
75− end <- getPosition
76− specialize (E.DeclDef name) $
77− do Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentEquals
78− oneOf E.DeclDefEquals
79− [
80− do word1 0x3A {-:-} E.DeclDefEquals
81− Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentType
82− (tipe, _) <- specialize E.DeclDefType Type.expression
83− Space.checkFreshLine E.DeclDefNameRepeat
84− defName <- chompMatchingName name
85− Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentEquals
86− chompDefArgsAndBody maybeDocs start defName (Just tipe) []
87− ,
88− chompDefArgsAndBody maybeDocs start (A.at start end name) Nothing []
89− ]
90−
91−
92−chompDefArgsAndBody :: Maybe Src.Comment -> A.Position -> A.Located Name.Name -> Maybe Src.Type -> [Src.Pattern] -> Space.Parser E.DeclDef Decl
93−chompDefArgsAndBody maybeDocs start name tipe revArgs =
94− oneOf E.DeclDefEquals
95− [ do arg <- specialize E.DeclDefArg Pattern.term
96− Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentEquals
97− chompDefArgsAndBody maybeDocs start name tipe (arg : revArgs)
98− , do word1 0x3D {-=-} E.DeclDefEquals
99− Space.chompAndCheckIndent E.DeclDefSpace E.DeclDefIndentBody
100− (body, end) <- specialize E.DeclDefBody Expr.expression
101− let value = Src.Value name (reverse revArgs) body tipe
102− let avalue = A.at start end value
103− return (Value maybeDocs avalue, end)
104− ]
105−
106−
107−chompMatchingName :: Name.Name -> Parser E.DeclDef (A.Located Name.Name)
108−chompMatchingName expectedName =
109− let
110− (P.Parser parserL) = Var.lower E.DeclDefNameRepeat
111− in
112− P.Parser $ \state@(P.State _ _ _ _ sr sc) cok eok cerr eerr ->
113− let
114− cokL name newState@(P.State _ _ _ _ er ec) =
115− if expectedName == name
116− then cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
117− else cerr sr sc (E.DeclDefNameMatch name)
118−
119− eokL name newState@(P.State _ _ _ _ er ec) =
120− if expectedName == name
121− then eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
122− else eerr sr sc (E.DeclDefNameMatch name)
123− in
124− parserL state cokL eokL cerr eerr
125−
126−
127−
128−-- TYPE DECLARATIONS
129−
130−
131−{-# INLINE typeDecl #-}
132−typeDecl :: Maybe Src.Comment -> A.Position -> Space.Parser E.Decl Decl
133−typeDecl maybeDocs start =
134− inContext E.DeclType (Keyword.type_ E.DeclStart) $
135− do Space.chompAndCheckIndent E.DT_Space E.DT_IndentName
136− oneOf E.DT_Name
137− [
138− inContext E.DT_Alias (Keyword.alias_ E.DT_Name) $
139− do Space.chompAndCheckIndent E.AliasSpace E.AliasIndentEquals
140− (name, args) <- chompAliasNameToEquals
141− (tipe, end) <- specialize E.AliasBody Type.expression
142− let alias = A.at start end (Src.Alias name args tipe)
143− return (Alias maybeDocs alias, end)
144− ,
145− specialize E.DT_Union $
146− do (name, args) <- chompCustomNameToEquals
147− (firstVariant, firstEnd) <- Type.variant
148− (variants, end) <- chompVariants [firstVariant] firstEnd
149− let union = A.at start end (Src.Union name args variants)
150− return (Union maybeDocs union, end)
151− ]
152−
153−
154−
155−-- TYPE ALIASES
156−
157−
158−chompAliasNameToEquals :: Parser E.TypeAlias (A.Located Name.Name, [A.Located Name.Name])
159−chompAliasNameToEquals =
160− do name <- addLocation (Var.upper E.AliasName)
161− Space.chompAndCheckIndent E.AliasSpace E.AliasIndentEquals
162− chompAliasNameToEqualsHelp name []
163−
164−
165−chompAliasNameToEqualsHelp :: A.Located Name.Name -> [A.Located Name.Name] -> Parser E.TypeAlias (A.Located Name.Name, [A.Located Name.Name])
166−chompAliasNameToEqualsHelp name args =
167− oneOf E.AliasEquals
168− [ do arg <- addLocation (Var.lower E.AliasEquals)
169− Space.chompAndCheckIndent E.AliasSpace E.AliasIndentEquals
170− chompAliasNameToEqualsHelp name (arg:args)
171− , do word1 0x3D {-=-} E.AliasEquals
172− Space.chompAndCheckIndent E.AliasSpace E.AliasIndentBody
173− return ( name, reverse args )
174− ]
175−
176−
177−
178−-- CUSTOM TYPES
179−
180−
181−chompCustomNameToEquals :: Parser E.CustomType (A.Located Name.Name, [A.Located Name.Name])
182−chompCustomNameToEquals =
183− do name <- addLocation (Var.upper E.CT_Name)
184− Space.chompAndCheckIndent E.CT_Space E.CT_IndentEquals
185− chompCustomNameToEqualsHelp name []
186−
187−
188−chompCustomNameToEqualsHelp :: A.Located Name.Name -> [A.Located Name.Name] -> Parser E.CustomType (A.Located Name.Name, [A.Located Name.Name])
189−chompCustomNameToEqualsHelp name args =
190− oneOf E.CT_Equals
191− [ do arg <- addLocation (Var.lower E.CT_Equals)
192− Space.chompAndCheckIndent E.CT_Space E.CT_IndentEquals
193− chompCustomNameToEqualsHelp name (arg:args)
194− , do word1 0x3D {-=-} E.CT_Equals
195− Space.chompAndCheckIndent E.CT_Space E.CT_IndentAfterEquals
196− return ( name, reverse args )
197− ]
198−
199−
200−chompVariants :: [(A.Located Name.Name, [Src.Type])] -> A.Position -> Space.Parser E.CustomType [(A.Located Name.Name, [Src.Type])]
201−chompVariants variants end =
202− oneOfWithFallback
203− [ do Space.checkIndent end E.CT_IndentBar
204− word1 0x7C {-|-} E.CT_Bar
205− Space.chompAndCheckIndent E.CT_Space E.CT_IndentAfterBar
206− (variant, newEnd) <- Type.variant
207− chompVariants (variant:variants) newEnd
208− ]
209− (reverse variants, end)
210−
211−
212−
213−-- PORT
214−
215−
216−{-# INLINE portDecl #-}
217−portDecl :: Maybe Src.Comment -> Space.Parser E.Decl Decl
218−portDecl maybeDocs =
219− inContext E.Port (Keyword.port_ E.DeclStart) $
220− do Space.chompAndCheckIndent E.PortSpace E.PortIndentName
221− name <- addLocation (Var.lower E.PortName)
222− Space.chompAndCheckIndent E.PortSpace E.PortIndentColon
223− word1 0x3A {-:-} E.PortColon
224− Space.chompAndCheckIndent E.PortSpace E.PortIndentType
225− (tipe, end) <- specialize E.PortType Type.expression
226− return
227− ( Port maybeDocs (Src.Port name tipe)
228− , end
229− )
230−
231−
232−
233−-- INFIX
234−
235−
236−-- INVARIANT: always chomps to a freshline
237−--
238−infix_ :: Parser E.Module (A.Located Src.Infix)
239−infix_ =
240− let
241− err = E.Infix
242− _err = \_ -> E.Infix
243− in
244− do start <- getPosition
245− Keyword.infix_ err
246− Space.chompAndCheckIndent _err err
247− associativity <-
248− oneOf err
249− [ Keyword.left_ err >> return Binop.Left
250− , Keyword.right_ err >> return Binop.Right
251− , Keyword.non_ err >> return Binop.Non
252− ]
253− Space.chompAndCheckIndent _err err
254− precedence <- Number.precedence err
255− Space.chompAndCheckIndent _err err
256− word1 0x28 {-(-} err
257− op <- Symbol.operator err _err
258− word1 0x29 {-)-} err
259− Space.chompAndCheckIndent _err err
260− word1 0x3D {-=-} err
261− Space.chompAndCheckIndent _err err
262− name <- Var.lower err
263− end <- getPosition
264− Space.chomp _err
265− Space.checkFreshLine err
266− return (A.at start end (Src.Infix op associativity precedence name))
compiler/src/Parse/Expression.hsdeleted−577
@@ -1,577 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Parse.Expression
4− ( expression
5− )
6− where
7−
8−
9−import qualified Data.Name as Name
10−
11−import qualified AST.Source as Src
12−import qualified Parse.Keyword as Keyword
13−import qualified Parse.Number as Number
14−import qualified Parse.Pattern as Pattern
15−import qualified Parse.Shader as Shader
16−import qualified Parse.Space as Space
17−import qualified Parse.Symbol as Symbol
18−import qualified Parse.Type as Type
19−import qualified Parse.String as String
20−import qualified Parse.Variable as Var
21−import Parse.Primitives hiding (State)
22−import qualified Parse.Primitives as P
23−import qualified Reporting.Annotation as A
24−import qualified Reporting.Error.Syntax as E
25−
26−
27−
28−-- TERMS
29−
30−
31−term :: Parser E.Expr Src.Expr
32−term =
33− do start <- getPosition
34− oneOf E.Start
35− [ variable start >>= accessible start
36− , string start
37− , number start
38− , Shader.shader start
39− , list start
40− , record start >>= accessible start
41− , tuple start >>= accessible start
42− , accessor start
43− , character start
44− ]
45−
46−
47−string :: A.Position -> Parser E.Expr Src.Expr
48−string start =
49− do str <- String.string E.Start E.String
50− addEnd start (Src.Str str)
51−
52−
53−character :: A.Position -> Parser E.Expr Src.Expr
54−character start =
55− do chr <- String.character E.Start E.Char
56− addEnd start (Src.Chr chr)
57−
58−
59−number :: A.Position -> Parser E.Expr Src.Expr
60−number start =
61− do nmbr <- Number.number E.Start E.Number
62− addEnd start $
63− case nmbr of
64− Number.Int int -> Src.Int int
65− Number.Float float -> Src.Float float
66−
67−
68−accessor :: A.Position -> Parser E.Expr Src.Expr
69−accessor start =
70− do word1 0x2E {-.-} E.Dot
71− field <- Var.lower E.Access
72− addEnd start (Src.Accessor field)
73−
74−
75−variable :: A.Position -> Parser E.Expr Src.Expr
76−variable start =
77− do var <- Var.foreignAlpha E.Start
78− addEnd start var
79−
80−
81−accessible :: A.Position -> Src.Expr -> Parser E.Expr Src.Expr
82−accessible start expr =
83− oneOfWithFallback
84− [ do word1 0x2E {-.-} E.Dot
85− pos <- getPosition
86− field <- Var.lower E.Access
87− end <- getPosition
88− accessible start $
89− A.at start end (Src.Access expr (A.at pos end field))
90− ]
91− expr
92−
93−
94−
95−-- LISTS
96−
97−
98−list :: A.Position -> Parser E.Expr Src.Expr
99−list start =
100− inContext E.List (word1 0x5B {-[-} E.Start) $
101− do Space.chompAndCheckIndent E.ListSpace E.ListIndentOpen
102− oneOf E.ListOpen
103− [ do (entry, end) <- specialize E.ListExpr expression
104− Space.checkIndent end E.ListIndentEnd
105− chompListEnd start [entry]
106− , do word1 0x5D {-]-} E.ListOpen
107− addEnd start (Src.List [])
108− ]
109−
110−
111−chompListEnd :: A.Position -> [Src.Expr] -> Parser E.List Src.Expr
112−chompListEnd start entries =
113− oneOf E.ListEnd
114− [ do word1 0x2C {-,-} E.ListEnd
115− Space.chompAndCheckIndent E.ListSpace E.ListIndentExpr
116− (entry, end) <- specialize E.ListExpr expression
117− Space.checkIndent end E.ListIndentEnd
118− chompListEnd start (entry:entries)
119− , do word1 0x5D {-]-} E.ListEnd
120− addEnd start (Src.List (reverse entries))
121− ]
122−
123−
124−
125−-- TUPLES
126−
127−
128−tuple :: A.Position -> Parser E.Expr Src.Expr
129−tuple start@(A.Position row col) =
130− inContext E.Tuple (word1 0x28 {-(-} E.Start) $
131− do before <- getPosition
132− Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr1
133− after <- getPosition
134− if before /= after
135− then
136− do (entry, end) <- specialize E.TupleExpr expression
137− Space.checkIndent end E.TupleIndentEnd
138− chompTupleEnd start entry []
139− else
140− oneOf E.TupleIndentExpr1
141− [
142− do op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved
143− if op == "-"
144− then
145− oneOf E.TupleOperatorClose
146− [
147− do word1 0x29 {-)-} E.TupleOperatorClose
148− addEnd start (Src.Op op)
149− ,
150− do (entry, end) <-
151− specialize E.TupleExpr $
152− do negatedExpr@(A.At (A.Region _ end) _) <- term
153− Space.chomp E.Space
154− let exprStart = A.Position row (col + 2)
155− let expr = A.at exprStart end (Src.Negate negatedExpr)
156− chompExprEnd exprStart (State [] expr [] end)
157− Space.checkIndent end E.TupleIndentEnd
158− chompTupleEnd start entry []
159− ]
160− else
161− do word1 0x29 {-)-} E.TupleOperatorClose
162− addEnd start (Src.Op op)
163− ,
164− do word1 0x29 {-)-} E.TupleIndentExpr1
165− addEnd start Src.Unit
166− ,
167− do (entry, end) <- specialize E.TupleExpr expression
168− Space.checkIndent end E.TupleIndentEnd
169− chompTupleEnd start entry []
170− ]
171−
172−
173−chompTupleEnd :: A.Position -> Src.Expr -> [Src.Expr] -> Parser E.Tuple Src.Expr
174−chompTupleEnd start firstExpr revExprs =
175− oneOf E.TupleEnd
176− [ do word1 0x2C {-,-} E.TupleEnd
177− Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExprN
178− (entry, end) <- specialize E.TupleExpr expression
179− Space.checkIndent end E.TupleIndentEnd
180− chompTupleEnd start firstExpr (entry : revExprs)
181− , do word1 0x29 {-)-} E.TupleEnd
182− case reverse revExprs of
183− [] ->
184− return firstExpr
185−
186− secondExpr : otherExprs ->
187− addEnd start (Src.Tuple firstExpr secondExpr otherExprs)
188− ]
189−
190−
191−
192−-- RECORDS
193−
194−
195−record :: A.Position -> Parser E.Expr Src.Expr
196−record start =
197− inContext E.Record (word1 0x7B {- { -} E.Start) $
198− do Space.chompAndCheckIndent E.RecordSpace E.RecordIndentOpen
199− oneOf E.RecordOpen
200− [ do word1 0x7D {-}-} E.RecordOpen
201− addEnd start (Src.Record [])
202− , do starter <- addLocation (Var.lower E.RecordField)
203− Space.chompAndCheckIndent E.RecordSpace E.RecordIndentEquals
204− oneOf E.RecordEquals
205− [ do word1 0x7C {-|-} E.RecordEquals
206− Space.chompAndCheckIndent E.RecordSpace E.RecordIndentField
207− firstField <- chompField
208− fields <- chompFields [firstField]
209− addEnd start (Src.Update starter fields)
210− , do word1 0x3D {-=-} E.RecordEquals
211− Space.chompAndCheckIndent E.RecordSpace E.RecordIndentExpr
212− (value, end) <- specialize E.RecordExpr expression
213− Space.checkIndent end E.RecordIndentEnd
214− fields <- chompFields [(starter, value)]
215− addEnd start (Src.Record fields)
216− ]
217− ]
218−
219−
220−type Field = ( A.Located Name.Name, Src.Expr )
221−
222−
223−chompFields :: [Field] -> Parser E.Record [Field]
224−chompFields fields =
225− oneOf E.RecordEnd
226− [ do word1 0x2C {-,-} E.RecordEnd
227− Space.chompAndCheckIndent E.RecordSpace E.RecordIndentField
228− f <- chompField
229− chompFields (f : fields)
230− , do word1 0x7D {-}-} E.RecordEnd
231− return (reverse fields)
232− ]
233−
234−
235−chompField :: Parser E.Record Field
236−chompField =
237− do key <- addLocation (Var.lower E.RecordField)
238− Space.chompAndCheckIndent E.RecordSpace E.RecordIndentEquals
239− word1 0x3D {-=-} E.RecordEquals
240− Space.chompAndCheckIndent E.RecordSpace E.RecordIndentExpr
241− (value, end) <- specialize E.RecordExpr expression
242− Space.checkIndent end E.RecordIndentEnd
243− return (key, value)
244−
245−
246−
247−-- EXPRESSIONS
248−
249−
250−expression :: Space.Parser E.Expr Src.Expr
251−expression =
252− do start <- getPosition
253− oneOf E.Start
254− [ let_ start
255− , if_ start
256− , case_ start
257− , function start
258− , do expr <- possiblyNegativeTerm start
259− end <- getPosition
260− Space.chomp E.Space
261− chompExprEnd start (State [] expr [] end)
262− ]
263−
264−
265−data State =
266− State
267− { _ops :: ![(Src.Expr, A.Located Name.Name)]
268− , _expr :: !Src.Expr
269− , _args :: ![Src.Expr]
270− , _end :: !A.Position
271− }
272−
273−
274−chompExprEnd :: A.Position -> State -> Space.Parser E.Expr Src.Expr
275−chompExprEnd start (State ops expr args end) =
276− oneOfWithFallback
277− [ -- argument
278− do Space.checkIndent end E.Start
279− arg <- term
280− newEnd <- getPosition
281− Space.chomp E.Space
282− chompExprEnd start (State ops expr (arg:args) newEnd)
283−
284− , -- operator
285− do Space.checkIndent end E.Start
286− op@(A.At (A.Region opStart opEnd) opName) <- addLocation (Symbol.operator E.Start E.OperatorReserved)
287− Space.chompAndCheckIndent E.Space (E.IndentOperatorRight opName)
288− newStart <- getPosition
289− if "-" == opName && end /= opStart && opEnd == newStart
290− then
291− -- negative terms
292− do negatedExpr <- term
293− newEnd <- getPosition
294− Space.chomp E.Space
295− let arg = A.at opStart newEnd (Src.Negate negatedExpr)
296− chompExprEnd start (State ops expr (arg:args) newEnd)
297− else
298− let err = E.OperatorRight opName in
299− oneOf err
300− [ -- term
301− do newExpr <- possiblyNegativeTerm newStart
302− newEnd <- getPosition
303− Space.chomp E.Space
304− let newOps = (toCall expr args, op) : ops
305− chompExprEnd start (State newOps newExpr [] newEnd)
306−
307− , -- final term
308− do (newLast, newEnd) <-
309− oneOf err
310− [ let_ newStart
311− , case_ newStart
312− , if_ newStart
313− , function newStart
314− ]
315− let newOps = (toCall expr args, op) : ops
316− let finalExpr = Src.Binops (reverse newOps) newLast
317− return ( A.at start newEnd finalExpr, newEnd )
318− ]
319−
320− ]
321− -- done
322− (
323− case ops of
324− [] ->
325− ( toCall expr args
326− , end
327− )
328−
329− _ ->
330− ( A.at start end (Src.Binops (reverse ops) (toCall expr args))
331− , end
332− )
333− )
334−
335−
336−possiblyNegativeTerm :: A.Position -> Parser E.Expr Src.Expr
337−possiblyNegativeTerm start =
338− oneOf E.Start
339− [ do word1 0x2D {---} E.Start
340− expr <- term
341− addEnd start (Src.Negate expr)
342− , term
343− ]
344−
345−
346−toCall :: Src.Expr -> [Src.Expr] -> Src.Expr
347−toCall func revArgs =
348− case revArgs of
349− [] ->
350− func
351−
352− lastArg : _ ->
353− A.merge func lastArg (Src.Call func (reverse revArgs))
354−
355−
356−
357−-- IF EXPRESSION
358−
359−
360−if_ :: A.Position -> Space.Parser E.Expr Src.Expr
361−if_ start =
362− inContext E.If (Keyword.if_ E.Start) $
363− chompIfEnd start []
364−
365−
366−chompIfEnd :: A.Position -> [(Src.Expr, Src.Expr)] -> Space.Parser E.If Src.Expr
367−chompIfEnd start branches =
368− do Space.chompAndCheckIndent E.IfSpace E.IfIndentCondition
369− (condition, condEnd) <- specialize E.IfCondition expression
370− Space.checkIndent condEnd E.IfIndentThen
371− Keyword.then_ E.IfThen
372− Space.chompAndCheckIndent E.IfSpace E.IfIndentThenBranch
373− (thenBranch, thenEnd) <- specialize E.IfThenBranch expression
374− Space.checkIndent thenEnd E.IfIndentElse
375− Keyword.else_ E.IfElse
376− Space.chompAndCheckIndent E.IfSpace E.IfIndentElseBranch
377− let newBranches = (condition, thenBranch) : branches
378− oneOf E.IfElseBranchStart
379− [
380− do Keyword.if_ E.IfElseBranchStart
381− chompIfEnd start newBranches
382− ,
383− do (elseBranch, elseEnd) <- specialize E.IfElseBranch expression
384− let ifExpr = Src.If (reverse newBranches) elseBranch
385− return ( A.at start elseEnd ifExpr, elseEnd )
386− ]
387−
388−
389−
390−-- LAMBDA EXPRESSION
391−
392−
393−function :: A.Position -> Space.Parser E.Expr Src.Expr
394−function start =
395− inContext E.Func (word1 0x5C {-\-} E.Start) $
396− do Space.chompAndCheckIndent E.FuncSpace E.FuncIndentArg
397− arg <- specialize E.FuncArg Pattern.term
398− Space.chompAndCheckIndent E.FuncSpace E.FuncIndentArrow
399− revArgs <- chompArgs [arg]
400− Space.chompAndCheckIndent E.FuncSpace E.FuncIndentBody
401− (body, end) <- specialize E.FuncBody expression
402− let funcExpr = Src.Lambda (reverse revArgs) body
403− return (A.at start end funcExpr, end)
404−
405−
406−chompArgs :: [Src.Pattern] -> Parser E.Func [Src.Pattern]
407−chompArgs revArgs =
408− oneOf E.FuncArrow
409− [ do arg <- specialize E.FuncArg Pattern.term
410− Space.chompAndCheckIndent E.FuncSpace E.FuncIndentArrow
411− chompArgs (arg:revArgs)
412− , do word2 0x2D 0x3E {-->-} E.FuncArrow
413− return revArgs
414− ]
415−
416−
417−
418−-- CASE EXPRESSIONS
419−
420−
421−case_ :: A.Position -> Space.Parser E.Expr Src.Expr
422−case_ start =
423− inContext E.Case (Keyword.case_ E.Start) $
424− do Space.chompAndCheckIndent E.CaseSpace E.CaseIndentExpr
425− (expr, exprEnd) <- specialize E.CaseExpr expression
426− Space.checkIndent exprEnd E.CaseIndentOf
427− Keyword.of_ E.CaseOf
428− Space.chompAndCheckIndent E.CaseSpace E.CaseIndentPattern
429− withIndent $
430− do (firstBranch, firstEnd) <- chompBranch
431− (branches, end) <- chompCaseEnd [firstBranch] firstEnd
432− return
433− ( A.at start end (Src.Case expr branches)
434− , end
435− )
436−
437−
438−chompBranch :: Space.Parser E.Case (Src.Pattern, Src.Expr)
439−chompBranch =
440− do (pattern, patternEnd) <- specialize E.CasePattern Pattern.expression
441− Space.checkIndent patternEnd E.CaseIndentArrow
442− word2 0x2D 0x3E {-->-} E.CaseArrow
443− Space.chompAndCheckIndent E.CaseSpace E.CaseIndentBranch
444− (branchExpr, end) <- specialize E.CaseBranch expression
445− return ( (pattern, branchExpr), end )
446−
447−
448−chompCaseEnd :: [(Src.Pattern, Src.Expr)] -> A.Position -> Space.Parser E.Case [(Src.Pattern, Src.Expr)]
449−chompCaseEnd branches end =
450− oneOfWithFallback
451− [ do Space.checkAligned E.CasePatternAlignment
452− (branch, newEnd) <- chompBranch
453− chompCaseEnd (branch:branches) newEnd
454− ]
455− (reverse branches, end)
456−
457−
458−
459−-- LET EXPRESSION
460−
461−
462−let_ :: A.Position -> Space.Parser E.Expr Src.Expr
463−let_ start =
464− inContext E.Let (Keyword.let_ E.Start) $
465− do (defs, defsEnd) <-
466− withBacksetIndent 3 $
467− do Space.chompAndCheckIndent E.LetSpace E.LetIndentDef
468− withIndent $
469− do (def, end) <- chompLetDef
470− chompLetDefs [def] end
471−
472− Space.checkIndent defsEnd E.LetIndentIn
473− Keyword.in_ E.LetIn
474− Space.chompAndCheckIndent E.LetSpace E.LetIndentBody
475− (body, end) <- specialize E.LetBody expression
476− return
477− ( A.at start end (Src.Let defs body)
478− , end
479− )
480−
481−
482−chompLetDefs :: [A.Located Src.Def] -> A.Position -> Space.Parser E.Let [A.Located Src.Def]
483−chompLetDefs revDefs end =
484− oneOfWithFallback
485− [ do Space.checkAligned E.LetDefAlignment
486− (def, newEnd) <- chompLetDef
487− chompLetDefs (def:revDefs) newEnd
488− ]
489− (reverse revDefs, end)
490−
491−
492−
493−-- LET DEFINITIONS
494−
495−
496−chompLetDef :: Space.Parser E.Let (A.Located Src.Def)
497−chompLetDef =
498− oneOf E.LetDefName
499− [ definition
500− , destructure
501− ]
502−
503−
504−
505−-- DEFINITION
506−
507−
508−definition :: Space.Parser E.Let (A.Located Src.Def)
509−definition =
510− do aname@(A.At (A.Region start _) name) <- addLocation (Var.lower E.LetDefName)
511− specialize (E.LetDef name) $
512− do Space.chompAndCheckIndent E.DefSpace E.DefIndentEquals
513− oneOf E.DefEquals
514− [
515− do word1 0x3A {-:-} E.DefEquals
516− Space.chompAndCheckIndent E.DefSpace E.DefIndentType
517− (tipe, _) <- specialize E.DefType Type.expression
518− Space.checkAligned E.DefAlignment
519− defName <- chompMatchingName name
520− Space.chompAndCheckIndent E.DefSpace E.DefIndentEquals
521− chompDefArgsAndBody start defName (Just tipe) []
522− ,
523− chompDefArgsAndBody start aname Nothing []
524− ]
525−
526−
527−chompDefArgsAndBody :: A.Position -> A.Located Name.Name -> Maybe Src.Type -> [Src.Pattern] -> Space.Parser E.Def (A.Located Src.Def)
528−chompDefArgsAndBody start name tipe revArgs =
529− oneOf E.DefEquals
530− [ do arg <- specialize E.DefArg Pattern.term
531− Space.chompAndCheckIndent E.DefSpace E.DefIndentEquals
532− chompDefArgsAndBody start name tipe (arg : revArgs)
533− , do word1 0x3D {-=-} E.DefEquals
534− Space.chompAndCheckIndent E.DefSpace E.DefIndentBody
535− (body, end) <- specialize E.DefBody expression
536− return
537− ( A.at start end (Src.Define name (reverse revArgs) body tipe)
538− , end
539− )
540− ]
541−
542−
543−chompMatchingName :: Name.Name -> Parser E.Def (A.Located Name.Name)
544−chompMatchingName expectedName =
545− let
546− (P.Parser parserL) = Var.lower E.DefNameRepeat
547− in
548− P.Parser $ \state@(P.State _ _ _ _ sr sc) cok eok cerr eerr ->
549− let
550− cokL name newState@(P.State _ _ _ _ er ec) =
551− if expectedName == name
552− then cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
553− else cerr sr sc (E.DefNameMatch name)
554−
555− eokL name newState@(P.State _ _ _ _ er ec) =
556− if expectedName == name
557− then eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
558− else eerr sr sc (E.DefNameMatch name)
559− in
560− parserL state cokL eokL cerr eerr
561−
562−
563−
564−
565−-- DESTRUCTURE
566−
567−
568−destructure :: Space.Parser E.Let (A.Located Src.Def)
569−destructure =
570− specialize E.LetDestruct $
571− do start <- getPosition
572− pattern <- specialize E.DestructPattern Pattern.term
573− Space.chompAndCheckIndent E.DestructSpace E.DestructIndentEquals
574− word1 0x3D {-=-} E.DestructEquals
575− Space.chompAndCheckIndent E.DestructSpace E.DestructIndentBody
576− (expr, end) <- specialize E.DestructBody expression
577− return ( A.at start end (Src.Destruct pattern expr), end )
compiler/src/Parse/Keyword.hsdeleted−265
@@ -1,265 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns #-}
3−module Parse.Keyword
4− ( type_, alias_, port_
5− , if_, then_, else_
6− , case_, of_
7− , let_, in_
8− , infix_, left_, right_, non_
9− , module_, import_, exposing_, as_
10− , effect_, where_, command_, subscription_
11− , k4, k5
12− )
13− where
14−
15−
16−import Foreign.Ptr (plusPtr)
17−import Data.Word (Word8)
18−
19−import Parse.Primitives (Parser, Row, Col)
20−import qualified Parse.Variable as Var
21−import qualified Parse.Primitives as P
22−
23−
24−
25−-- DECLARATIONS
26−
27−
28−type_ :: (Row -> Col -> x) -> Parser x ()
29−type_ tx = k4 0x74 0x79 0x70 0x65 tx
30−
31−alias_ :: (Row -> Col -> x) -> Parser x ()
32−alias_ tx = k5 0x61 0x6C 0x69 0x61 0x73 tx
33−
34−port_ :: (Row -> Col -> x) -> Parser x ()
35−port_ tx = k4 0x70 0x6F 0x72 0x74 tx
36−
37−
38−
39−-- IF EXPRESSIONS
40−
41−
42−if_ :: (Row -> Col -> x) -> Parser x ()
43−if_ tx = k2 0x69 0x66 tx
44−
45−then_ :: (Row -> Col -> x) -> Parser x ()
46−then_ tx = k4 0x74 0x68 0x65 0x6E tx
47−
48−else_ :: (Row -> Col -> x) -> Parser x ()
49−else_ tx = k4 0x65 0x6C 0x73 0x65 tx
50−
51−
52−
53−-- CASE EXPRESSIONS
54−
55−
56−case_ :: (Row -> Col -> x) -> Parser x ()
57−case_ tx = k4 0x63 0x61 0x73 0x65 tx
58−
59−of_ :: (Row -> Col -> x) -> Parser x ()
60−of_ tx = k2 0x6F 0x66 tx
61−
62−
63−
64−-- LET EXPRESSIONS
65−
66−
67−let_ :: (Row -> Col -> x) -> Parser x ()
68−let_ tx = k3 0x6C 0x65 0x74 tx
69−
70−in_ :: (Row -> Col -> x) -> Parser x ()
71−in_ tx = k2 0x69 0x6E tx
72−
73−
74−
75−-- INFIXES
76−
77−
78−infix_ :: (Row -> Col -> x) -> Parser x ()
79−infix_ tx = k5 0x69 0x6E 0x66 0x69 0x78 tx
80−
81−left_ :: (Row -> Col -> x) -> Parser x ()
82−left_ tx = k4 0x6C 0x65 0x66 0x74 tx
83−
84−right_ :: (Row -> Col -> x) -> Parser x ()
85−right_ tx = k5 0x72 0x69 0x67 0x68 0x74 tx
86−
87−non_ :: (Row -> Col -> x) -> Parser x ()
88−non_ tx = k3 0x6E 0x6F 0x6E tx
89−
90−
91−
92−-- IMPORTS
93−
94−
95−module_ :: (Row -> Col -> x) -> Parser x ()
96−module_ tx = k6 0x6D 0x6F 0x64 0x75 0x6C 0x65 tx
97−
98−import_ :: (Row -> Col -> x) -> Parser x ()
99−import_ tx = k6 0x69 0x6D 0x70 0x6F 0x72 0x74 tx
100−
101−exposing_ :: (Row -> Col -> x) -> Parser x ()
102−exposing_ tx = k8 0x65 0x78 0x70 0x6F 0x73 0x69 0x6E 0x67 tx
103−
104−as_ :: (Row -> Col -> x) -> Parser x ()
105−as_ tx = k2 0x61 0x73 tx
106−
107−
108−
109−-- EFFECTS
110−
111−
112−effect_ :: (Row -> Col -> x) -> Parser x ()
113−effect_ tx = k6 0x65 0x66 0x66 0x65 0x63 0x74 tx
114−
115−where_ :: (Row -> Col -> x) -> Parser x ()
116−where_ tx = k5 0x77 0x68 0x65 0x72 0x65 tx
117−
118−command_ :: (Row -> Col -> x) -> Parser x ()
119−command_ tx = k7 0x63 0x6F 0x6D 0x6D 0x61 0x6E 0x64 tx
120−
121−subscription_ :: (Row -> Col -> x) -> Parser x ()
122−subscription_ toError =
123− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
124− let !pos12 = plusPtr pos 12 in
125− if pos12 <= end
126− && P.unsafeIndex ( pos ) == 0x73
127− && P.unsafeIndex (plusPtr pos 1) == 0x75
128− && P.unsafeIndex (plusPtr pos 2) == 0x62
129− && P.unsafeIndex (plusPtr pos 3) == 0x73
130− && P.unsafeIndex (plusPtr pos 4) == 0x63
131− && P.unsafeIndex (plusPtr pos 5) == 0x72
132− && P.unsafeIndex (plusPtr pos 6) == 0x69
133− && P.unsafeIndex (plusPtr pos 7) == 0x70
134− && P.unsafeIndex (plusPtr pos 8) == 0x74
135− && P.unsafeIndex (plusPtr pos 9) == 0x69
136− && P.unsafeIndex (plusPtr pos 10) == 0x6F
137− && P.unsafeIndex (plusPtr pos 11) == 0x6E
138− && Var.getInnerWidth pos12 end == 0
139− then
140− let !s = P.State src pos12 end indent row (col + 12) in cok () s
141− else
142− eerr row col toError
143−
144−
145−
146−-- KEYWORDS
147−
148−
149−k2 :: Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
150−k2 w1 w2 toError =
151− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
152− let !pos2 = plusPtr pos 2 in
153− if pos2 <= end
154− && P.unsafeIndex ( pos ) == w1
155− && P.unsafeIndex (plusPtr pos 1) == w2
156− && Var.getInnerWidth pos2 end == 0
157− then
158− let !s = P.State src pos2 end indent row (col + 2) in cok () s
159− else
160− eerr row col toError
161−
162−
163−k3 :: Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
164−k3 w1 w2 w3 toError =
165− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
166− let !pos3 = plusPtr pos 3 in
167− if pos3 <= end
168− && P.unsafeIndex ( pos ) == w1
169− && P.unsafeIndex (plusPtr pos 1) == w2
170− && P.unsafeIndex (plusPtr pos 2) == w3
171− && Var.getInnerWidth pos3 end == 0
172− then
173− let !s = P.State src pos3 end indent row (col + 3) in cok () s
174− else
175− eerr row col toError
176−
177−
178−k4 :: Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
179−k4 w1 w2 w3 w4 toError =
180− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
181− let !pos4 = plusPtr pos 4 in
182− if pos4 <= end
183− && P.unsafeIndex ( pos ) == w1
184− && P.unsafeIndex (plusPtr pos 1) == w2
185− && P.unsafeIndex (plusPtr pos 2) == w3
186− && P.unsafeIndex (plusPtr pos 3) == w4
187− && Var.getInnerWidth pos4 end == 0
188− then
189− let !s = P.State src pos4 end indent row (col + 4) in cok () s
190− else
191− eerr row col toError
192−
193−
194−k5 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
195−k5 w1 w2 w3 w4 w5 toError =
196− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
197− let !pos5 = plusPtr pos 5 in
198− if pos5 <= end
199− && P.unsafeIndex ( pos ) == w1
200− && P.unsafeIndex (plusPtr pos 1) == w2
201− && P.unsafeIndex (plusPtr pos 2) == w3
202− && P.unsafeIndex (plusPtr pos 3) == w4
203− && P.unsafeIndex (plusPtr pos 4) == w5
204− && Var.getInnerWidth pos5 end == 0
205− then
206− let !s = P.State src pos5 end indent row (col + 5) in cok () s
207− else
208− eerr row col toError
209−
210−
211−k6 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
212−k6 w1 w2 w3 w4 w5 w6 toError =
213− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
214− let !pos6 = plusPtr pos 6 in
215− if pos6 <= end
216− && P.unsafeIndex ( pos ) == w1
217− && P.unsafeIndex (plusPtr pos 1) == w2
218− && P.unsafeIndex (plusPtr pos 2) == w3
219− && P.unsafeIndex (plusPtr pos 3) == w4
220− && P.unsafeIndex (plusPtr pos 4) == w5
221− && P.unsafeIndex (plusPtr pos 5) == w6
222− && Var.getInnerWidth pos6 end == 0
223− then
224− let !s = P.State src pos6 end indent row (col + 6) in cok () s
225− else
226− eerr row col toError
227−
228−
229−k7 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
230−k7 w1 w2 w3 w4 w5 w6 w7 toError =
231− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
232− let !pos7 = plusPtr pos 7 in
233− if pos7 <= end
234− && P.unsafeIndex ( pos ) == w1
235− && P.unsafeIndex (plusPtr pos 1) == w2
236− && P.unsafeIndex (plusPtr pos 2) == w3
237− && P.unsafeIndex (plusPtr pos 3) == w4
238− && P.unsafeIndex (plusPtr pos 4) == w5
239− && P.unsafeIndex (plusPtr pos 5) == w6
240− && P.unsafeIndex (plusPtr pos 6) == w7
241− && Var.getInnerWidth pos7 end == 0
242− then
243− let !s = P.State src pos7 end indent row (col + 7) in cok () s
244− else
245− eerr row col toError
246−
247−
248−k8 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
249−k8 w1 w2 w3 w4 w5 w6 w7 w8 toError =
250− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
251− let !pos8 = plusPtr pos 8 in
252− if pos8 <= end
253− && P.unsafeIndex ( pos ) == w1
254− && P.unsafeIndex (plusPtr pos 1) == w2
255− && P.unsafeIndex (plusPtr pos 2) == w3
256− && P.unsafeIndex (plusPtr pos 3) == w4
257− && P.unsafeIndex (plusPtr pos 4) == w5
258− && P.unsafeIndex (plusPtr pos 5) == w6
259− && P.unsafeIndex (plusPtr pos 6) == w7
260− && P.unsafeIndex (plusPtr pos 7) == w8
261− && Var.getInnerWidth pos8 end == 0
262− then
263− let !s = P.State src pos8 end indent row (col + 8) in cok () s
264− else
265− eerr row col toError
compiler/src/Parse/Module.hsdeleted−487
@@ -1,487 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Parse.Module
4− ( fromByteString
5− , ProjectType(..)
6− , isKernel
7− , chompImports
8− , chompImport
9− )
10− where
11−
12−
13−import qualified Data.ByteString as BS
14−import qualified Data.Name as Name
15−
16−import qualified AST.Source as Src
17−import qualified Elm.Compiler.Imports as Imports
18−import qualified Elm.Package as Pkg
19−import qualified Parse.Declaration as Decl
20−import qualified Parse.Keyword as Keyword
21−import qualified Parse.Space as Space
22−import qualified Parse.Symbol as Symbol
23−import qualified Parse.Variable as Var
24−import qualified Parse.Primitives as P
25−import Parse.Primitives hiding (State, fromByteString)
26−import qualified Reporting.Annotation as A
27−import qualified Reporting.Error.Syntax as E
28−
29−
30−
31−-- FROM BYTE STRING
32−
33−
34−fromByteString :: ProjectType -> BS.ByteString -> Either E.Error Src.Module
35−fromByteString projectType source =
36− case P.fromByteString (chompModule projectType) E.ModuleBadEnd source of
37− Right modul -> checkModule projectType modul
38− Left err -> Left (E.ParseError err)
39−
40−
41−
42−-- PROJECT TYPE
43−
44−
45−data ProjectType
46− = Package Pkg.Name
47− | Application
48−
49−
50−isCore :: ProjectType -> Bool
51−isCore projectType =
52− case projectType of
53− Package pkg -> pkg == Pkg.core
54− Application -> False
55−
56−
57−isKernel :: ProjectType -> Bool
58−isKernel projectType =
59− case projectType of
60− Package pkg -> Pkg.isKernel pkg
61− Application -> False
62−
63−
64−
65−-- MODULE
66−
67−
68−data Module =
69− Module
70− { _header :: Maybe Header
71− , _imports :: [Src.Import]
72− , _infixes :: [A.Located Src.Infix]
73− , _decls :: [Decl.Decl]
74− }
75−
76−
77−chompModule :: ProjectType -> Parser E.Module Module
78−chompModule projectType =
79− do header <- chompHeader
80− imports <- chompImports (if isCore projectType then [] else Imports.defaults)
81− infixes <- if isKernel projectType then chompInfixes [] else return []
82− decls <- specialize E.Declarations $ chompDecls []
83− return (Module header imports infixes decls)
84−
85−
86−
87−-- CHECK MODULE
88−
89−
90−checkModule :: ProjectType -> Module -> Either E.Error Src.Module
91−checkModule projectType (Module maybeHeader imports infixes decls) =
92− let
93− (values, unions, aliases, ports) = categorizeDecls [] [] [] [] decls
94− in
95− case maybeHeader of
96− Just (Header name effects exports docs) ->
97− Src.Module (Just name) exports (toDocs docs decls) imports values unions aliases infixes
98− <$> checkEffects projectType ports effects
99−
100− Nothing ->
101− Right $
102− Src.Module Nothing (A.At A.one Src.Open) (Src.NoDocs A.one) imports values unions aliases infixes $
103− case ports of
104− [] -> Src.NoEffects
105− _:_ -> Src.Ports ports
106−
107−
108−checkEffects :: ProjectType -> [Src.Port] -> Effects -> Either E.Error Src.Effects
109−checkEffects projectType ports effects =
110− case effects of
111− NoEffects region ->
112− case ports of
113− [] ->
114− Right Src.NoEffects
115−
116− Src.Port name _ : _ ->
117− case projectType of
118− Package _ -> Left (E.NoPortsInPackage name)
119− Application -> Left (E.UnexpectedPort region)
120−
121− Ports region ->
122− case projectType of
123− Package _ ->
124− Left (E.NoPortModulesInPackage region)
125−
126− Application ->
127− case ports of
128− [] -> Left (E.NoPorts region)
129− _:_ -> Right (Src.Ports ports)
130−
131− Manager region manager ->
132− if isKernel projectType then
133− case ports of
134− [] -> Right (Src.Manager region manager)
135− _:_ -> Left (E.UnexpectedPort region)
136− else
137− Left (E.NoEffectsOutsideKernel region)
138−
139−
140−
141−categorizeDecls :: [A.Located Src.Value] -> [A.Located Src.Union] -> [A.Located Src.Alias] -> [Src.Port] -> [Decl.Decl] -> ( [A.Located Src.Value], [A.Located Src.Union], [A.Located Src.Alias], [Src.Port] )
142−categorizeDecls values unions aliases ports decls =
143− case decls of
144− [] ->
145− (values, unions, aliases, ports)
146−
147− decl:otherDecls ->
148− case decl of
149− Decl.Value _ value -> categorizeDecls (value:values) unions aliases ports otherDecls
150− Decl.Union _ union -> categorizeDecls values (union:unions) aliases ports otherDecls
151− Decl.Alias _ alias -> categorizeDecls values unions (alias:aliases) ports otherDecls
152− Decl.Port _ port_ -> categorizeDecls values unions aliases (port_:ports) otherDecls
153−
154−
155−
156−-- TO DOCS
157−
158−
159−toDocs :: Either A.Region Src.Comment -> [Decl.Decl] -> Src.Docs
160−toDocs comment decls =
161− case comment of
162− Right overview ->
163− Src.YesDocs overview (getComments decls [])
164−
165− Left region ->
166− Src.NoDocs region
167−
168−
169−getComments :: [Decl.Decl] -> [(Name.Name,Src.Comment)] -> [(Name.Name,Src.Comment)]
170−getComments decls comments =
171− case decls of
172− [] ->
173− comments
174−
175− decl:otherDecls ->
176− case decl of
177− Decl.Value c (A.At _ (Src.Value n _ _ _)) -> getComments otherDecls (addComment c n comments)
178− Decl.Union c (A.At _ (Src.Union n _ _ )) -> getComments otherDecls (addComment c n comments)
179− Decl.Alias c (A.At _ (Src.Alias n _ _ )) -> getComments otherDecls (addComment c n comments)
180− Decl.Port c (Src.Port n _ ) -> getComments otherDecls (addComment c n comments)
181−
182−
183−addComment :: Maybe Src.Comment -> A.Located Name.Name -> [(Name.Name,Src.Comment)] -> [(Name.Name,Src.Comment)]
184−addComment maybeComment (A.At _ name) comments =
185− case maybeComment of
186− Just comment -> (name, comment) : comments
187− Nothing -> comments
188−
189−
190−
191−-- FRESH LINES
192−
193−
194−freshLine :: (Row -> Col -> E.Module) -> Parser E.Module ()
195−freshLine toFreshLineError =
196− do Space.chomp E.ModuleSpace
197− Space.checkFreshLine toFreshLineError
198−
199−
200−
201−-- CHOMP DECLARATIONS
202−
203−
204−chompDecls :: [Decl.Decl] -> Parser E.Decl [Decl.Decl]
205−chompDecls decls =
206− do (decl, _) <- Decl.declaration
207− oneOfWithFallback
208− [ do Space.checkFreshLine E.DeclStart
209− chompDecls (decl:decls)
210− ]
211− (reverse (decl:decls))
212−
213−
214−chompInfixes :: [A.Located Src.Infix] -> Parser E.Module [A.Located Src.Infix]
215−chompInfixes infixes =
216− oneOfWithFallback
217− [ do binop <- Decl.infix_
218− chompInfixes (binop:infixes)
219− ]
220− infixes
221−
222−
223−
224−-- MODULE DOC COMMENT
225−
226−
227−chompModuleDocCommentSpace :: Parser E.Module (Either A.Region Src.Comment)
228−chompModuleDocCommentSpace =
229− do (A.At region ()) <- addLocation (freshLine E.FreshLine)
230− oneOfWithFallback
231− [
232− do docComment <- Space.docComment E.ImportStart E.ModuleSpace
233− Space.chomp E.ModuleSpace
234− Space.checkFreshLine E.FreshLine
235− return (Right docComment)
236− ]
237− (Left region)
238−
239−
240−
241−-- HEADER
242−
243−
244−data Header =
245− Header (A.Located Name.Name) Effects (A.Located Src.Exposing) (Either A.Region Src.Comment)
246−
247−
248−data Effects
249− = NoEffects A.Region
250− | Ports A.Region
251− | Manager A.Region Src.Manager
252−
253−
254−chompHeader :: Parser E.Module (Maybe Header)
255−chompHeader =
256− do freshLine E.FreshLine
257− start <- getPosition
258− oneOfWithFallback
259− [
260− -- module MyThing exposing (..)
261− do Keyword.module_ E.ModuleProblem
262− effectEnd <- getPosition
263− Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
264− name <- addLocation (Var.moduleName E.ModuleName)
265− Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
266− Keyword.exposing_ E.ModuleProblem
267− Space.chompAndCheckIndent E.ModuleSpace E.ModuleProblem
268− exports <- addLocation (specialize E.ModuleExposing exposing)
269− comment <- chompModuleDocCommentSpace
270− return $ Just $
271− Header name (NoEffects (A.Region start effectEnd)) exports comment
272− ,
273− -- port module MyThing exposing (..)
274− do Keyword.port_ E.PortModuleProblem
275− Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
276− Keyword.module_ E.PortModuleProblem
277− effectEnd <- getPosition
278− Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
279− name <- addLocation (Var.moduleName E.PortModuleName)
280− Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
281− Keyword.exposing_ E.PortModuleProblem
282− Space.chompAndCheckIndent E.ModuleSpace E.PortModuleProblem
283− exports <- addLocation (specialize E.PortModuleExposing exposing)
284− comment <- chompModuleDocCommentSpace
285− return $ Just $
286− Header name (Ports (A.Region start effectEnd)) exports comment
287− ,
288− -- effect module MyThing where { command = MyCmd } exposing (..)
289− do Keyword.effect_ E.Effect
290− Space.chompAndCheckIndent E.ModuleSpace E.Effect
291− Keyword.module_ E.Effect
292− effectEnd <- getPosition
293− Space.chompAndCheckIndent E.ModuleSpace E.Effect
294− name <- addLocation (Var.moduleName E.ModuleName)
295− Space.chompAndCheckIndent E.ModuleSpace E.Effect
296− Keyword.where_ E.Effect
297− Space.chompAndCheckIndent E.ModuleSpace E.Effect
298− manager <- chompManager
299− Space.chompAndCheckIndent E.ModuleSpace E.Effect
300− Keyword.exposing_ E.Effect
301− Space.chompAndCheckIndent E.ModuleSpace E.Effect
302− exports <- addLocation (specialize (const E.Effect) exposing)
303− comment <- chompModuleDocCommentSpace
304− return $ Just $
305− Header name (Manager (A.Region start effectEnd) manager) exports comment
306− ]
307− -- default header
308− Nothing
309−
310−
311−chompManager :: Parser E.Module Src.Manager
312−chompManager =
313− do word1 0x7B {- { -} E.Effect
314− spaces_em
315− oneOf E.Effect
316− [ do cmd <- chompCommand
317− spaces_em
318− oneOf E.Effect
319− [ do word1 0x7D {-}-} E.Effect
320− spaces_em
321− return (Src.Cmd cmd)
322− , do word1 0x2C {-,-} E.Effect
323− spaces_em
324− sub <- chompSubscription
325− spaces_em
326− word1 0x7D {-}-} E.Effect
327− spaces_em
328− return (Src.Fx cmd sub)
329− ]
330− , do sub <- chompSubscription
331− spaces_em
332− oneOf E.Effect
333− [ do word1 0x7D {-}-} E.Effect
334− spaces_em
335− return (Src.Sub sub)
336− , do word1 0x2C {-,-} E.Effect
337− spaces_em
338− cmd <- chompCommand
339− spaces_em
340− word1 0x7D {-}-} E.Effect
341− spaces_em
342− return (Src.Fx cmd sub)
343− ]
344− ]
345−
346−
347−chompCommand :: Parser E.Module (A.Located Name.Name)
348−chompCommand =
349− do Keyword.command_ E.Effect
350− spaces_em
351− word1 0x3D {-=-} E.Effect
352− spaces_em
353− addLocation (Var.upper E.Effect)
354−
355−
356−chompSubscription :: Parser E.Module (A.Located Name.Name)
357−chompSubscription =
358− do Keyword.subscription_ E.Effect
359− spaces_em
360− word1 0x3D {-=-} E.Effect
361− spaces_em
362− addLocation (Var.upper E.Effect)
363−
364−
365−spaces_em :: Parser E.Module ()
366−spaces_em =
367− Space.chompAndCheckIndent E.ModuleSpace E.Effect
368−
369−
370−
371−-- IMPORTS
372−
373−
374−chompImports :: [Src.Import] -> Parser E.Module [Src.Import]
375−chompImports is =
376− oneOfWithFallback
377− [ do i <- chompImport
378− chompImports (i:is)
379− ]
380− (reverse is)
381−
382−
383−chompImport :: Parser E.Module Src.Import
384−chompImport =
385− do Keyword.import_ E.ImportStart
386− Space.chompAndCheckIndent E.ModuleSpace E.ImportIndentName
387− name@(A.At (A.Region _ end) _) <- addLocation (Var.moduleName E.ImportName)
388− Space.chomp E.ModuleSpace
389− oneOf E.ImportEnd
390− [ do Space.checkFreshLine E.ImportEnd
391− return $ Src.Import name Nothing (Src.Explicit [])
392− , do Space.checkIndent end E.ImportEnd
393− oneOf E.ImportAs
394− [ chompAs name
395− , chompExposing name Nothing
396− ]
397− ]
398−
399−
400−chompAs :: A.Located Name.Name -> Parser E.Module Src.Import
401−chompAs name =
402− do Keyword.as_ E.ImportAs
403− Space.chompAndCheckIndent E.ModuleSpace E.ImportIndentAlias
404− alias <- Var.upper E.ImportAlias
405− end <- getPosition
406− Space.chomp E.ModuleSpace
407− oneOf E.ImportEnd
408− [ do Space.checkFreshLine E.ImportEnd
409− return $ Src.Import name (Just alias) (Src.Explicit [])
410− , do Space.checkIndent end E.ImportEnd
411− chompExposing name (Just alias)
412− ]
413−
414−
415−chompExposing :: A.Located Name.Name -> Maybe Name.Name -> Parser E.Module Src.Import
416−chompExposing name maybeAlias =
417− do Keyword.exposing_ E.ImportExposing
418− Space.chompAndCheckIndent E.ModuleSpace E.ImportIndentExposingList
419− exposed <- specialize E.ImportExposingList exposing
420− freshLine E.ImportEnd
421− return $ Src.Import name maybeAlias exposed
422−
423−
424−
425−-- LISTING
426−
427−
428−exposing :: Parser E.Exposing Src.Exposing
429−exposing =
430− do word1 0x28 {-(-} E.ExposingStart
431− Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentValue
432− oneOf E.ExposingValue
433− [ do word2 0x2E 0x2E {-..-} E.ExposingValue
434− Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentEnd
435− word1 0x29 {-)-} E.ExposingEnd
436− return Src.Open
437− , do exposed <- chompExposed
438− Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentEnd
439− exposingHelp [exposed]
440− ]
441−
442−
443−exposingHelp :: [Src.Exposed] -> Parser E.Exposing Src.Exposing
444−exposingHelp revExposed =
445− oneOf E.ExposingEnd
446− [ do word1 0x2C {-,-} E.ExposingEnd
447− Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentValue
448− exposed <- chompExposed
449− Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentEnd
450− exposingHelp (exposed:revExposed)
451− , do word1 0x29 {-)-} E.ExposingEnd
452− return (Src.Explicit (reverse revExposed))
453− ]
454−
455−
456−chompExposed :: Parser E.Exposing Src.Exposed
457−chompExposed =
458− do start <- getPosition
459− oneOf E.ExposingValue
460− [ do name <- Var.lower E.ExposingValue
461− end <- getPosition
462− return $ Src.Lower $ A.at start end name
463− , do word1 0x28 {-(-} E.ExposingValue
464− op <- Symbol.operator E.ExposingOperator E.ExposingOperatorReserved
465− word1 0x29 {-)-} E.ExposingOperatorRightParen
466− end <- getPosition
467− return $ Src.Operator (A.Region start end) op
468− , do name <- Var.upper E.ExposingValue
469− end <- getPosition
470− Space.chompAndCheckIndent E.ExposingSpace E.ExposingIndentEnd
471− Src.Upper (A.at start end name) <$> privacy
472− ]
473−
474−
475−privacy :: Parser E.Exposing Src.Privacy
476−privacy =
477− oneOfWithFallback
478− [ do word1 0x28 {-(-} E.ExposingTypePrivacy
479− Space.chompAndCheckIndent E.ExposingSpace E.ExposingTypePrivacy
480− start <- getPosition
481− word2 0x2E 0x2E {-..-} E.ExposingTypePrivacy
482− end <- getPosition
483− Space.chompAndCheckIndent E.ExposingSpace E.ExposingTypePrivacy
484− word1 0x29 {-)-} E.ExposingTypePrivacy
485− return $ Src.Public (A.Region start end)
486− ]
487− Src.Private
compiler/src/Parse/Number.hsdeleted−305
@@ -1,305 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, UnboxedTuples #-}
3−module Parse.Number
4− ( Number(..)
5− , number
6− , Outcome(..)
7− , chompInt
8− , chompHex
9− , precedence
10− )
11− where
12−
13−
14−import Data.Word (Word8)
15−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
16−
17−import qualified AST.Utils.Binop as Binop
18−import qualified Elm.Float as EF
19−import Parse.Primitives (Parser, Row, Col)
20−import qualified Parse.Variable as Var
21−import qualified Parse.Primitives as P
22−import qualified Reporting.Error.Syntax as E
23−
24−
25−
26−-- HELPERS
27−
28−
29−isDirtyEnd :: Ptr Word8 -> Ptr Word8 -> Word8 -> Bool
30−isDirtyEnd pos end word =
31− Var.getInnerWidthHelp pos end word > 0
32−
33−
34−{-# INLINE isDecimalDigit #-}
35−isDecimalDigit :: Word8 -> Bool
36−isDecimalDigit word =
37− word <= 0x39 {-9-} && word >= 0x30 {-0-}
38−
39−
40−
41−-- NUMBERS
42−
43−
44−data Number
45− = Int Int
46− | Float EF.Float
47−
48−
49−number :: (Row -> Col -> x) -> (E.Number -> Row -> Col -> x) -> Parser x Number
50−number toExpectation toError =
51− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
52− if pos >= end then
53− eerr row col toExpectation
54−
55− else
56− let !word = P.unsafeIndex pos in
57− if not (isDecimalDigit word) then
58− eerr row col toExpectation
59−
60− else
61− let
62− outcome =
63− if word == 0x30 {-0-} then
64− chompZero (plusPtr pos 1) end
65− else
66− chompInt (plusPtr pos 1) end (fromIntegral (word - 0x30 {-0-}))
67− in
68− case outcome of
69− Err newPos problem ->
70− let
71− !newCol = col + fromIntegral (minusPtr newPos pos)
72− in
73− cerr row newCol (toError problem)
74−
75− OkInt newPos n ->
76− let
77− !newCol = col + fromIntegral (minusPtr newPos pos)
78− !integer = Int n
79− !newState = P.State src newPos end indent row newCol
80− in
81− cok integer newState
82−
83− OkFloat newPos ->
84− let
85− !newCol = col + fromIntegral (minusPtr newPos pos)
86− !copy = EF.fromPtr pos newPos
87− !float = Float copy
88− !newState = P.State src newPos end indent row newCol
89− in
90− cok float newState
91−
92−
93−
94−-- CHOMP OUTCOME
95−
96−
97−-- first Int is newPos
98−--
99−data Outcome
100− = Err (Ptr Word8) E.Number
101− | OkInt (Ptr Word8) Int
102− | OkFloat (Ptr Word8)
103−
104−
105−
106−-- CHOMP INT
107−
108−
109−chompInt :: Ptr Word8 -> Ptr Word8 -> Int -> Outcome
110−chompInt !pos end !n =
111− if pos >= end then
112−
113− OkInt pos n
114−
115− else
116−
117− let
118− !word = P.unsafeIndex pos
119− in
120− if isDecimalDigit word then
121− chompInt (plusPtr pos 1) end (10 * n + fromIntegral (word - 0x30 {-0-}))
122−
123− else if word == 0x2E {-.-} then
124− chompFraction pos end n
125−
126− else if word == 0x65 {-e-} || word == 0x45 {-E-} then
127− chompExponent (plusPtr pos 1) end
128−
129− else if isDirtyEnd pos end word then
130− Err pos E.NumberEnd
131−
132− else
133− OkInt pos n
134−
135−
136−
137−-- CHOMP FRACTION
138−
139−
140−chompFraction :: Ptr Word8 -> Ptr Word8 -> Int -> Outcome
141−chompFraction pos end n =
142− let
143− !pos1 = plusPtr pos 1
144− in
145− if pos1 >= end then
146− Err pos (E.NumberDot n)
147−
148− else if isDecimalDigit (P.unsafeIndex pos1) then
149− chompFractionHelp (plusPtr pos1 1) end
150−
151− else
152− Err pos (E.NumberDot n)
153−
154−
155−chompFractionHelp :: Ptr Word8 -> Ptr Word8 -> Outcome
156−chompFractionHelp pos end =
157− if pos >= end then
158− OkFloat pos
159−
160− else
161− let !word = P.unsafeIndex pos in
162− if isDecimalDigit word then
163− chompFractionHelp (plusPtr pos 1) end
164−
165− else if word == 0x65 {-e-} || word == 0x45 {-E-} then
166− chompExponent (plusPtr pos 1) end
167−
168− else if isDirtyEnd pos end word then
169− Err pos E.NumberEnd
170−
171− else
172− OkFloat pos
173−
174−
175−
176−-- CHOMP EXPONENT
177−
178−
179−chompExponent :: Ptr Word8 -> Ptr Word8 -> Outcome
180−chompExponent pos end =
181− if pos >= end then
182− Err pos E.NumberEnd
183−
184− else
185− let !word = P.unsafeIndex pos in
186− if isDecimalDigit word then
187− chompExponentHelp (plusPtr pos 1) end
188−
189− else if word == 0x2B {-+-} || word == 0x2D {---} then
190−
191− let !pos1 = plusPtr pos 1 in
192− if pos1 < end && isDecimalDigit (P.unsafeIndex pos1) then
193− chompExponentHelp (plusPtr pos 2) end
194− else
195− Err pos E.NumberEnd
196−
197− else
198− Err pos E.NumberEnd
199−
200−
201−chompExponentHelp :: Ptr Word8 -> Ptr Word8 -> Outcome
202−chompExponentHelp pos end =
203− if pos >= end then
204− OkFloat pos
205−
206− else if isDecimalDigit (P.unsafeIndex pos) then
207− chompExponentHelp (plusPtr pos 1) end
208−
209− else
210− OkFloat pos
211−
212−
213−
214−-- CHOMP ZERO
215−
216−
217−chompZero :: Ptr Word8 -> Ptr Word8 -> Outcome
218−chompZero pos end =
219− if pos >= end then
220− OkInt pos 0
221−
222− else
223− let !word = P.unsafeIndex pos in
224− if word == 0x78 {-x-} then
225− chompHexInt (plusPtr pos 1) end
226−
227− else if word == 0x2E {-.-} then
228− chompFraction pos end 0
229−
230− else if isDecimalDigit word then
231− Err pos E.NumberNoLeadingZero
232−
233− else if isDirtyEnd pos end word then
234− Err pos E.NumberEnd
235−
236− else
237− OkInt pos 0
238−
239−
240−chompHexInt :: Ptr Word8 -> Ptr Word8 -> Outcome
241−chompHexInt pos end =
242− let (# newPos, answer #) = chompHex pos end in
243− if answer < 0 then
244− Err newPos E.NumberHexDigit
245− else
246− OkInt newPos answer
247−
248−
249−
250−-- CHOMP HEX
251−
252−
253−-- Return -1 if it has NO digits
254−-- Return -2 if it has BAD digits
255−
256−{-# INLINE chompHex #-}
257−chompHex :: Ptr Word8 -> Ptr Word8 -> (# Ptr Word8, Int #)
258−chompHex pos end =
259− chompHexHelp pos end (-1) 0
260−
261−
262−chompHexHelp :: Ptr Word8 -> Ptr Word8 -> Int -> Int -> (# Ptr Word8, Int #)
263−chompHexHelp pos end answer accumulator =
264− if pos >= end then
265− (# pos, answer #)
266− else
267− let
268− !newAnswer =
269− stepHex pos end (P.unsafeIndex pos) accumulator
270− in
271− if newAnswer < 0 then
272− (# pos, if newAnswer == -1 then answer else -2 #)
273− else
274− chompHexHelp (plusPtr pos 1) end newAnswer newAnswer
275−
276−
277−{-# INLINE stepHex #-}
278−stepHex :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int -> Int
279−stepHex pos end word acc
280− | 0x30 {-0-} <= word && word <= 0x39 {-9-} = 16 * acc + fromIntegral (word - 0x30 {-0-})
281− | 0x61 {-a-} <= word && word <= 0x66 {-f-} = 16 * acc + 10 + fromIntegral (word - 0x61 {-a-})
282− | 0x41 {-A-} <= word && word <= 0x46 {-F-} = 16 * acc + 10 + fromIntegral (word - 0x41 {-A-})
283− | isDirtyEnd pos end word = -2
284− | True = -1
285−
286−
287−
288−-- PRECEDENCE
289−
290−
291−precedence :: (Row -> Col -> x) -> Parser x Binop.Precedence
292−precedence toExpectation =
293− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
294− if pos >= end then
295− eerr row col toExpectation
296−
297− else
298− let !word = P.unsafeIndex pos in
299− if isDecimalDigit word then
300− cok
301− (Binop.Precedence (fromIntegral (word - 0x30 {-0-})))
302− (P.State src (plusPtr pos 1) end indent row (col + 1))
303−
304− else
305− eerr row col toExpectation
compiler/src/Parse/Pattern.hsdeleted−279
@@ -1,279 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
3−module Parse.Pattern
4− ( term
5− , expression
6− )
7− where
8−
9−
10−import qualified Data.List as List
11−import qualified Data.Name as Name
12−import qualified Data.Utf8 as Utf8
13−import Foreign.Ptr (plusPtr)
14−
15−import qualified AST.Source as Src
16−import qualified Parse.Keyword as Keyword
17−import qualified Parse.Number as Number
18−import qualified Parse.Space as Space
19−import qualified Parse.String as String
20−import qualified Parse.Variable as Var
21−import qualified Parse.Primitives as P
22−import Parse.Primitives (Parser, addLocation, addEnd, getPosition, inContext, oneOf, oneOfWithFallback, word1, word2)
23−import qualified Reporting.Annotation as A
24−import qualified Reporting.Error.Syntax as E
25−
26−
27−
28−-- TERM
29−
30−
31−term :: Parser E.Pattern Src.Pattern
32−term =
33− do start <- getPosition
34− oneOf E.PStart
35− [ record start
36− , tuple start
37− , list start
38− , termHelp start
39− ]
40−
41−
42−termHelp :: A.Position -> Parser E.Pattern Src.Pattern
43−termHelp start =
44− oneOf E.PStart
45− [
46− do wildcard
47− addEnd start Src.PAnything
48− ,
49− do name <- Var.lower E.PStart
50− addEnd start (Src.PVar name)
51− ,
52− do upper <- Var.foreignUpper E.PStart
53− end <- getPosition
54− let region = A.Region start end
55− return $ A.at start end $
56− case upper of
57− Var.Unqualified name ->
58− Src.PCtor region name []
59−
60− Var.Qualified home name ->
61− Src.PCtorQual region home name []
62− ,
63− do number <- Number.number E.PStart E.PNumber
64− end <- getPosition
65− case number of
66− Number.Int int ->
67− return (A.at start end (Src.PInt int))
68−
69− Number.Float float ->
70− P.Parser $ \(P.State _ _ _ _ row col) _ _ cerr _ ->
71− let
72− width = fromIntegral (Utf8.size float)
73− in
74− cerr row (col - width) (E.PFloat width)
75− ,
76− do str <- String.string E.PStart E.PString
77− addEnd start (Src.PStr str)
78− ,
79− do chr <- String.character E.PStart E.PChar
80− addEnd start (Src.PChr chr)
81− ]
82−
83−
84−
85−-- WILDCARD
86−
87−
88−wildcard :: Parser E.Pattern ()
89−wildcard =
90− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
91− if pos == end || P.unsafeIndex pos /= 0x5F {- _ -} then
92− eerr row col E.PStart
93− else
94− let
95− !newPos = plusPtr pos 1
96− !newCol = col + 1
97− in
98− if Var.getInnerWidth newPos end > 0 then
99− let (# badPos, badCol #) = Var.chompInnerChars newPos end newCol in
100− cerr row col (E.PWildcardNotVar (Name.fromPtr pos badPos) (fromIntegral (badCol - col)))
101− else
102− let !newState = P.State src newPos end indent row newCol in
103− cok () newState
104−
105−
106−
107−-- RECORDS
108−
109−
110−record :: A.Position -> Parser E.Pattern Src.Pattern
111−record start =
112− inContext E.PRecord (word1 0x7B {- { -} E.PStart) $
113− do Space.chompAndCheckIndent E.PRecordSpace E.PRecordIndentOpen
114− oneOf E.PRecordOpen
115− [ do var <- addLocation (Var.lower E.PRecordField)
116− Space.chompAndCheckIndent E.PRecordSpace E.PRecordIndentEnd
117− recordHelp start [var]
118− , do word1 0x7D {-}-} E.PRecordEnd
119− addEnd start (Src.PRecord [])
120− ]
121−
122−
123−recordHelp :: A.Position -> [A.Located Name.Name] -> Parser E.PRecord Src.Pattern
124−recordHelp start vars =
125− oneOf E.PRecordEnd
126− [ do word1 0x2C {-,-} E.PRecordEnd
127− Space.chompAndCheckIndent E.PRecordSpace E.PRecordIndentField
128− var <- addLocation (Var.lower E.PRecordField)
129− Space.chompAndCheckIndent E.PRecordSpace E.PRecordIndentEnd
130− recordHelp start (var:vars)
131− , do word1 0x7D {-}-} E.PRecordEnd
132− addEnd start (Src.PRecord (reverse vars))
133− ]
134−
135−
136−
137−-- TUPLES
138−
139−
140−tuple :: A.Position -> Parser E.Pattern Src.Pattern
141−tuple start =
142− inContext E.PTuple (word1 0x28 {-(-} E.PStart) $
143− do Space.chompAndCheckIndent E.PTupleSpace E.PTupleIndentExpr1
144− oneOf E.PTupleOpen
145− [ do (pattern, end) <- P.specialize E.PTupleExpr expression
146− Space.checkIndent end E.PTupleIndentEnd
147− tupleHelp start pattern []
148− , do word1 0x29 {-)-} E.PTupleEnd
149− addEnd start Src.PUnit
150− ]
151−
152−
153−tupleHelp :: A.Position -> Src.Pattern -> [Src.Pattern] -> Parser E.PTuple Src.Pattern
154−tupleHelp start firstPattern revPatterns =
155− oneOf E.PTupleEnd
156− [ do word1 0x2C {-,-} E.PTupleEnd
157− Space.chompAndCheckIndent E.PTupleSpace E.PTupleIndentExprN
158− (pattern, end) <- P.specialize E.PTupleExpr expression
159− Space.checkIndent end E.PTupleIndentEnd
160− tupleHelp start firstPattern (pattern : revPatterns)
161− , do word1 0x29 {-)-} E.PTupleEnd
162− case reverse revPatterns of
163− [] ->
164− return firstPattern
165−
166− secondPattern : otherPatterns ->
167− addEnd start (Src.PTuple firstPattern secondPattern otherPatterns)
168− ]
169−
170−
171−
172−-- LIST
173−
174−
175−list :: A.Position -> Parser E.Pattern Src.Pattern
176−list start =
177− inContext E.PList (word1 0x5B {-[-} E.PStart) $
178− do Space.chompAndCheckIndent E.PListSpace E.PListIndentOpen
179− oneOf E.PListOpen
180− [ do (pattern, end) <- P.specialize E.PListExpr expression
181− Space.checkIndent end E.PListIndentEnd
182− listHelp start [pattern]
183− , do word1 0x5D {-]-} E.PListEnd
184− addEnd start (Src.PList [])
185− ]
186−
187−
188−listHelp :: A.Position -> [Src.Pattern] -> Parser E.PList Src.Pattern
189−listHelp start patterns =
190− oneOf E.PListEnd
191− [ do word1 0x2C {-,-} E.PListEnd
192− Space.chompAndCheckIndent E.PListSpace E.PListIndentExpr
193− (pattern, end) <- P.specialize E.PListExpr expression
194− Space.checkIndent end E.PListIndentEnd
195− listHelp start (pattern:patterns)
196− , do word1 0x5D {-]-} E.PListEnd
197− addEnd start (Src.PList (reverse patterns))
198− ]
199−
200−
201−
202−-- EXPRESSION
203−
204−
205−expression :: Space.Parser E.Pattern Src.Pattern
206−expression =
207− do start <- getPosition
208− ePart <- exprPart
209− exprHelp start [] ePart
210−
211−
212−exprHelp :: A.Position -> [Src.Pattern] -> (Src.Pattern, A.Position) -> Space.Parser E.Pattern Src.Pattern
213−exprHelp start revPatterns (pattern, end) =
214− oneOfWithFallback
215− [ do Space.checkIndent end E.PIndentStart
216− word2 0x3A 0x3A {-::-} E.PStart
217− Space.chompAndCheckIndent E.PSpace E.PIndentStart
218− ePart <- exprPart
219− exprHelp start (pattern:revPatterns) ePart
220− , do Space.checkIndent end E.PIndentStart
221− Keyword.as_ E.PStart
222− Space.chompAndCheckIndent E.PSpace E.PIndentAlias
223− nameStart <- getPosition
224− name <- Var.lower E.PAlias
225− newEnd <- getPosition
226− Space.chomp E.PSpace
227− let alias = A.at nameStart newEnd name
228− return
229− ( A.at start newEnd (Src.PAlias (List.foldl' cons pattern revPatterns) alias)
230− , newEnd
231− )
232− ]
233− ( List.foldl' cons pattern revPatterns
234− , end
235− )
236−
237−
238−cons :: Src.Pattern -> Src.Pattern -> Src.Pattern
239−cons tl hd =
240− A.merge hd tl (Src.PCons hd tl)
241−
242−
243−
244−-- EXPRESSION PART
245−
246−
247−exprPart :: Space.Parser E.Pattern Src.Pattern
248−exprPart =
249− oneOf E.PStart
250− [
251− do start <- getPosition
252− upper <- Var.foreignUpper E.PStart
253− end <- getPosition
254− exprTermHelp (A.Region start end) upper start []
255− ,
256− do eterm@(A.At (A.Region _ end) _) <- term
257− Space.chomp E.PSpace
258− return (eterm, end)
259− ]
260−
261−
262−exprTermHelp :: A.Region -> Var.Upper -> A.Position -> [Src.Pattern] -> Space.Parser E.Pattern Src.Pattern
263−exprTermHelp region upper start revArgs =
264− do end <- getPosition
265− Space.chomp E.PSpace
266− oneOfWithFallback
267− [ do Space.checkIndent end E.PIndentStart
268− arg <- term
269− exprTermHelp region upper start (arg:revArgs)
270− ]
271− ( A.at start end $
272− case upper of
273− Var.Unqualified name ->
274− Src.PCtor region name (reverse revArgs)
275−
276− Var.Qualified home name ->
277− Src.PCtorQual region home name (reverse revArgs)
278− , end
279− )
compiler/src/Parse/Primitives.hsdeleted−404
@@ -1,404 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing #-}
2−{-# LANGUAGE BangPatterns, Rank2Types, UnboxedTuples #-}
3−module Parse.Primitives
4− ( fromByteString
5− , Parser(..)
6− , State(..)
7− , Row
8− , Col
9− , oneOf, oneOfWithFallback
10− , inContext, specialize
11− , getPosition, getCol, addLocation, addEnd
12− , getIndent, setIndent, withIndent, withBacksetIndent
13− , word1, word2
14− , unsafeIndex, isWord, getCharWidth
15− , Snippet(..)
16− , fromSnippet
17− )
18− where
19−
20−
21−import Prelude hiding (length)
22−import qualified Control.Applicative as Applicative (Applicative(..))
23−import qualified Data.ByteString.Internal as B
24−import Data.Word (Word8, Word16)
25−import Foreign.Ptr (Ptr, plusPtr)
26−import Foreign.Storable (peek)
27−import Foreign.ForeignPtr (ForeignPtr, touchForeignPtr)
28−import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
29−
30−import qualified Reporting.Annotation as A
31−
32−
33−
34−-- PARSER
35−
36−
37−newtype Parser x a =
38− Parser (
39− forall b.
40− State
41− -> (a -> State -> b) -- consumed ok
42− -> (a -> State -> b) -- empty ok
43− -> (Row -> Col -> (Row -> Col -> x) -> b) -- consumed err
44− -> (Row -> Col -> (Row -> Col -> x) -> b) -- empty err
45− -> b
46− )
47−
48−
49−data State = -- PERF try taking some out to avoid allocation
50− State
51− { _src :: ForeignPtr Word8
52− , _pos :: !(Ptr Word8)
53− , _end :: !(Ptr Word8)
54− , _indent :: !Word16
55− , _row :: !Row
56− , _col :: !Col
57− }
58−
59−
60−type Row = Word16
61−type Col = Word16
62−
63−
64−
65−-- FUNCTOR
66−
67−
68−instance Functor (Parser x) where
69− {-# INLINE fmap #-}
70− fmap f (Parser parser) =
71− Parser $ \state cok eok cerr eerr ->
72− let
73− cok' a s = cok (f a) s
74− eok' a s = eok (f a) s
75− in
76− parser state cok' eok' cerr eerr
77−
78−
79−
80−-- APPLICATIVE
81−
82−
83−instance Applicative.Applicative (Parser x) where
84− {-# INLINE pure #-}
85− pure = return
86−
87− {-# INLINE (<*>) #-}
88− (<*>) (Parser parserFunc) (Parser parserArg) =
89− Parser $ \state cok eok cerr eerr ->
90− let
91− cokF func s1 =
92− let
93− cokA arg s2 = cok (func arg) s2
94− in
95− parserArg s1 cokA cokA cerr cerr
96−
97− eokF func s1 =
98− let
99− cokA arg s2 = cok (func arg) s2
100− eokA arg s2 = eok (func arg) s2
101− in
102− parserArg s1 cokA eokA cerr eerr
103− in
104− parserFunc state cokF eokF cerr eerr
105−
106−
107−
108−-- ONE OF
109−
110−
111−{-# INLINE oneOf #-}
112−oneOf :: (Row -> Col -> x) -> [Parser x a] -> Parser x a
113−oneOf toError parsers =
114− Parser $ \state cok eok cerr eerr ->
115− oneOfHelp state cok eok cerr eerr toError parsers
116−
117−
118−oneOfHelp
119− :: State
120− -> (a -> State -> b)
121− -> (a -> State -> b)
122− -> (Row -> Col -> (Row -> Col -> x) -> b)
123− -> (Row -> Col -> (Row -> Col -> x) -> b)
124− -> (Row -> Col -> x)
125− -> [Parser x a]
126− -> b
127−oneOfHelp state cok eok cerr eerr toError parsers =
128− case parsers of
129− Parser parser : parsers ->
130− let
131− eerr' _ _ _ =
132− oneOfHelp state cok eok cerr eerr toError parsers
133− in
134− parser state cok eok cerr eerr'
135−
136− [] ->
137− let
138− (State _ _ _ _ row col) = state
139− in
140− eerr row col toError
141−
142−
143−
144−-- ONE OF WITH FALLBACK
145−
146−
147−{-# INLINE oneOfWithFallback #-}
148−oneOfWithFallback :: [Parser x a] -> a -> Parser x a -- PERF is this function okay? Worried about allocation/laziness with fallback values.
149−oneOfWithFallback parsers fallback =
150− Parser $ \state cok eok cerr _ ->
151− oowfHelp state cok eok cerr parsers fallback
152−
153−
154−oowfHelp
155− :: State
156− -> (a -> State -> b)
157− -> (a -> State -> b)
158− -> (Row -> Col -> (Row -> Col -> x) -> b)
159− -> [Parser x a]
160− -> a
161− -> b
162−oowfHelp state cok eok cerr parsers fallback =
163− case parsers of
164− [] ->
165− eok fallback state
166−
167− Parser parser : parsers ->
168− let
169− eerr' _ _ _ =
170− oowfHelp state cok eok cerr parsers fallback
171− in
172− parser state cok eok cerr eerr'
173−
174−
175−
176−-- MONAD
177−
178−
179−instance Monad (Parser x) where
180− {-# INLINE return #-}
181− return value =
182− Parser $ \state _ eok _ _ ->
183− eok value state
184−
185− {-# INLINE (>>=) #-}
186− (Parser parserA) >>= callback =
187− Parser $ \state cok eok cerr eerr ->
188− let
189− cok' a s =
190− case callback a of
191− Parser parserB -> parserB s cok cok cerr cerr
192−
193− eok' a s =
194− case callback a of
195− Parser parserB -> parserB s cok eok cerr eerr
196− in
197− parserA state cok' eok' cerr eerr
198−
199−
200−
201−-- FROM BYTESTRING
202−
203−
204−fromByteString :: Parser x a -> (Row -> Col -> x) -> B.ByteString -> Either x a
205−fromByteString (Parser parser) toBadEnd (B.PS fptr offset length) =
206− B.accursedUnutterablePerformIO $
207− let
208− toOk' = toOk toBadEnd
209− !pos = plusPtr (unsafeForeignPtrToPtr fptr) offset
210− !end = plusPtr pos length
211− !result = parser (State fptr pos end 0 1 1) toOk' toOk' toErr toErr
212− in
213− do touchForeignPtr fptr
214− return result
215−
216−
217−toOk :: (Row -> Col -> x) -> a -> State -> Either x a
218−toOk toBadEnd !a (State _ pos end _ row col) =
219− if pos == end
220− then Right a
221− else Left (toBadEnd row col)
222−
223−
224−toErr :: Row -> Col -> (Row -> Col -> x) -> Either x a
225−toErr row col toError =
226− Left (toError row col)
227−
228−
229−
230−-- FROM SNIPPET
231−
232−
233−data Snippet =
234− Snippet
235− { _fptr :: ForeignPtr Word8
236− , _offset :: Int
237− , _length :: Int
238− , _offRow :: Row
239− , _offCol :: Col
240− }
241−
242−
243−fromSnippet :: Parser x a -> (Row -> Col -> x) -> Snippet -> Either x a
244−fromSnippet (Parser parser) toBadEnd (Snippet fptr offset length row col) =
245− B.accursedUnutterablePerformIO $
246− let
247− toOk' = toOk toBadEnd
248− !pos = plusPtr (unsafeForeignPtrToPtr fptr) offset
249− !end = plusPtr pos length
250− !result = parser (State fptr pos end 0 row col) toOk' toOk' toErr toErr
251− in
252− do touchForeignPtr fptr
253− return result
254−
255−
256−
257−-- POSITION
258−
259−
260−getCol :: Parser x Word16
261−getCol =
262− Parser $ \state@(State _ _ _ _ _ col) _ eok _ _ ->
263− eok col state
264−
265−
266−{-# INLINE getPosition #-}
267−getPosition :: Parser x A.Position
268−getPosition =
269− Parser $ \state@(State _ _ _ _ row col) _ eok _ _ ->
270− eok (A.Position row col) state
271−
272−
273−addLocation :: Parser x a -> Parser x (A.Located a)
274−addLocation (Parser parser) =
275− Parser $ \state@(State _ _ _ _ sr sc) cok eok cerr eerr ->
276− let
277− cok' a s@(State _ _ _ _ er ec) = cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) a) s
278− eok' a s@(State _ _ _ _ er ec) = eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) a) s
279− in
280− parser state cok' eok' cerr eerr
281−
282−
283−addEnd :: A.Position -> a -> Parser x (A.Located a)
284−addEnd start value =
285− Parser $ \state@(State _ _ _ _ row col) _ eok _ _ ->
286− eok (A.at start (A.Position row col) value) state
287−
288−
289−
290−-- INDENT
291−
292−
293−getIndent :: Parser x Word16
294−getIndent =
295− Parser $ \state@(State _ _ _ indent _ _) _ eok _ _ ->
296− eok indent state
297−
298−
299−setIndent :: Word16 -> Parser x ()
300−setIndent indent =
301− Parser $ \(State src pos end _ row col) _ eok _ _ ->
302− let
303− !newState = State src pos end indent row col
304− in
305− eok () newState
306−
307−
308−withIndent :: Parser x a -> Parser x a
309−withIndent (Parser parser) =
310− Parser $ \(State src pos end oldIndent row col) cok eok cerr eerr ->
311− let
312− cok' a (State s p e _ r c) = cok a (State s p e oldIndent r c)
313− eok' a (State s p e _ r c) = eok a (State s p e oldIndent r c)
314− in
315− parser (State src pos end col row col) cok' eok' cerr eerr
316−
317−
318−withBacksetIndent :: Word16 -> Parser x a -> Parser x a
319−withBacksetIndent backset (Parser parser) =
320− Parser $ \(State src pos end oldIndent row col) cok eok cerr eerr ->
321− let
322− cok' a (State s p e _ r c) = cok a (State s p e oldIndent r c)
323− eok' a (State s p e _ r c) = eok a (State s p e oldIndent r c)
324− in
325− parser (State src pos end (col - backset) row col) cok' eok' cerr eerr
326−
327−
328−
329−-- CONTEXT
330−
331−
332−inContext :: (x -> Row -> Col -> y) -> Parser y start -> Parser x a -> Parser y a
333−inContext addContext (Parser parserStart) (Parser parserA) =
334− Parser $ \state@(State _ _ _ _ row col) cok eok cerr eerr ->
335− let
336− cerrA r c tx = cerr row col (addContext (tx r c))
337− eerrA r c tx = eerr row col (addContext (tx r c))
338−
339− cokS _ s = parserA s cok cok cerrA cerrA
340− eokS _ s = parserA s cok eok cerrA eerrA
341− in
342− parserStart state cokS eokS cerr eerr
343−
344−
345−specialize :: (x -> Row -> Col -> y) -> Parser x a -> Parser y a
346−specialize addContext (Parser parser) =
347− Parser $ \state@(State _ _ _ _ row col) cok eok cerr eerr ->
348− let
349− cerr' r c tx = cerr row col (addContext (tx r c))
350− eerr' r c tx = eerr row col (addContext (tx r c))
351− in
352− parser state cok eok cerr' eerr'
353−
354−
355−
356−-- SYMBOLS
357−
358−
359−word1 :: Word8 -> (Row -> Col -> x) -> Parser x ()
360−word1 word toError =
361− Parser $ \(State src pos end indent row col) cok _ _ eerr ->
362− if pos < end && unsafeIndex pos == word then
363− let !newState = State src (plusPtr pos 1) end indent row (col + 1) in
364− cok () newState
365− else
366− eerr row col toError
367−
368−
369−word2 :: Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
370−word2 w1 w2 toError =
371− Parser $ \(State src pos end indent row col) cok _ _ eerr ->
372− let
373− !pos1 = plusPtr pos 1
374− in
375− if pos1 < end && unsafeIndex pos == w1 && unsafeIndex pos1 == w2 then
376− let !newState = State src (plusPtr pos 2) end indent row (col + 2) in
377− cok () newState
378− else
379− eerr row col toError
380−
381−
382−
383−-- LOW-LEVEL CHECKS
384−
385−
386−unsafeIndex :: Ptr Word8 -> Word8
387−unsafeIndex ptr =
388− B.accursedUnutterablePerformIO (peek ptr)
389−
390−
391−{-# INLINE isWord #-}
392−isWord :: Ptr Word8 -> Ptr Word8 -> Word8 -> Bool
393−isWord pos end word =
394− pos < end && unsafeIndex pos == word
395−
396−
397−getCharWidth :: Word8 -> Int
398−getCharWidth word
399− | word < 0x80 = 1
400− | word < 0xc0 = error "Need UTF-8 encoded input. Ran into unrecognized bits."
401− | word < 0xe0 = 2
402− | word < 0xf0 = 3
403− | word < 0xf8 = 4
404− | True = error "Need UTF-8 encoded input. Ran into unrecognized bits."
compiler/src/Parse/Shader.hsdeleted−181
@@ -1,181 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, UnboxedTuples #-}
3−module Parse.Shader
4− ( shader
5− )
6− where
7−
8−
9−import qualified Data.ByteString.Internal as B
10−import qualified Data.ByteString.UTF8 as BS_UTF8
11−import qualified Data.Map as Map
12−import qualified Data.Name as Name
13−import Data.Word (Word8)
14−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
15−import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
16−import qualified Language.GLSL.Parser as GLP
17−import qualified Language.GLSL.Syntax as GLS
18−import qualified Text.Parsec as Parsec
19−import qualified Text.Parsec.Error as Parsec
20−
21−import qualified AST.Source as Src
22−import qualified AST.Utils.Shader as Shader
23−import Parse.Primitives (Parser, Row, Col)
24−import qualified Parse.Primitives as P
25−import qualified Reporting.Annotation as A
26−import qualified Reporting.Error.Syntax as E
27−
28−
29−
30−-- SHADER
31−
32−
33−shader :: A.Position -> Parser E.Expr Src.Expr
34−shader start@(A.Position row col) =
35− do block <- parseBlock
36− shdr <- parseGlsl row col block
37− end <- P.getPosition
38− return (A.at start end (Src.Shader (Shader.fromChars block) shdr))
39−
40−
41−
42−-- BLOCK
43−
44−
45−parseBlock :: Parser E.Expr [Char]
46−parseBlock =
47− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
48− let
49− !pos6 = plusPtr pos 6
50− in
51− if pos6 <= end
52− && P.unsafeIndex ( pos ) == 0x5B {- [ -}
53− && P.unsafeIndex (plusPtr pos 1) == 0x67 {- g -}
54− && P.unsafeIndex (plusPtr pos 2) == 0x6C {- l -}
55− && P.unsafeIndex (plusPtr pos 3) == 0x73 {- s -}
56− && P.unsafeIndex (plusPtr pos 4) == 0x6C {- l -}
57− && P.unsafeIndex (plusPtr pos 5) == 0x7C {- | -}
58− then
59− let
60− (# status, newPos, newRow, newCol #) =
61− eatShader pos6 end row (col + 6)
62− in
63− case status of
64− Good ->
65− let
66− !off = minusPtr pos6 (unsafeForeignPtrToPtr src)
67− !len = minusPtr newPos pos6
68− !block = BS_UTF8.toString (B.PS src off len)
69− !newState = P.State src (plusPtr newPos 2) end indent newRow (newCol + 2)
70− in
71− cok block newState
72−
73− Unending ->
74− cerr row col E.EndlessShader
75−
76− else
77− eerr row col E.Start
78−
79−
80−data Status
81− = Good
82− | Unending
83−
84−
85−eatShader :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# Status, Ptr Word8, Row, Col #)
86−eatShader pos end row col =
87− if pos >= end then
88− (# Unending, pos, row, col #)
89−
90− else
91− let !word = P.unsafeIndex pos in
92− if word == 0x007C {- | -} && P.isWord (plusPtr pos 1) end 0x5D {- ] -} then
93− (# Good, pos, row, col #)
94−
95− else if word == 0x0A {- \n -} then
96− eatShader (plusPtr pos 1) end (row + 1) 1
97−
98− else
99− let !newPos = plusPtr pos (P.getCharWidth word) in
100− eatShader newPos end row (col + 1)
101−
102−
103−
104−-- GLSL
105−
106−
107−parseGlsl :: Row -> Col -> [Char] -> Parser E.Expr Shader.Types
108−parseGlsl startRow startCol src =
109− case GLP.parse src of
110− Right (GLS.TranslationUnit decls) ->
111− return (foldr addInput emptyTypes (concatMap extractInputs decls))
112−
113− Left err ->
114− let
115− pos = Parsec.errorPos err
116− row = fromIntegral (Parsec.sourceLine pos)
117− col = fromIntegral (Parsec.sourceColumn pos)
118− msg =
119− Parsec.showErrorMessages
120− "or"
121− "unknown parse error"
122− "expecting"
123− "unexpected"
124− "end of input"
125− (Parsec.errorMessages err)
126− in
127− if row == 1
128− then failure startRow (startCol + 6 + col) msg
129− else failure (startRow + row - 1) col msg
130−
131−
132−failure :: Row -> Col -> [Char] -> Parser E.Expr a
133−failure row col msg =
134− P.Parser $ \(P.State _ _ _ _ _ _) _ _ cerr _ ->
135− cerr row col (E.ShaderProblem msg)
136−
137−
138−
139−-- INPUTS
140−
141−
142−emptyTypes :: Shader.Types
143−emptyTypes =
144− Shader.Types Map.empty Map.empty Map.empty
145−
146−
147−addInput :: (GLS.StorageQualifier, Shader.Type, [Char]) -> Shader.Types -> Shader.Types
148−addInput (qual, tipe, name) glDecls =
149− case qual of
150− GLS.Attribute -> glDecls { Shader._attribute = Map.insert (Name.fromChars name) tipe (Shader._attribute glDecls) }
151− GLS.Uniform -> glDecls { Shader._uniform = Map.insert (Name.fromChars name) tipe (Shader._uniform glDecls) }
152− GLS.Varying -> glDecls { Shader._varying = Map.insert (Name.fromChars name) tipe (Shader._varying glDecls) }
153− _ -> error "Should never happen due to `extractInputs` function"
154−
155−
156−extractInputs :: GLS.ExternalDeclaration -> [(GLS.StorageQualifier, Shader.Type, [Char])]
157−extractInputs decl =
158− case decl of
159− GLS.Declaration
160− (GLS.InitDeclaration
161− (GLS.TypeDeclarator
162− (GLS.FullType
163− (Just (GLS.TypeQualSto qual))
164− (GLS.TypeSpec _prec (GLS.TypeSpecNoPrecision tipe _mexpr1))))
165− [GLS.InitDecl name _mexpr2 _mexpr3]
166− ) ->
167− case elem qual [GLS.Attribute, GLS.Varying, GLS.Uniform] of
168− False -> []
169− True ->
170− case tipe of
171− GLS.Vec2 -> [(qual, Shader.V2, name)]
172− GLS.Vec3 -> [(qual, Shader.V3, name)]
173− GLS.Vec4 -> [(qual, Shader.V4, name)]
174− GLS.Mat4 -> [(qual, Shader.M4, name)]
175− GLS.Int -> [(qual, Shader.Int, name)]
176− GLS.Float -> [(qual, Shader.Float, name)]
177− GLS.Sampler2D -> [(qual, Shader.Texture, name)]
178− _ -> []
179− _ -> []
180−
181−
compiler/src/Parse/Space.hsdeleted−273
@@ -1,273 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
3−module Parse.Space
4− ( Parser
5− --
6− , chomp
7− , chompAndCheckIndent
8− --
9− , checkIndent
10− , checkAligned
11− , checkFreshLine
12− --
13− , docComment
14− )
15− where
16−
17−
18−import Data.Word (Word8, Word16)
19−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
20−import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
21−
22−import qualified AST.Source as Src
23−import Parse.Primitives (Row, Col)
24−import qualified Parse.Primitives as P
25−import qualified Reporting.Annotation as A
26−import qualified Reporting.Error.Syntax as E
27−
28−
29−
30−-- SPACE PARSING
31−
32−
33−type Parser x a =
34− P.Parser x (a, A.Position)
35−
36−
37−
38−-- CHOMP
39−
40−
41−chomp :: (E.Space -> Row -> Col -> x) -> P.Parser x ()
42−chomp toError =
43− P.Parser $ \(P.State src pos end indent row col) cok _ cerr _ ->
44− let
45− (# status, newPos, newRow, newCol #) = eatSpaces pos end row col
46− in
47− case status of
48− Good ->
49− let
50− !newState = P.State src newPos end indent newRow newCol
51− in
52− cok () newState
53−
54− HasTab -> cerr newRow newCol (toError E.HasTab)
55− EndlessMultiComment -> cerr newRow newCol (toError E.EndlessMultiComment)
56−
57−
58−
59−-- CHECKS -- to be called right after a `chomp`
60−
61−
62−checkIndent :: A.Position -> (Row -> Col -> x) -> P.Parser x ()
63−checkIndent (A.Position endRow endCol) toError =
64− P.Parser $ \state@(P.State _ _ _ indent _ col) _ eok _ eerr ->
65− if col > indent && col > 1
66− then eok () state
67− else eerr endRow endCol toError
68−
69−
70−checkAligned :: (Word16 -> Row -> Col -> x) -> P.Parser x ()
71−checkAligned toError =
72− P.Parser $ \state@(P.State _ _ _ indent row col) _ eok _ eerr ->
73− if col == indent
74− then eok () state
75− else eerr row col (toError indent)
76−
77−
78−checkFreshLine :: (Row -> Col -> x) -> P.Parser x ()
79−checkFreshLine toError =
80− P.Parser $ \state@(P.State _ _ _ _ row col) _ eok _ eerr ->
81− if col == 1
82− then eok () state
83− else eerr row col toError
84−
85−
86−
87−-- CHOMP AND CHECK
88−
89−
90−chompAndCheckIndent :: (E.Space -> Row -> Col -> x) -> (Row -> Col -> x) -> P.Parser x ()
91−chompAndCheckIndent toSpaceError toIndentError =
92− P.Parser $ \(P.State src pos end indent row col) cok _ cerr _ ->
93− let
94− (# status, newPos, newRow, newCol #) = eatSpaces pos end row col
95− in
96− case status of
97− Good ->
98− if newCol > indent && newCol > 1
99− then
100−
101− let
102− !newState = P.State src newPos end indent newRow newCol
103− in
104− cok () newState
105−
106− else
107− cerr row col toIndentError
108−
109− HasTab -> cerr newRow newCol (toSpaceError E.HasTab)
110− EndlessMultiComment -> cerr newRow newCol (toSpaceError E.EndlessMultiComment)
111−
112−
113−
114−-- EAT SPACES
115−
116−
117−data Status
118− = Good
119− | HasTab
120− | EndlessMultiComment
121−
122−
123−eatSpaces :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# Status, Ptr Word8, Row, Col #)
124−eatSpaces pos end row col =
125− if pos >= end then
126− (# Good, pos, row, col #)
127−
128− else
129− case P.unsafeIndex pos of
130− 0x20 {- -} ->
131− eatSpaces (plusPtr pos 1) end row (col + 1)
132−
133− 0x0A {- \n -} ->
134− eatSpaces (plusPtr pos 1) end (row + 1) 1
135−
136− 0x7B {- { -} ->
137− eatMultiComment pos end row col
138−
139− 0x2D {- - -} ->
140− let !pos1 = plusPtr pos 1 in
141− if pos1 < end && P.unsafeIndex pos1 == 0x2D {- - -} then
142− eatLineComment (plusPtr pos 2) end row (col + 2)
143− else
144− (# Good, pos, row, col #)
145−
146− 0x0D {- \r -} ->
147− eatSpaces (plusPtr pos 1) end row col
148−
149− 0x09 {- \t -} ->
150− (# HasTab, pos, row, col #)
151−
152− _ ->
153− (# Good, pos, row, col #)
154−
155−
156−
157−-- LINE COMMENTS
158−
159−
160−eatLineComment :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# Status, Ptr Word8, Row, Col #)
161−eatLineComment pos end row col =
162− if pos >= end then
163− (# Good, pos, row, col #)
164−
165− else
166− let !word = P.unsafeIndex pos in
167− if word == 0x0A {- \n -} then
168− eatSpaces (plusPtr pos 1) end (row + 1) 1
169− else
170− let !newPos = plusPtr pos (P.getCharWidth word) in
171− eatLineComment newPos end row (col + 1)
172−
173−
174−
175−-- MULTI COMMENTS
176−
177−
178−eatMultiComment :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> (# Status, Ptr Word8, Row, Col #)
179−eatMultiComment pos end row col =
180− let
181− !pos1 = plusPtr pos 1
182− !pos2 = plusPtr pos 2
183− in
184− if pos2 >= end then
185− (# Good, pos, row, col #)
186−
187− else if P.unsafeIndex pos1 == 0x2D {- - -} then
188−
189− if P.unsafeIndex pos2 == 0x7C {- | -} then
190− (# Good, pos, row, col #)
191− else
192− let
193− (# status, newPos, newRow, newCol #) =
194− eatMultiCommentHelp pos2 end row (col + 2) 1
195− in
196− case status of
197− MultiGood -> eatSpaces newPos end newRow newCol
198− MultiTab -> (# HasTab, newPos, newRow, newCol #)
199− MultiEndless -> (# EndlessMultiComment, pos, row, col #)
200−
201− else
202− (# Good, pos, row, col #)
203−
204−
205−data MultiStatus
206− = MultiGood
207− | MultiTab
208− | MultiEndless
209−
210−
211−eatMultiCommentHelp :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> Word16 -> (# MultiStatus, Ptr Word8, Row, Col #)
212−eatMultiCommentHelp pos end row col openComments =
213− if pos >= end then
214− (# MultiEndless, pos, row, col #)
215−
216− else
217− let !word = P.unsafeIndex pos in
218− if word == 0x0A {- \n -} then
219− eatMultiCommentHelp (plusPtr pos 1) end (row + 1) 1 openComments
220−
221− else if word == 0x09 {- \t -} then
222− (# MultiTab, pos, row, col #)
223−
224− else if word == 0x2D {- - -} && P.isWord (plusPtr pos 1) end 0x7D {- } -} then
225− if openComments == 1 then
226− (# MultiGood, plusPtr pos 2, row, col + 2 #)
227− else
228− eatMultiCommentHelp (plusPtr pos 2) end row (col + 2) (openComments - 1)
229−
230− else if word == 0x7B {- { -} && P.isWord (plusPtr pos 1) end 0x2D {- - -} then
231− eatMultiCommentHelp (plusPtr pos 2) end row (col + 2) (openComments + 1)
232−
233− else
234− let !newPos = plusPtr pos (P.getCharWidth word) in
235− eatMultiCommentHelp newPos end row (col + 1) openComments
236−
237−
238−
239−-- DOCUMENTATION COMMENT
240−
241−
242−docComment :: (Row -> Col -> x) -> (E.Space -> Row -> Col -> x) -> P.Parser x Src.Comment
243−docComment toExpectation toSpaceError =
244− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
245− let
246− !pos3 = plusPtr pos 3
247− in
248− if pos3 <= end
249− && P.unsafeIndex ( pos ) == 0x7B {- { -}
250− && P.unsafeIndex (plusPtr pos 1) == 0x2D {- - -}
251− && P.unsafeIndex (plusPtr pos 2) == 0x7C {- | -}
252− then
253− let
254− !col3 = col + 3
255−
256− (# status, newPos, newRow, newCol #) =
257− eatMultiCommentHelp pos3 end row col3 1
258− in
259− case status of
260− MultiGood ->
261− let
262− !off = minusPtr pos3 (unsafeForeignPtrToPtr src)
263− !len = minusPtr newPos pos3 - 2
264− !snippet = P.Snippet src off len row col3
265− !comment = Src.Comment snippet
266− !newState = P.State src newPos end indent newRow newCol
267− in
268− cok comment newState
269−
270− MultiTab -> cerr newRow newCol (toSpaceError E.HasTab)
271− MultiEndless -> cerr row col (toSpaceError E.EndlessMultiComment)
272− else
273− eerr row col toExpectation
compiler/src/Parse/String.hsdeleted−343
@@ -1,343 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−{-# LANGUAGE BangPatterns, MagicHash, OverloadedStrings, UnboxedTuples #-}
3−module Parse.String
4− ( string
5− , character
6− )
7− where
8−
9−
10−import qualified Data.Utf8 as Utf8
11−import Data.Word (Word8, Word16)
12−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
13−
14−import qualified Elm.String as ES
15−import Parse.Primitives (Parser, Row, Col)
16−import qualified Parse.Number as Number
17−import qualified Parse.Primitives as P
18−import qualified Reporting.Error.Syntax as E
19−
20−
21−
22−-- CHARACTER
23−
24−
25−character :: (Row -> Col -> x) -> (E.Char -> Row -> Col -> x) -> Parser x ES.String
26−character toExpectation toError =
27− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
28− if pos >= end || P.unsafeIndex pos /= 0x27 {- ' -} then
29− eerr row col toExpectation
30−
31− else
32− case chompChar (plusPtr pos 1) end row (col + 1) 0 placeholder of
33− Good newPos newCol numChars mostRecent ->
34− if numChars /= 1 then
35− cerr row col (toError (E.CharNotString (fromIntegral (newCol - col))))
36− else
37− let
38− !newState = P.State src newPos end indent row newCol
39− !char = ES.fromChunks [mostRecent]
40− in
41− cok char newState
42−
43− CharEndless newCol ->
44− cerr row newCol (toError E.CharEndless)
45−
46− CharEscape r c escape ->
47− cerr r c (toError (E.CharEscape escape))
48−
49−
50−data CharResult
51− = Good (Ptr Word8) Col Word16 ES.Chunk
52− | CharEndless Col
53− | CharEscape Row Col E.Escape
54−
55−
56−chompChar :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> Word16 -> ES.Chunk -> CharResult
57−chompChar pos end row col numChars mostRecent =
58− if pos >= end then
59− CharEndless col
60−
61− else
62− let
63− !word = P.unsafeIndex pos
64− in
65− if word == 0x27 {- ' -} then
66− Good (plusPtr pos 1) (col + 1) numChars mostRecent
67−
68− else if word == 0x0A {- \n -} then
69− CharEndless col
70−
71− else if word == 0x22 {- " -} then
72− chompChar (plusPtr pos 1) end row (col + 1) (numChars + 1) doubleQuote
73−
74− else if word == 0x5C {- \ -} then
75− case eatEscape (plusPtr pos 1) end row col of
76− EscapeNormal ->
77− chompChar (plusPtr pos 2) end row (col + 2) (numChars + 1) (ES.Slice pos 2)
78−
79− EscapeUnicode delta code ->
80− chompChar (plusPtr pos delta) end row (col + fromIntegral delta) (numChars + 1) (ES.CodePoint code)
81−
82− EscapeProblem r c badEscape ->
83− CharEscape r c badEscape
84−
85− EscapeEndOfFile ->
86− CharEndless col
87−
88− else
89− let
90− !width = P.getCharWidth word
91− !newPos = plusPtr pos width
92− in
93− chompChar newPos end row (col + 1) (numChars + 1) (ES.Slice pos width)
94−
95−
96−
97−-- STRINGS
98−
99−
100−string :: (Row -> Col -> x) -> (E.String -> Row -> Col -> x) -> Parser x ES.String
101−string toExpectation toError =
102− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
103− if isDoubleQuote pos end then
104−
105− let
106− !pos1 = plusPtr pos 1
107− in
108− case
109− if isDoubleQuote pos1 end then
110− let !pos2 = plusPtr pos 2 in
111− if isDoubleQuote pos2 end then
112− let
113− !pos3 = plusPtr pos 3
114− !col3 = col + 3
115− in
116− multiString pos3 end row col3 pos3 row col mempty
117− else
118− Ok pos2 row (col + 2) Utf8.empty
119− else
120− singleString pos1 end row (col + 1) pos1 mempty
121− of
122− Ok newPos newRow newCol utf8 ->
123− let
124− !newState =
125− P.State src newPos end indent newRow newCol
126− in
127− cok utf8 newState
128−
129− Err r c x ->
130− cerr r c (toError x)
131−
132− else
133− eerr row col toExpectation
134−
135−
136−{-# INLINE isDoubleQuote #-}
137−isDoubleQuote :: Ptr Word8 -> Ptr Word8 -> Bool
138−isDoubleQuote pos end =
139− pos < end && P.unsafeIndex pos == 0x22 {- " -}
140−
141−
142−data StringResult
143− = Ok (Ptr Word8) Row Col !ES.String
144− | Err Row Col E.String
145−
146−
147−finalize :: Ptr Word8 -> Ptr Word8 -> [ES.Chunk] -> ES.String
148−finalize start end revChunks =
149− ES.fromChunks $ reverse $
150− if start == end then
151− revChunks
152− else
153− ES.Slice start (minusPtr end start) : revChunks
154−
155−
156−addEscape :: ES.Chunk -> Ptr Word8 -> Ptr Word8 -> [ES.Chunk] -> [ES.Chunk]
157−addEscape chunk start end revChunks =
158− if start == end then
159− chunk : revChunks
160− else
161− chunk : ES.Slice start (minusPtr end start) : revChunks
162−
163−
164−
165−-- SINGLE STRINGS
166−
167−
168−singleString :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> Ptr Word8 -> [ES.Chunk] -> StringResult
169−singleString pos end row col initialPos revChunks =
170− if pos >= end then
171− Err row col E.StringEndless_Single
172−
173− else
174− let
175− !word = P.unsafeIndex pos
176− in
177− if word == 0x22 {- " -} then
178− Ok (plusPtr pos 1) row (col + 1) $
179− finalize initialPos pos revChunks
180−
181− else if word == 0x0A {- \n -} then
182− Err row col E.StringEndless_Single
183−
184− else if word == 0x27 {- ' -} then
185− let !newPos = plusPtr pos 1 in
186− singleString newPos end row (col + 1) newPos $
187− addEscape singleQuote initialPos pos revChunks
188−
189− else if word == 0x5C {- \ -} then
190− case eatEscape (plusPtr pos 1) end row col of
191− EscapeNormal ->
192− singleString (plusPtr pos 2) end row (col + 2) initialPos revChunks
193−
194− EscapeUnicode delta code ->
195− let !newPos = plusPtr pos delta in
196− singleString newPos end row (col + fromIntegral delta) newPos $
197− addEscape (ES.CodePoint code) initialPos pos revChunks
198−
199− EscapeProblem r c x ->
200− Err r c (E.StringEscape x)
201−
202− EscapeEndOfFile ->
203− Err row (col + 1) E.StringEndless_Single
204−
205− else
206− let !newPos = plusPtr pos (P.getCharWidth word) in
207− singleString newPos end row (col + 1) initialPos revChunks
208−
209−
210−
211−-- MULTI STRINGS
212−
213−
214−multiString :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> Ptr Word8 -> Row -> Col -> [ES.Chunk] -> StringResult
215−multiString pos end row col initialPos sr sc revChunks =
216− if pos >= end then
217− Err sr sc E.StringEndless_Multi
218−
219− else
220− let !word = P.unsafeIndex pos in
221− if word == 0x22 {- " -} && isDoubleQuote (plusPtr pos 1) end && isDoubleQuote (plusPtr pos 2) end then
222− Ok (plusPtr pos 3) row (col + 3) $
223− finalize initialPos pos revChunks
224−
225− else if word == 0x27 {- ' -} then
226− let !pos1 = plusPtr pos 1 in
227− multiString pos1 end row (col + 1) pos1 sr sc $
228− addEscape singleQuote initialPos pos revChunks
229−
230− else if word == 0x0A {- \n -} then
231− let !pos1 = plusPtr pos 1 in
232− multiString pos1 end (row + 1) 1 pos1 sr sc $
233− addEscape newline initialPos pos revChunks
234−
235− else if word == 0x0D {- \r -} then
236− let !pos1 = plusPtr pos 1 in
237− multiString pos1 end row col pos1 sr sc $
238− addEscape carriageReturn initialPos pos revChunks
239−
240− else if word == 0x5C {- \ -} then
241− case eatEscape (plusPtr pos 1) end row col of
242− EscapeNormal ->
243− multiString (plusPtr pos 2) end row (col + 2) initialPos sr sc revChunks
244−
245− EscapeUnicode delta code ->
246− let !newPos = plusPtr pos delta in
247− multiString newPos end row (col + fromIntegral delta) newPos sr sc $
248− addEscape (ES.CodePoint code) initialPos pos revChunks
249−
250− EscapeProblem r c x ->
251− Err r c (E.StringEscape x)
252−
253− EscapeEndOfFile ->
254− Err sr sc E.StringEndless_Multi
255−
256− else
257− let !newPos = plusPtr pos (P.getCharWidth word) in
258− multiString newPos end row (col + 1) initialPos sr sc revChunks
259−
260−
261−
262−-- ESCAPE CHARACTERS
263−
264−
265−data Escape
266− = EscapeNormal
267− | EscapeUnicode !Int !Int
268− | EscapeEndOfFile
269− | EscapeProblem Row Col E.Escape
270−
271−
272−eatEscape :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> Escape
273−eatEscape pos end row col =
274− if pos >= end then
275− EscapeEndOfFile
276−
277− else
278− case P.unsafeIndex pos of
279− 0x6E {- n -} -> EscapeNormal
280− 0x72 {- r -} -> EscapeNormal
281− 0x74 {- t -} -> EscapeNormal
282− 0x22 {- " -} -> EscapeNormal
283− 0x27 {- ' -} -> EscapeNormal
284− 0x5C {- \ -} -> EscapeNormal
285− 0x75 {- u -} -> eatUnicode (plusPtr pos 1) end row col
286− _ -> EscapeProblem row col E.EscapeUnknown
287−
288−
289−eatUnicode :: Ptr Word8 -> Ptr Word8 -> Row -> Col -> Escape
290−eatUnicode pos end row col =
291− if pos >= end || P.unsafeIndex pos /= 0x7B {- { -} then
292− EscapeProblem row col (E.BadUnicodeFormat 2)
293− else
294− let
295− !digitPos = plusPtr pos 1
296− (# newPos, code #) = Number.chompHex digitPos end
297− !numDigits = minusPtr newPos digitPos
298− in
299− if newPos >= end || P.unsafeIndex newPos /= 0x7D {- } -} then
300− EscapeProblem row col $ E.BadUnicodeFormat (2 + fromIntegral (minusPtr newPos pos))
301−
302− else if code < 0 || 0x10FFFF < code then
303− EscapeProblem row col $ E.BadUnicodeCode (3 + fromIntegral (minusPtr newPos pos))
304−
305− else if numDigits < 4 || 6 < numDigits then
306− EscapeProblem row col $
307− E.BadUnicodeLength
308− (3 + fromIntegral (minusPtr newPos pos))
309− numDigits
310− code
311−
312− else
313− EscapeUnicode (numDigits + 4) code
314−
315−
316−{-# NOINLINE singleQuote #-}
317−singleQuote :: ES.Chunk
318−singleQuote =
319− ES.Escape 0x27 {-'-}
320−
321−
322−{-# NOINLINE doubleQuote #-}
323−doubleQuote :: ES.Chunk
324−doubleQuote =
325− ES.Escape 0x22 {-"-}
326−
327−
328−{-# NOINLINE newline #-}
329−newline :: ES.Chunk
330−newline =
331− ES.Escape 0x6E {-n-}
332−
333−
334−{-# NOINLINE carriageReturn #-}
335−carriageReturn :: ES.Chunk
336−carriageReturn =
337− ES.Escape 0x72 {-r-}
338−
339−
340−{-# NOINLINE placeholder #-}
341−placeholder :: ES.Chunk
342−placeholder =
343− ES.CodePoint 0xFFFD {-replacement character-}
compiler/src/Parse/Symbol.hsdeleted−79
@@ -1,79 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
3−module Parse.Symbol
4− ( operator
5− , BadOperator(..)
6− , binopCharSet
7− )
8− where
9−
10−
11−import qualified Data.Char as Char
12−import qualified Data.IntSet as IntSet
13−import qualified Data.Name as Name
14−import qualified Data.Vector as Vector
15−import Foreign.Ptr (Ptr, plusPtr, minusPtr)
16−import GHC.Word (Word8)
17−
18−import Parse.Primitives (Parser, Row, Col)
19−import qualified Parse.Primitives as P
20−
21−
22−
23−-- OPERATOR
24−
25−
26−data BadOperator
27− = BadDot
28− | BadPipe
29− | BadArrow
30− | BadEquals
31− | BadHasType
32−
33−
34−operator :: (Row -> Col -> x) -> (BadOperator -> Row -> Col -> x) -> Parser x Name.Name
35−operator toExpectation toError =
36− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
37− let !newPos = chompOps pos end in
38− if pos == newPos then
39− eerr row col toExpectation
40−
41− else
42− case Name.fromPtr pos newPos of
43− "." -> eerr row col (toError BadDot)
44− "|" -> cerr row col (toError BadPipe)
45− "->" -> cerr row col (toError BadArrow)
46− "=" -> cerr row col (toError BadEquals)
47− ":" -> cerr row col (toError BadHasType)
48− op ->
49− let
50− !newCol = col + fromIntegral (minusPtr newPos pos)
51− !newState = P.State src newPos end indent row newCol
52− in
53− cok op newState
54−
55−
56−chompOps :: Ptr Word8 -> Ptr Word8 -> Ptr Word8
57−chompOps pos end =
58− if pos < end && isBinopCharHelp (P.unsafeIndex pos) then
59− chompOps (plusPtr pos 1) end
60− else
61− pos
62−
63−
64−{-# INLINE isBinopCharHelp #-}
65−isBinopCharHelp :: Word8 -> Bool
66−isBinopCharHelp word =
67− word < 128 && Vector.unsafeIndex binopCharVector (fromIntegral word)
68−
69−
70−{-# NOINLINE binopCharVector #-}
71−binopCharVector :: Vector.Vector Bool
72−binopCharVector =
73− Vector.generate 128 (\i -> IntSet.member i binopCharSet)
74−
75−
76−{-# NOINLINE binopCharSet #-}
77−binopCharSet :: IntSet.IntSet
78−binopCharSet =
79− IntSet.fromList (map Char.ord "+-/*=.<>:&|^?%!")
compiler/src/Parse/Type.hsdeleted−203
@@ -1,203 +0,0 @@
1−{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Parse.Type
4− ( expression
5− , variant
6− )
7− where
8−
9−
10−import qualified Data.Name as Name
11−
12−import qualified AST.Source as Src
13−import Parse.Primitives (Parser, addLocation, addEnd, getPosition, inContext, specialize, oneOf, oneOfWithFallback, word1, word2)
14−import qualified Parse.Space as Space
15−import qualified Parse.Variable as Var
16−import qualified Reporting.Annotation as A
17−import qualified Reporting.Error.Syntax as E
18−
19−
20−
21−-- TYPE TERMS
22−
23−
24−term :: Parser E.Type Src.Type
25−term =
26− do start <- getPosition
27− oneOf E.TStart
28− [
29− -- types with no arguments (Int, Float, etc.)
30− do upper <- Var.foreignUpper E.TStart
31− end <- getPosition
32− let region = A.Region start end
33− return $ A.At region $
34− case upper of
35− Var.Unqualified name ->
36− Src.TType region name []
37−
38− Var.Qualified home name ->
39− Src.TTypeQual region home name []
40− ,
41− -- type variables
42− do var <- Var.lower E.TStart
43− addEnd start (Src.TVar var)
44− ,
45− -- tuples
46− inContext E.TTuple (word1 0x28 {-(-} E.TStart) $
47− oneOf E.TTupleOpen
48− [ do word1 0x29 {-)-} E.TTupleOpen
49− addEnd start Src.TUnit
50− , do Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentType1
51− (tipe, end) <- specialize E.TTupleType expression
52− Space.checkIndent end E.TTupleIndentEnd
53− chompTupleEnd start tipe []
54− ]
55− ,
56− -- records
57− inContext E.TRecord (word1 0x7B {- { -} E.TStart) $
58− do Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentOpen
59− oneOf E.TRecordOpen
60− [ do word1 0x7D {-}-} E.TRecordEnd
61− addEnd start (Src.TRecord [] Nothing)
62− , do name <- addLocation (Var.lower E.TRecordField)
63− Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentColon
64− oneOf E.TRecordColon
65− [ do word1 0x7C {-|-} E.TRecordColon
66− Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentField
67− field <- chompField
68− fields <- chompRecordEnd [field]
69− addEnd start (Src.TRecord fields (Just name))
70− , do word1 0x3A {-:-} E.TRecordColon
71− Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentType
72− (tipe, end) <- specialize E.TRecordType expression
73− Space.checkIndent end E.TRecordIndentEnd
74− fields <- chompRecordEnd [(name, tipe)]
75− addEnd start (Src.TRecord fields Nothing)
76− ]
77− ]
78− ]
79−
80−
81−
82−-- TYPE EXPRESSIONS
83−
84−
85−expression :: Space.Parser E.Type Src.Type
86−expression =
87− do start <- getPosition
88− term1@(tipe1, end1) <-
89− oneOf E.TStart
90− [ app start
91− , do eterm <- term
92− end <- getPosition
93− Space.chomp E.TSpace
94− return (eterm, end)
95− ]
96− oneOfWithFallback
97− [ do Space.checkIndent end1 E.TIndentStart -- should never trigger
98− word2 0x2D 0x3E {-->-} E.TStart -- could just be another type instead
99− Space.chompAndCheckIndent E.TSpace E.TIndentStart
100− (tipe2, end2) <- expression
101− let tipe = A.at start end2 (Src.TLambda tipe1 tipe2)
102− return ( tipe, end2 )
103− ]
104− term1
105−
106−
107−
108−-- TYPE CONSTRUCTORS
109−
110−
111−app :: A.Position -> Space.Parser E.Type Src.Type
112−app start =
113− do upper <- Var.foreignUpper E.TStart
114− upperEnd <- getPosition
115− Space.chomp E.TSpace
116− (args, end) <- chompArgs [] upperEnd
117−
118− let region = A.Region start upperEnd
119− let tipe =
120− case upper of
121− Var.Unqualified name ->
122− Src.TType region name args
123−
124− Var.Qualified home name ->
125− Src.TTypeQual region home name args
126−
127− return ( A.at start end tipe, end )
128−
129−
130−chompArgs :: [Src.Type] -> A.Position -> Space.Parser E.Type [Src.Type]
131−chompArgs args end =
132− oneOfWithFallback
133− [ do Space.checkIndent end E.TIndentStart
134− arg <- term
135− newEnd <- getPosition
136− Space.chomp E.TSpace
137− chompArgs (arg:args) newEnd
138− ]
139− (reverse args, end)
140−
141−
142−
143−-- TUPLES
144−
145−
146−chompTupleEnd :: A.Position -> Src.Type -> [Src.Type] -> Parser E.TTuple Src.Type
147−chompTupleEnd start firstType revTypes =
148− oneOf E.TTupleEnd
149− [ do word1 0x2C {-,-} E.TTupleEnd
150− Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentTypeN
151− (tipe, end) <- specialize E.TTupleType expression
152− Space.checkIndent end E.TTupleIndentEnd
153− chompTupleEnd start firstType (tipe : revTypes)
154− , do word1 0x29 {-)-} E.TTupleEnd
155− case reverse revTypes of
156− [] ->
157− return firstType
158−
159− secondType : otherTypes ->
160− addEnd start (Src.TTuple firstType secondType otherTypes)
161− ]
162−
163−
164−
165−-- RECORD
166−
167−
168−type Field = ( A.Located Name.Name, Src.Type )
169−
170−
171−chompRecordEnd :: [Field] -> Parser E.TRecord [Field]
172−chompRecordEnd fields =
173− oneOf E.TRecordEnd
174− [ do word1 0x2C {-,-} E.TRecordEnd
175− Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentField
176− field <- chompField
177− chompRecordEnd (field : fields)
178− , do word1 0x7D {-}-} E.TRecordEnd
179− return (reverse fields)
180− ]
181−
182−
183−chompField :: Parser E.TRecord Field
184−chompField =
185− do name <- addLocation (Var.lower E.TRecordField)
186− Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentColon
187− word1 0x3A {-:-} E.TRecordColon
188− Space.chompAndCheckIndent E.TRecordSpace E.TRecordIndentType
189− (tipe, end) <- specialize E.TRecordType expression
190− Space.checkIndent end E.TRecordIndentEnd
191− return (name, tipe)
192−
193−
194−
195−-- VARIANT
196−
197−
198−variant :: Space.Parser E.CustomType (A.Located Name.Name, [Src.Type])
199−variant =
200− do name@(A.At (A.Region _ nameEnd) _) <- addLocation (Var.upper E.CT_Variant)
201− Space.chomp E.CT_Space
202− (args, end) <- specialize E.CT_VariantArg (chompArgs [] nameEnd)
203− return ( (name, args), end )
compiler/src/Parse/Variable.hsdeleted−387
@@ -1,387 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, MagicHash, OverloadedStrings, UnboxedTuples #-}
3−module Parse.Variable
4− ( lower
5− , upper
6− , moduleName
7− , Upper(..)
8− , foreignUpper
9− , foreignAlpha
10− , chompInnerChars
11− , getUpperWidth
12− , getInnerWidth
13− , getInnerWidthHelp
14− , reservedWords
15− )
16− where
17−
18−
19−import qualified Data.Char as Char
20−import qualified Data.Name as Name
21−import qualified Data.Set as Set
22−import Data.Word (Word8)
23−import Foreign.Ptr (Ptr, plusPtr)
24−import GHC.Exts (Char(C#), Int#, (+#), (-#), chr#, uncheckedIShiftL#, word2Int#)
25−import GHC.Word (Word8(W8#))
26−
27−import qualified AST.Source as Src
28−import Parse.Primitives (Parser, Row, Col, unsafeIndex)
29−import qualified Parse.Primitives as P
30−
31−
32−
33−-- LOCAL UPPER
34−
35−
36−upper :: (Row -> Col -> x) -> Parser x Name.Name
37−upper toError =
38− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
39− let (# newPos, newCol #) = chompUpper pos end col in
40− if pos == newPos then
41− eerr row col toError
42− else
43− let !name = Name.fromPtr pos newPos in
44− cok name (P.State src newPos end indent row newCol)
45−
46−
47−
48−-- LOCAL LOWER
49−
50−
51−lower :: (Row -> Col -> x) -> Parser x Name.Name
52−lower toError =
53− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
54− let (# newPos, newCol #) = chompLower pos end col in
55− if pos == newPos then
56− eerr row col toError
57− else
58− let !name = Name.fromPtr pos newPos in
59− if Set.member name reservedWords then
60− eerr row col toError
61− else
62− let
63− !newState =
64− P.State src newPos end indent row newCol
65− in
66− cok name newState
67−
68−
69−{-# NOINLINE reservedWords #-}
70−reservedWords :: Set.Set Name.Name -- PERF try using a trie instead
71−reservedWords =
72− Set.fromList
73− [ "if", "then", "else"
74− , "case", "of"
75− , "let", "in"
76− , "type"
77− , "module", "where"
78− , "import", "exposing"
79− , "as"
80− , "port"
81− ]
82−
83−
84−
85−-- MODULE NAME
86−
87−
88−moduleName :: (Row -> Col -> x) -> Parser x Name.Name
89−moduleName toError =
90− P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
91− let
92− (# pos1, col1 #) = chompUpper pos end col
93− in
94− if pos == pos1 then
95− eerr row col toError
96− else
97− let
98− (# status, newPos, newCol #) = moduleNameHelp pos1 end col1
99− in
100− case status of
101− Good ->
102− let
103− !name = Name.fromPtr pos newPos
104− !newState = P.State src newPos end indent row newCol
105− in
106− cok name newState
107−
108− Bad ->
109− cerr row newCol toError
110−
111−
112−data ModuleNameStatus
113− = Good
114− | Bad
115−
116−
117−moduleNameHelp :: Ptr Word8 -> Ptr Word8 -> Col -> (# ModuleNameStatus, Ptr Word8, Col #)
118−moduleNameHelp pos end col =
119− if isDot pos end then
120− let
121− !pos1 = plusPtr pos 1
122− (# newPos, newCol #) = chompUpper pos1 end (col + 1)
123− in
124− if pos1 == newPos then
125− (# Bad, newPos, newCol #)
126− else
127− moduleNameHelp newPos end newCol
128−
129− else
130− (# Good, pos, col #)
131−
132−
133−
134−-- FOREIGN UPPER
135−
136−
137−data Upper
138− = Unqualified Name.Name
139− | Qualified Name.Name Name.Name
140−
141−
142−foreignUpper :: (Row -> Col -> x) -> Parser x Upper
143−foreignUpper toError =
144− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
145− let (# upperStart, upperEnd, newCol #) = foreignUpperHelp pos end col in
146− if upperStart == upperEnd then
147− eerr row newCol toError
148− else
149− let
150− !newState = P.State src upperEnd end indent row newCol
151− !name = Name.fromPtr upperStart upperEnd
152− !upperName =
153− if upperStart == pos then
154− Unqualified name
155− else
156− let !home = Name.fromPtr pos (plusPtr upperStart (-1)) in
157− Qualified home name
158− in
159− cok upperName newState
160−
161−
162−foreignUpperHelp :: Ptr Word8 -> Ptr Word8 -> Col -> (# Ptr Word8, Ptr Word8, Col #)
163−foreignUpperHelp pos end col =
164− let
165− (# newPos, newCol #) = chompUpper pos end col
166− in
167− if pos == newPos then
168− (# pos, pos, col #)
169−
170− else if isDot newPos end then
171− foreignUpperHelp (plusPtr newPos 1) end (newCol + 1)
172−
173− else
174− (# pos, newPos, newCol #)
175−
176−
177−
178−-- FOREIGN ALPHA
179−
180−
181−foreignAlpha :: (Row -> Col -> x) -> Parser x Src.Expr_
182−foreignAlpha toError =
183− P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
184− let (# alphaStart, alphaEnd, newCol, varType #) = foreignAlphaHelp pos end col in
185− if alphaStart == alphaEnd then
186− eerr row newCol toError
187− else
188− let
189− !newState = P.State src alphaEnd end indent row newCol
190− !name = Name.fromPtr alphaStart alphaEnd
191− in
192− if alphaStart == pos then
193− if Set.member name reservedWords then
194− eerr row col toError
195− else
196− cok (Src.Var varType name) newState
197− else
198− let !home = Name.fromPtr pos (plusPtr alphaStart (-1)) in
199− cok (Src.VarQual varType home name) newState
200−
201−
202−foreignAlphaHelp :: Ptr Word8 -> Ptr Word8 -> Col -> (# Ptr Word8, Ptr Word8, Col, Src.VarType #)
203−foreignAlphaHelp pos end col =
204− let
205− (# lowerPos, lowerCol #) = chompLower pos end col
206− in
207− if pos < lowerPos then
208− (# pos, lowerPos, lowerCol, Src.LowVar #)
209−
210− else
211− let
212− (# upperPos, upperCol #) = chompUpper pos end col
213− in
214− if pos == upperPos then
215− (# pos, pos, col, Src.CapVar #)
216−
217− else if isDot upperPos end then
218− foreignAlphaHelp (plusPtr upperPos 1) end (upperCol + 1)
219−
220− else
221− (# pos, upperPos, upperCol, Src.CapVar #)
222−
223−
224−
225−---- CHAR CHOMPERS ----
226−
227−
228−
229−-- DOTS
230−
231−
232−{-# INLINE isDot #-}
233−isDot :: Ptr Word8 -> Ptr Word8 -> Bool
234−isDot pos end =
235− pos < end && unsafeIndex pos == 0x2e {- . -}
236−
237−
238−
239−-- UPPER CHARS
240−
241−
242−chompUpper :: Ptr Word8 -> Ptr Word8 -> Col -> (# Ptr Word8, Col #)
243−chompUpper pos end col =
244− let !width = getUpperWidth pos end in
245− if width == 0 then
246− (# pos, col #)
247− else
248− chompInnerChars (plusPtr pos width) end (col + 1)
249−
250−
251−{-# INLINE getUpperWidth #-}
252−getUpperWidth :: Ptr Word8 -> Ptr Word8 -> Int
253−getUpperWidth pos end =
254− if pos < end then
255− getUpperWidthHelp pos end (unsafeIndex pos)
256− else
257− 0
258−
259−
260−{-# INLINE getUpperWidthHelp #-}
261−getUpperWidthHelp :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int
262−getUpperWidthHelp pos _ word
263− | 0x41 {- A -} <= word && word <= 0x5A {- Z -} = 1
264− | word < 0xc0 = 0
265− | word < 0xe0 = if Char.isUpper (chr2 pos word) then 2 else 0
266− | word < 0xf0 = if Char.isUpper (chr3 pos word) then 3 else 0
267− | word < 0xf8 = if Char.isUpper (chr4 pos word) then 4 else 0
268− | True = 0
269−
270−
271−
272−-- LOWER CHARS
273−
274−
275−chompLower :: Ptr Word8 -> Ptr Word8 -> Col -> (# Ptr Word8, Col #)
276−chompLower pos end col =
277− let !width = getLowerWidth pos end in
278− if width == 0 then
279− (# pos, col #)
280− else
281− chompInnerChars (plusPtr pos width) end (col + 1)
282−
283−
284−{-# INLINE getLowerWidth #-}
285−getLowerWidth :: Ptr Word8 -> Ptr Word8 -> Int
286−getLowerWidth pos end =
287− if pos < end then
288− getLowerWidthHelp pos end (unsafeIndex pos)
289− else
290− 0
291−
292−
293−{-# INLINE getLowerWidthHelp #-}
294−getLowerWidthHelp :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int
295−getLowerWidthHelp pos _ word
296− | 0x61 {- a -} <= word && word <= 0x7A {- z -} = 1
297− | word < 0xc0 = 0
298− | word < 0xe0 = if Char.isLower (chr2 pos word) then 2 else 0
299− | word < 0xf0 = if Char.isLower (chr3 pos word) then 3 else 0
300− | word < 0xf8 = if Char.isLower (chr4 pos word) then 4 else 0
301− | True = 0
302−
303−
304−
305−-- INNER CHARS
306−
307−
308−chompInnerChars :: Ptr Word8 -> Ptr Word8 -> Col -> (# Ptr Word8, Col #)
309−chompInnerChars !pos end !col =
310− let !width = getInnerWidth pos end in
311− if width == 0 then
312− (# pos, col #)
313− else
314− chompInnerChars (plusPtr pos width) end (col + 1)
315−
316−
317−getInnerWidth :: Ptr Word8 -> Ptr Word8 -> Int
318−getInnerWidth pos end =
319− if pos < end then
320− getInnerWidthHelp pos end (unsafeIndex pos)
321− else
322− 0
323−
324−
325−{-# INLINE getInnerWidthHelp #-}
326−getInnerWidthHelp :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int
327−getInnerWidthHelp pos _ word
328− | 0x61 {- a -} <= word && word <= 0x7A {- z -} = 1
329− | 0x41 {- A -} <= word && word <= 0x5A {- Z -} = 1
330− | 0x30 {- 0 -} <= word && word <= 0x39 {- 9 -} = 1
331− | word == 0x5F {- _ -} = 1
332− | word < 0xc0 = 0
333− | word < 0xe0 = if Char.isAlpha (chr2 pos word) then 2 else 0
334− | word < 0xf0 = if Char.isAlpha (chr3 pos word) then 3 else 0
335− | word < 0xf8 = if Char.isAlpha (chr4 pos word) then 4 else 0
336− | True = 0
337−
338−
339−
340−-- EXTRACT CHARACTERS
341−
342−
343−{-# INLINE chr2 #-}
344−chr2 :: Ptr Word8 -> Word8 -> Char
345−chr2 pos firstWord =
346− let
347− !i1# = unpack firstWord
348− !i2# = unpack (unsafeIndex (plusPtr pos 1))
349− !c1# = uncheckedIShiftL# (i1# -# 0xC0#) 6#
350− !c2# = i2# -# 0x80#
351− in
352− C# (chr# (c1# +# c2#))
353−
354−
355−{-# INLINE chr3 #-}
356−chr3 :: Ptr Word8 -> Word8 -> Char
357−chr3 pos firstWord =
358− let
359− !i1# = unpack firstWord
360− !i2# = unpack (unsafeIndex (plusPtr pos 1))
361− !i3# = unpack (unsafeIndex (plusPtr pos 2))
362− !c1# = uncheckedIShiftL# (i1# -# 0xE0#) 12#
363− !c2# = uncheckedIShiftL# (i2# -# 0x80#) 6#
364− !c3# = i3# -# 0x80#
365− in
366− C# (chr# (c1# +# c2# +# c3#))
367−
368−
369−{-# INLINE chr4 #-}
370−chr4 :: Ptr Word8 -> Word8 -> Char
371−chr4 pos firstWord =
372− let
373− !i1# = unpack firstWord
374− !i2# = unpack (unsafeIndex (plusPtr pos 1))
375− !i3# = unpack (unsafeIndex (plusPtr pos 2))
376− !i4# = unpack (unsafeIndex (plusPtr pos 3))
377− !c1# = uncheckedIShiftL# (i1# -# 0xF0#) 18#
378− !c2# = uncheckedIShiftL# (i2# -# 0x80#) 12#
379− !c3# = uncheckedIShiftL# (i3# -# 0x80#) 6#
380− !c4# = i4# -# 0x80#
381− in
382− C# (chr# (c1# +# c2# +# c3# +# c4#))
383−
384−
385−unpack :: Word8 -> Int#
386−unpack (W8# word#) =
387− word2Int# word#
compiler/src/Reporting/Annotation.hsdeleted−103
@@ -1,103 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Reporting.Annotation
3− ( Located(..)
4− , Position(..)
5− , Region(..)
6− , traverse
7− , toValue
8− , merge
9− , at
10− , toRegion
11− , mergeRegions
12− , zero
13− , one
14− )
15− where
16−
17−
18−import Prelude hiding (traverse)
19−import Control.Monad (liftM2)
20−import Data.Binary (Binary, get, put)
21−import Data.Word (Word16)
22−
23−
24−
25−-- LOCATED
26−
27−
28−data Located a =
29− At Region a -- PERF see if unpacking region is helpful
30−
31−
32−instance Functor Located where
33− fmap f (At region a) =
34− At region (f a)
35−
36−
37−traverse :: (Functor f) => (a -> f b) -> Located a -> f (Located b)
38−traverse func (At region value) =
39− At region <$> func value
40−
41−
42−toValue :: Located a -> a
43−toValue (At _ value) =
44− value
45−
46−
47−merge :: Located a -> Located b -> value -> Located value
48−merge (At r1 _) (At r2 _) value =
49− At (mergeRegions r1 r2) value
50−
51−
52−
53−-- POSITION
54−
55−
56−data Position =
57− Position
58− {-# UNPACK #-} !Word16
59− {-# UNPACK #-} !Word16
60− deriving (Eq)
61−
62−
63−at :: Position -> Position -> a -> Located a
64−at start end a =
65− At (Region start end) a
66−
67−
68−
69−-- REGION
70−
71−
72−data Region = Region Position Position
73− deriving (Eq)
74−
75−
76−toRegion :: Located a -> Region
77−toRegion (At region _) =
78− region
79−
80−
81−mergeRegions :: Region -> Region -> Region
82−mergeRegions (Region start _) (Region _ end) =
83− Region start end
84−
85−
86−zero :: Region
87−zero =
88− Region (Position 0 0) (Position 0 0)
89−
90−
91−one :: Region
92−one =
93− Region (Position 1 1) (Position 1 1)
94−
95−
96−instance Binary Region where
97− put (Region a b) = put a >> put b
98− get = liftM2 Region get get
99−
100−
101−instance Binary Position where
102− put (Position a b) = put a >> put b
103− get = liftM2 Position get get
compiler/src/Reporting/Doc.hsdeleted−431
@@ -1,431 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Doc
4− ( P.Doc
5− , (P.<+>), (<>)
6− , P.align, P.cat, P.empty, P.fill, P.fillSep, P.hang
7− , P.hcat, P.hsep, P.indent, P.sep, P.vcat
8− , P.red, P.cyan, P.magenta, P.green, P.blue, P.black, P.yellow
9− , P.dullred, P.dullcyan, P.dullyellow
10− --
11− , fromChars
12− , fromName
13− , fromVersion
14− , fromPackage
15− , fromInt
16− --
17− , toAnsi
18− , toString
19− , toLine
20− --
21− , encode
22− --
23− , stack
24− , reflow
25− , commaSep
26− --
27− , toSimpleNote
28− , toFancyNote
29− , toSimpleHint
30− , toFancyHint
31− --
32− , link
33− , fancyLink
34− , reflowLink
35− , makeLink
36− , makeNakedLink
37− --
38− , args
39− , moreArgs
40− , ordinal
41− , intToOrdinal
42− , cycle
43− )
44− where
45−
46−
47−import Prelude hiding (cycle)
48−import qualified Data.List as List
49−import Data.Monoid ((<>))
50−import qualified Data.Name as Name
51−import qualified System.Console.ANSI.Types as Ansi
52−import qualified System.Info as Info
53−import System.IO (Handle)
54−import qualified Text.PrettyPrint.ANSI.Leijen as P
55−
56−import qualified Data.Index as Index
57−import qualified Elm.Package as Pkg
58−import qualified Elm.Version as V
59−import Json.Encode ((==>))
60−import qualified Json.Encode as E
61−import qualified Json.String as Json
62−
63−
64−
65−-- FROM
66−
67−
68−fromChars :: String -> P.Doc
69−fromChars =
70− P.text
71−
72−
73−fromName :: Name.Name -> P.Doc
74−fromName name =
75− P.text (Name.toChars name)
76−
77−
78−fromVersion :: V.Version -> P.Doc
79−fromVersion vsn =
80− P.text (V.toChars vsn)
81−
82−
83−fromPackage :: Pkg.Name -> P.Doc
84−fromPackage pkg =
85− P.text (Pkg.toChars pkg)
86−
87−
88−fromInt :: Int -> P.Doc
89−fromInt n =
90− P.text (show n)
91−
92−
93−
94−-- TO STRING
95−
96−
97−toAnsi :: Handle -> P.Doc -> IO ()
98−toAnsi handle doc =
99− P.displayIO handle (P.renderPretty 1 80 doc)
100−
101−
102−toString :: P.Doc -> String
103−toString doc =
104− P.displayS (P.renderPretty 1 80 (P.plain doc)) ""
105−
106−
107−toLine :: P.Doc -> String
108−toLine doc =
109− P.displayS (P.renderPretty 1 (div maxBound 2) (P.plain doc)) ""
110−
111−
112−
113−-- FORMATTING
114−
115−
116−stack :: [P.Doc] -> P.Doc
117−stack docs =
118− P.vcat (List.intersperse "" docs)
119−
120−
121−reflow :: String -> P.Doc
122−reflow paragraph =
123− P.fillSep (map P.text (words paragraph))
124−
125−
126−commaSep :: P.Doc -> (P.Doc -> P.Doc) -> [P.Doc] -> [P.Doc]
127−commaSep conjunction addStyle names =
128− case names of
129− [name] ->
130− [ addStyle name ]
131−
132− [name1,name2] ->
133− [ addStyle name1, conjunction, addStyle name2 ]
134−
135− _ ->
136− map (\name -> addStyle name <> ",") (init names)
137− ++
138− [ conjunction
139− , addStyle (last names)
140− ]
141−
142−
143−
144−-- NOTES
145−
146−
147−toSimpleNote :: String -> P.Doc
148−toSimpleNote message =
149− toFancyNote (map P.text (words message))
150−
151−
152−toFancyNote :: [P.Doc] -> P.Doc
153−toFancyNote chunks =
154− P.fillSep (P.underline "Note" <> ":" : chunks)
155−
156−
157−
158−-- HINTS
159−
160−
161−toSimpleHint :: String -> P.Doc
162−toSimpleHint message =
163− toFancyHint (map P.text (words message))
164−
165−
166−toFancyHint :: [P.Doc] -> P.Doc
167−toFancyHint chunks =
168− P.fillSep (P.underline "Hint" <> ":" : chunks)
169−
170−
171−
172−-- LINKS
173−
174−
175−link :: String -> String -> String -> String -> P.Doc
176−link word before fileName after =
177− P.fillSep $
178− (P.underline (P.text word) <> ":")
179− : map P.text (words before)
180− ++ P.text (makeLink fileName)
181− : map P.text (words after)
182−
183−
184−fancyLink :: String -> [P.Doc] -> String -> [P.Doc] -> P.Doc
185−fancyLink word before fileName after =
186− P.fillSep $
187− (P.underline (P.text word) <> ":") : before ++ P.text (makeLink fileName) : after
188−
189−
190−makeLink :: [Char] -> [Char]
191−makeLink fileName =
192− "<https://elm-lang.org/" <> V.toChars V.compiler <> "/" <> fileName <> ">"
193−
194−
195−makeNakedLink :: [Char] -> [Char]
196−makeNakedLink fileName =
197− "https://elm-lang.org/" <> V.toChars V.compiler <> "/" <> fileName
198−
199−
200−reflowLink :: [Char] -> [Char] -> [Char] -> P.Doc
201−reflowLink before fileName after =
202− P.fillSep $
203− map P.text (words before)
204− ++ P.text (makeLink fileName)
205− : map P.text (words after)
206−
207−
208−
209−-- HELPERS
210−
211−
212−args :: Int -> String
213−args n =
214− show n <> if n == 1 then " argument" else " arguments"
215−
216−
217−moreArgs :: Int -> String
218−moreArgs n =
219− show n <> " more" <> if n == 1 then " argument" else " arguments"
220−
221−
222−ordinal :: Index.ZeroBased -> String
223−ordinal index =
224− intToOrdinal (Index.toHuman index)
225−
226−
227−intToOrdinal :: Int -> String
228−intToOrdinal number =
229− let
230− remainder10 =
231− number `mod` 10
232−
233− remainder100 =
234− number `mod` 100
235−
236− ending
237− | remainder100 `elem` [11..13] = "th"
238− | remainder10 == 1 = "st"
239− | remainder10 == 2 = "nd"
240− | remainder10 == 3 = "rd"
241− | otherwise = "th"
242− in
243− show number <> ending
244−
245−
246−
247−cycle :: Int -> Name.Name -> [Name.Name] -> P.Doc
248−cycle indent name names =
249− let
250− toLn n = cycleLn <> P.dullyellow (fromName n)
251− in
252− P.indent indent $ P.vcat $
253− cycleTop : List.intersperse cycleMid (toLn name : map toLn names) ++ [ cycleEnd ]
254−
255−
256−cycleTop, cycleLn, cycleMid, cycleEnd :: P.Doc
257−cycleTop = if isWindows then "+-----+" else "┌─────┐"
258−cycleLn = if isWindows then "| " else "│ "
259−cycleMid = if isWindows then "| |" else "│ ↓"
260−cycleEnd = if isWindows then "+-<---+" else "└─────┘"
261−
262−
263−isWindows :: Bool
264−isWindows =
265− Info.os == "mingw32"
266−
267−
268−
269−-- JSON
270−
271−
272−encode :: P.Doc -> E.Value
273−encode doc =
274− E.array (toJsonHelp noStyle [] (P.renderPretty 1 80 doc))
275−
276−
277−data Style =
278− Style
279− { _bold :: Bool
280− , _underline :: Bool
281− , _color :: Maybe Color
282− }
283−
284−
285−noStyle :: Style
286−noStyle =
287− Style False False Nothing
288−
289−
290−data Color
291− = Red
292− | RED
293− | Magenta
294− | MAGENTA
295− | Yellow
296− | YELLOW
297− | Green
298− | GREEN
299− | Cyan
300− | CYAN
301− | Blue
302− | BLUE
303− | Black
304− | BLACK
305− | White
306− | WHITE
307−
308−
309−toJsonHelp :: Style -> [String] -> P.SimpleDoc -> [E.Value]
310−toJsonHelp style revChunks simpleDoc =
311− case simpleDoc of
312− P.SFail ->
313− error $
314− "according to the main implementation, @SFail@ can not\
315− \ appear uncaught in a rendered @SimpleDoc@"
316−
317− P.SEmpty ->
318− [ encodeChunks style revChunks ]
319−
320− P.SChar char rest ->
321− toJsonHelp style ([char] : revChunks) rest
322−
323− P.SText _ string rest ->
324− toJsonHelp style (string : revChunks) rest
325−
326− P.SLine indent rest ->
327− toJsonHelp style (replicate indent ' ' : "\n" : revChunks) rest
328−
329− P.SSGR sgrs rest ->
330− encodeChunks style revChunks : toJsonHelp (sgrToStyle sgrs style) [] rest
331−
332−
333−sgrToStyle :: [Ansi.SGR] -> Style -> Style
334−sgrToStyle sgrs style@(Style bold underline color) =
335− case sgrs of
336− [] ->
337− style
338−
339− sgr : rest ->
340− sgrToStyle rest $
341− case sgr of
342− Ansi.Reset -> noStyle
343− Ansi.SetConsoleIntensity i -> Style (isBold i) underline color
344− Ansi.SetItalicized _ -> style
345− Ansi.SetUnderlining u -> Style bold (isUnderline u) color
346− Ansi.SetBlinkSpeed _ -> style
347− Ansi.SetVisible _ -> style
348− Ansi.SetSwapForegroundBackground _ -> style
349− Ansi.SetColor l i c -> Style bold underline (toColor l i c)
350− Ansi.SetRGBColor _ _ -> style
351−
352−
353−isBold :: Ansi.ConsoleIntensity -> Bool
354−isBold intensity =
355− case intensity of
356− Ansi.BoldIntensity -> True
357− Ansi.FaintIntensity -> False
358− Ansi.NormalIntensity -> False
359−
360−
361−isUnderline :: Ansi.Underlining -> Bool
362−isUnderline underlining =
363− case underlining of
364− Ansi.SingleUnderline -> True
365− Ansi.DoubleUnderline -> False
366− Ansi.NoUnderline -> False
367−
368−
369−toColor :: Ansi.ConsoleLayer -> Ansi.ColorIntensity -> Ansi.Color -> Maybe Color
370−toColor layer intensity color =
371− case layer of
372− Ansi.Background ->
373− Nothing
374−
375− Ansi.Foreground ->
376− let
377− pick dull vivid =
378− case intensity of
379− Ansi.Dull -> dull
380− Ansi.Vivid -> vivid
381− in
382− Just $
383− case color of
384− Ansi.Red -> pick Red RED
385− Ansi.Magenta -> pick Magenta MAGENTA
386− Ansi.Yellow -> pick Yellow YELLOW
387− Ansi.Green -> pick Green GREEN
388− Ansi.Cyan -> pick Cyan CYAN
389− Ansi.Blue -> pick Blue BLUE
390− Ansi.White -> pick White WHITE
391− Ansi.Black -> pick Black BLACK
392−
393−
394−encodeChunks :: Style -> [String] -> E.Value
395−encodeChunks (Style bold underline color) revChunks =
396− let
397− chars = concat (reverse revChunks)
398− in
399− case color of
400− Nothing | not bold && not underline ->
401− E.chars chars
402−
403− _ ->
404− E.object
405− [ "bold" ==> E.bool bold
406− , "underline" ==> E.bool underline
407− , "color" ==> maybe E.null encodeColor color
408− , "string" ==> E.chars chars
409− ]
410−
411−
412−encodeColor :: Color -> E.Value
413−encodeColor color =
414− E.string $ Json.fromChars $
415− case color of
416− Red -> "red"
417− RED -> "RED"
418− Magenta -> "magenta"
419− MAGENTA -> "MAGENTA"
420− Yellow -> "yellow"
421− YELLOW -> "YELLOW"
422− Green -> "green"
423− GREEN -> "GREEN"
424− Cyan -> "cyan"
425− CYAN -> "CYAN"
426− Blue -> "blue"
427− BLUE -> "BLUE"
428− Black -> "black"
429− BLACK -> "BLACK"
430− White -> "white"
431− WHITE -> "WHITE"
compiler/src/Reporting/Error.hsdeleted−210
@@ -1,210 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error
4− ( Module(..)
5− , Error(..)
6− , toDoc
7− , toJson
8− )
9− where
10−
11−
12−import qualified Data.ByteString as B
13−import qualified Data.NonEmptyList as NE
14−import qualified Data.OneOrMore as OneOrMore
15−import qualified System.FilePath as FP
16−
17−import qualified Elm.ModuleName as ModuleName
18−import qualified File
19−import qualified Json.Encode as E
20−import Json.Encode ((==>))
21−import qualified Reporting.Annotation as A
22−import qualified Reporting.Doc as D
23−import qualified Reporting.Error.Canonicalize as Canonicalize
24−import qualified Reporting.Error.Docs as Docs
25−import qualified Reporting.Error.Import as Import
26−import qualified Reporting.Error.Main as Main
27−import qualified Reporting.Error.Pattern as Pattern
28−import qualified Reporting.Error.Syntax as Syntax
29−import qualified Reporting.Error.Type as Type
30−import qualified Reporting.Render.Code as Code
31−import qualified Reporting.Render.Type.Localizer as L
32−import qualified Reporting.Report as Report
33−
34−
35−
36−-- MODULE
37−
38−
39−data Module =
40− Module
41− { _name :: ModuleName.Raw
42− , _absolutePath :: FilePath
43− , _modificationTime :: File.Time
44− , _source :: B.ByteString
45− , _error :: Error
46− }
47−
48−
49−
50−-- ERRORS
51−
52−
53−data Error
54− = BadSyntax Syntax.Error
55− | BadImports (NE.List Import.Error)
56− | BadNames (OneOrMore.OneOrMore Canonicalize.Error)
57− | BadTypes L.Localizer (NE.List Type.Error)
58− | BadMains L.Localizer (OneOrMore.OneOrMore Main.Error)
59− | BadPatterns (NE.List Pattern.Error)
60− | BadDocs Docs.Error
61−
62−
63−
64−-- TO REPORT
65−
66−
67−toReports :: Code.Source -> Error -> NE.List Report.Report
68−toReports source err =
69− case err of
70− BadSyntax syntaxError ->
71− NE.List (Syntax.toReport source syntaxError) []
72−
73− BadImports errs ->
74− fmap (Import.toReport source) errs
75−
76− BadNames errs ->
77− fmap (Canonicalize.toReport source) (OneOrMore.destruct NE.List errs)
78−
79− BadTypes localizer errs ->
80− fmap (Type.toReport source localizer) errs
81−
82− BadMains localizer errs ->
83− fmap (Main.toReport localizer source) (OneOrMore.destruct NE.List errs)
84−
85− BadPatterns errs ->
86− fmap (Pattern.toReport source) errs
87−
88− BadDocs docsErr ->
89− Docs.toReports source docsErr
90−
91−
92−
93−-- TO DOC
94−
95−
96−toDoc :: FilePath -> Module -> [Module] -> D.Doc
97−toDoc root err errs =
98− let
99− (NE.List m ms) = NE.sortBy _modificationTime (NE.List err errs)
100− in
101− D.vcat (toDocHelp root m ms)
102−
103−
104−toDocHelp :: FilePath -> Module -> [Module] -> [D.Doc]
105−toDocHelp root module1 modules =
106− case modules of
107− [] ->
108− [moduleToDoc root module1
109− ,""
110− ]
111−
112− module2 : otherModules ->
113− moduleToDoc root module1
114− : toSeparator module1 module2
115− : toDocHelp root module2 otherModules
116−
117−
118−toSeparator :: Module -> Module -> D.Doc
119−toSeparator beforeModule afterModule =
120− let
121− before = ModuleName.toChars (_name beforeModule) ++ " ↑ "
122− after = " ↓ " ++ ModuleName.toChars (_name afterModule)
123− in
124− D.dullred $ D.vcat $
125− [ D.indent (80 - length before) (D.fromChars before)
126− , "====o======================================================================o===="
127− , D.fromChars after
128− , ""
129− , ""
130− ]
131−
132−
133−
134−-- MODULE TO DOC
135−
136−
137−moduleToDoc :: FilePath -> Module -> D.Doc
138−moduleToDoc root (Module _ absolutePath _ source err) =
139− let
140− reports =
141− toReports (Code.toSource source) err
142−
143− relativePath =
144− FP.makeRelative root absolutePath
145− in
146− D.vcat $ map (reportToDoc relativePath) (NE.toList reports)
147−
148−
149−reportToDoc :: FilePath -> Report.Report -> D.Doc
150−reportToDoc relativePath (Report.Report title _ _ message) =
151− D.vcat
152− [ toMessageBar title relativePath
153− , ""
154− , message
155− , ""
156− ]
157−
158−
159−toMessageBar :: String -> FilePath -> D.Doc
160−toMessageBar title filePath =
161− let
162− usedSpace =
163− 4 + length title + 1 + length filePath
164− in
165− D.dullcyan $ D.fromChars $
166− "-- " ++ title
167− ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
168− ++ " " ++ filePath
169−
170−
171−
172−-- TO JSON
173−
174−
175−toJson :: Module -> E.Value
176−toJson (Module name path _ source err) =
177− let
178− reports =
179− toReports (Code.toSource source) err
180− in
181− E.object
182− [ "path" ==> E.chars path
183− , "name" ==> E.name name
184− , "problems" ==> E.array (map reportToJson (NE.toList reports))
185− ]
186−
187−
188−reportToJson :: Report.Report -> E.Value
189−reportToJson (Report.Report title region _sgstns message) =
190− E.object
191− [ "title" ==> E.chars title
192− , "region" ==> encodeRegion region
193− , "message" ==> D.encode message
194− ]
195−
196−
197−encodeRegion :: A.Region -> E.Value
198−encodeRegion (A.Region (A.Position sr sc) (A.Position er ec)) =
199− E.object
200− [ "start" ==>
201− E.object
202− [ "line" ==> E.int (fromIntegral sr)
203− , "column" ==> E.int (fromIntegral sc)
204− ]
205− , "end" ==>
206− E.object
207− [ "line" ==> E.int (fromIntegral er)
208− , "column" ==> E.int (fromIntegral ec)
209− ]
210− ]
compiler/src/Reporting/Error/Canonicalize.hsdeleted−1261

This diff is too big to show here.

compiler/src/Reporting/Error/Docs.hsdeleted−250

This diff is too big to show here.

compiler/src/Reporting/Error/Import.hsdeleted−162

This diff is too big to show here.

compiler/src/Reporting/Error/Json.hsdeleted−344

This diff is too big to show here.

compiler/src/Reporting/Error/Syntax.hsdeleted−5848

This diff is too big to show here.

compiler/src/Reporting/Error/Type.hsdeleted−1613

This diff is too big to show here.

compiler/src/Reporting/Render/Code.hsdeleted−288

This diff is too big to show here.

compiler/src/Reporting/Render/Type/Localizer.hsdeleted−120

This diff is too big to show here.

compiler/src/Reporting/Report.hsdeleted−22

This diff is too big to show here.

compiler/src/Reporting/Suggest.hsdeleted−52

This diff is too big to show here.

compiler/src/Type/Error.hsdeleted−589

This diff is too big to show here.

docs/elm.json/application.mddeleted−69

This diff is too big to show here.

docs/elm.json/package.mddeleted−93

This diff is too big to show here.

docs/upgrade-instructions/0.16.mddeleted−174

This diff is too big to show here.

docs/upgrade-instructions/0.17.mddeleted−275

This diff is too big to show here.

docs/upgrade-instructions/0.18.mddeleted−161

This diff is too big to show here.

docs/upgrade-instructions/0.19.0.mddeleted−164

This diff is too big to show here.

docs/upgrade-instructions/0.19.1.mddeleted−60

This diff is too big to show here.

elm-compiler.cabalnew file+215

This diff is too big to show here.

elm.cabaldeleted−238

This diff is too big to show here.

hints/bad-recursion.md+27−25

This diff is too big to show here.

hints/comparing-custom-types.mddeleted−98

This diff is too big to show here.

hints/comparing-records.mddeleted−85

This diff is too big to show here.

hints/effect-modules.mdnew file+10

This diff is too big to show here.

hints/implicit-casts.md+5−2

This diff is too big to show here.

hints/imports.md+6−7

This diff is too big to show here.

hints/infinite-type.md+94−20

This diff is too big to show here.

hints/init.mddeleted−55

This diff is too big to show here.

hints/missing-patterns.md+69−66

This diff is too big to show here.

hints/optimize.mddeleted−59

This diff is too big to show here.

hints/recursive-alias.md+2−3

This diff is too big to show here.

hints/repl.mddeleted−73

This diff is too big to show here.

hints/shadowing.md−1

This diff is too big to show here.

hints/tuples.mddeleted−19

This diff is too big to show here.

hints/type-annotations.md+8−2

This diff is too big to show here.

installers/README.mddeleted−32

This diff is too big to show here.

installers/linux/Dockerfiledeleted−39

This diff is too big to show here.

installers/linux/README.mddeleted−93

This diff is too big to show here.

installers/mac/Distribution.xmldeleted−33

This diff is too big to show here.

installers/mac/README.mddeleted−93

This diff is too big to show here.

installers/mac/Resources/en.lproj/conclusion.rtfdeleted−16

This diff is too big to show here.

installers/mac/Resources/en.lproj/welcome.rtfdeleted−12

This diff is too big to show here.

installers/mac/helper-scripts/elm-startup.shdeleted−3

This diff is too big to show here.

installers/mac/helper-scripts/uninstall.shdeleted−21

This diff is too big to show here.

installers/mac/make-installer.shdeleted−81

This diff is too big to show here.

installers/mac/postinstalldeleted−5

This diff is too big to show here.

installers/mac/preinstalldeleted−18

This diff is too big to show here.

installers/npm/.gitignoredeleted−1

This diff is too big to show here.

installers/npm/.npmignoredeleted−3

This diff is too big to show here.

installers/npm/PUBLISHING.mddeleted−59

This diff is too big to show here.

installers/npm/README.mddeleted−45

This diff is too big to show here.

installers/npm/bin/elmdeleted−54

This diff is too big to show here.

installers/npm/download.jsdeleted−114

This diff is too big to show here.

installers/npm/install.jsdeleted−4

This diff is too big to show here.

installers/npm/package.jsondeleted−42

This diff is too big to show here.

installers/npm/troubleshooting.mddeleted−76

This diff is too big to show here.

installers/win/CreateInternetShortcut.nshdeleted−5

This diff is too big to show here.

installers/win/Nsisfile.nsideleted−264

This diff is too big to show here.

installers/win/README.mddeleted−24

This diff is too big to show here.

installers/win/inst.datdeleted−6

This diff is too big to show here.

installers/win/logo.icodeleted

Binary file not shown.

installers/win/make_installer.cmddeleted−18

This diff is too big to show here.

installers/win/removefrompath.vbsdeleted−17

This diff is too big to show here.

installers/win/uninst.datdeleted−6

This diff is too big to show here.

installers/win/updatepath.vbsdeleted−14

This diff is too big to show here.

installers/win/welcome.bmpdeleted

Binary file not shown.

profiling/Main.hsnew file+77

This diff is too big to show here.

profiling/cabal.confignew file+2

This diff is too big to show here.

profiling/elm-prof.cabalnew file+18

This diff is too big to show here.

reactor/assets/favicon.icodeleted

Binary file not shown.

reactor/assets/source-code-pro.ttfdeleted

Binary file not shown.

reactor/assets/source-sans-pro.ttfdeleted

Binary file not shown.

reactor/assets/styles.cssdeleted−157

This diff is too big to show here.

reactor/check.pydeleted−48

This diff is too big to show here.

reactor/elm.jsondeleted−31

This diff is too big to show here.

reactor/src/Deps.elmdeleted−1210

This diff is too big to show here.

reactor/src/Errors.elmdeleted−207

This diff is too big to show here.

reactor/src/Index.elmdeleted−280

This diff is too big to show here.

reactor/src/Index/Icon.elmdeleted−111

This diff is too big to show here.

reactor/src/Index/Navigator.elmdeleted−63

This diff is too big to show here.

reactor/src/Index/Skeleton.elmdeleted−61

This diff is too big to show here.

reactor/src/NotFound.elmdeleted−29

This diff is too big to show here.

reactor/src/mock.txtdeleted−33

This diff is too big to show here.

roadmap.mddeleted−29

This diff is too big to show here.

compiler/src/AST/Canonical.hs → src/AST/Canonical.hsrenamed+72−99

This diff is too big to show here.

src/AST/Module/Name.hsnew file+198

This diff is too big to show here.

compiler/src/AST/Optimized.hs → src/AST/Optimized.hsrenamed+113−150

This diff is too big to show here.

src/AST/Source.hsnew file+193

This diff is too big to show here.

compiler/src/AST/Utils/Binop.hs → src/AST/Utils/Binop.hsrenamed+6−5

This diff is too big to show here.

src/AST/Utils/Shader.hsnew file+36

This diff is too big to show here.

compiler/src/AST/Utils/Type.hs → src/AST/Utils/Type.hsrenamed+7−16

This diff is too big to show here.

src/AST/Valid.hsnew file+129

This diff is too big to show here.

compiler/src/Canonicalize/Effects.hs → src/Canonicalize/Effects.hsrenamed+38−42

This diff is too big to show here.

compiler/src/Canonicalize/Environment.hs → src/Canonicalize/Environment.hsrenamed+42−72

This diff is too big to show here.

compiler/src/Canonicalize/Environment/Dups.hs → src/Canonicalize/Environment/Dups.hsrenamed+14−27

This diff is too big to show here.

src/Canonicalize/Environment/Foreign.hsnew file+287

This diff is too big to show here.

compiler/src/Canonicalize/Environment/Local.hs → src/Canonicalize/Environment/Local.hsrenamed+74−73

This diff is too big to show here.

compiler/src/Canonicalize/Expression.hs → src/Canonicalize/Expression.hsrenamed+77−78

This diff is too big to show here.

compiler/src/Canonicalize/Module.hs → src/Canonicalize/Module.hsrenamed+74−65

This diff is too big to show here.

compiler/src/Canonicalize/Pattern.hs → src/Canonicalize/Pattern.hsrenamed+12−16

This diff is too big to show here.

compiler/src/Canonicalize/Type.hs → src/Canonicalize/Type.hsrenamed+9−22

This diff is too big to show here.

src/Compile.hsnew file+124

This diff is too big to show here.

compiler/src/Data/Bag.hs → src/Data/Bag.hsrenamed+11

This diff is too big to show here.

compiler/src/Data/Index.hs → src/Data/Index.hsrenamed

The content is the same.

src/Data/OneOrMore.hsnew file+64

This diff is too big to show here.

src/Elm/Compiler.hsnew file+70

This diff is too big to show here.

src/Elm/Compiler/Imports.hsnew file+79

This diff is too big to show here.

src/Elm/Compiler/Module.hsnew file+96

This diff is too big to show here.

src/Elm/Compiler/Objects.hsnew file+110

This diff is too big to show here.

src/Elm/Compiler/Type.hsnew file+248

This diff is too big to show here.

compiler/src/Elm/Compiler/Type/Extract.hs → src/Elm/Compiler/Type/Extract.hsrenamed+28−79

This diff is too big to show here.

src/Elm/Compiler/Version.hsnew file+27

This diff is too big to show here.

src/Elm/Docs.hsnew file+540

This diff is too big to show here.

src/Elm/Header.hsnew file+73

This diff is too big to show here.

src/Elm/Interface.hsnew file+113

This diff is too big to show here.

src/Elm/Kernel.hsnew file+248

This diff is too big to show here.

src/Elm/Name.hsnew file+316

This diff is too big to show here.

src/Elm/Package.hsnew file+390

This diff is too big to show here.

src/Elm/Utils.hsnew file+13

This diff is too big to show here.

src/Generate/JavaScript.hsnew file+533

This diff is too big to show here.

src/Generate/JavaScript/Builder.hsnew file+540

This diff is too big to show here.

compiler/src/Generate/JavaScript/Expression.hs → src/Generate/JavaScript/Expression.hsrenamed+236−269

This diff is too big to show here.

compiler/src/Generate/JavaScript/Name.hs → src/Generate/JavaScript/Name.hsrenamed+112−46

This diff is too big to show here.

src/Json/Decode.hsnew file+306

This diff is too big to show here.

src/Json/Decode/Internals.hsnew file+367

This diff is too big to show here.

compiler/src/Json/Encode.hs → src/Json/Encode.hsrenamed+59−47

This diff is too big to show here.

compiler/src/Nitpick/PatternMatches.hs → src/Nitpick/PatternMatches.hsrenamed+32−44

This diff is too big to show here.

compiler/src/Optimize/Case.hs → src/Optimize/Case.hsrenamed+2−2

This diff is too big to show here.

compiler/src/Optimize/DecisionTree.hs → src/Optimize/DecisionTree.hsrenamed+20−42

This diff is too big to show here.

compiler/src/Optimize/Expression.hs → src/Optimize/Expression.hsrenamed+35−59

This diff is too big to show here.

compiler/src/Optimize/Module.hs → src/Optimize/Module.hsrenamed+107−97

This diff is too big to show here.

compiler/src/Optimize/Names.hs → src/Optimize/Names.hsrenamed+24−18

This diff is too big to show here.

compiler/src/Optimize/Port.hs → src/Optimize/Port.hsrenamed+45−49

This diff is too big to show here.

src/Parse/Declaration.hsnew file+197

This diff is too big to show here.

src/Parse/Expression.hsnew file+564

This diff is too big to show here.

src/Parse/Module.hsnew file+295

This diff is too big to show here.

src/Parse/Parse.hsnew file+65

This diff is too big to show here.

src/Parse/Pattern.hsnew file+273

This diff is too big to show here.

src/Parse/Primitives.hsnew file+228

This diff is too big to show here.

src/Parse/Primitives/Internals.hsnew file+251

This diff is too big to show here.

src/Parse/Primitives/Kernel.hsnew file+116

This diff is too big to show here.

src/Parse/Primitives/Keyword.hsnew file+235

This diff is too big to show here.

src/Parse/Primitives/Number.hsnew file+297

This diff is too big to show here.

src/Parse/Primitives/Shader.hsnew file+69

This diff is too big to show here.

src/Parse/Primitives/Symbol.hsnew file+259

This diff is too big to show here.

src/Parse/Primitives/Utf8.hsnew file+471

This diff is too big to show here.

src/Parse/Primitives/Variable.hsnew file+376

This diff is too big to show here.

src/Parse/Primitives/Whitespace.hsnew file+223

This diff is too big to show here.

src/Parse/Repl.hsnew file+101

This diff is too big to show here.

src/Parse/Shader.hsnew file+101

This diff is too big to show here.

src/Parse/Type.hsnew file+228

This diff is too big to show here.

src/Reporting/Annotation.hsnew file+60

This diff is too big to show here.

src/Reporting/Error.hsnew file+57

This diff is too big to show here.

src/Reporting/Error/Canonicalize.hsnew file+1171

This diff is too big to show here.

src/Reporting/Error/Docs.hsnew file+140

This diff is too big to show here.

compiler/src/Reporting/Error/Main.hs → src/Reporting/Error/Main.hsrenamed+29−31

This diff is too big to show here.

compiler/src/Reporting/Error/Pattern.hs → src/Reporting/Error/Pattern.hsrenamed+28−29

This diff is too big to show here.

src/Reporting/Error/Syntax.hsnew file+787

This diff is too big to show here.

src/Reporting/Error/Type.hsnew file+1696

This diff is too big to show here.

src/Reporting/Helpers.hsnew file+250

This diff is too big to show here.

src/Reporting/Region.hsnew file+79

This diff is too big to show here.

src/Reporting/Render/Code.hsnew file+153

This diff is too big to show here.

compiler/src/Reporting/Render/Type.hs → src/Reporting/Render/Type.hsrenamed+49−71

This diff is too big to show here.

src/Reporting/Report.hsnew file+83

This diff is too big to show here.

compiler/src/Reporting/Result.hs → src/Reporting/Result.hsrenamed+2−12

This diff is too big to show here.

compiler/src/Reporting/Warning.hs → src/Reporting/Warning.hsrenamed+27−28

This diff is too big to show here.

compiler/src/Type/Constrain/Expression.hs → src/Type/Constrain/Expression.hsrenamed+93−78

This diff is too big to show here.

compiler/src/Type/Constrain/Module.hs → src/Type/Constrain/Module.hsrenamed+31−24

This diff is too big to show here.

compiler/src/Type/Constrain/Pattern.hs → src/Type/Constrain/Pattern.hsrenamed+11−15

This diff is too big to show here.

src/Type/Error.hsnew file+617

This diff is too big to show here.

compiler/src/Type/Instantiate.hs → src/Type/Instantiate.hsrenamed+4−9

This diff is too big to show here.

compiler/src/Type/Occurs.hs → src/Type/Occurs.hsrenamed

The content is the same.

compiler/src/Type/Solve.hs → src/Type/Solve.hsrenamed+29−42

This diff is too big to show here.

compiler/src/Type/Type.hs → src/Type/Type.hsrenamed+85−77

This diff is too big to show here.

compiler/src/Type/Unify.hs → src/Type/Unify.hsrenamed+75−57

This diff is too big to show here.

compiler/src/Type/UnionFind.hs → src/Type/UnionFind.hsrenamed

The content is the same.

src/Validate.hsnew file+334

This diff is too big to show here.

terminal/impl/Terminal.hsdeleted−375

This diff is too big to show here.

terminal/impl/Terminal/Chomp.hsdeleted−514

This diff is too big to show here.

terminal/impl/Terminal/Error.hsdeleted−457

This diff is too big to show here.

terminal/impl/Terminal/Helpers.hsdeleted−148

This diff is too big to show here.

terminal/impl/Terminal/Internal.hsdeleted−93

This diff is too big to show here.

terminal/src/Bump.hsdeleted−169

This diff is too big to show here.

terminal/src/Develop.hsdeleted−256

This diff is too big to show here.

terminal/src/Develop/Generate/Help.hsdeleted−65

This diff is too big to show here.

terminal/src/Develop/Generate/Index.hsdeleted−213

This diff is too big to show here.

terminal/src/Develop/Socket.hsdeleted−43

This diff is too big to show here.

terminal/src/Develop/StaticFiles.hsdeleted−123

This diff is too big to show here.

terminal/src/Develop/StaticFiles/Build.hsdeleted−73

This diff is too big to show here.

terminal/src/Diff.hsdeleted−359

This diff is too big to show here.

terminal/src/Init.hsdeleted−104

This diff is too big to show here.

terminal/src/Install.hsdeleted−425

This diff is too big to show here.

terminal/src/Main.hsdeleted−338

This diff is too big to show here.

terminal/src/Make.hsdeleted−319

This diff is too big to show here.

terminal/src/Publish.hsdeleted−540

This diff is too big to show here.

terminal/src/Repl.hsdeleted−726

This diff is too big to show here.

tests/Test.hsnew file+14

This diff is too big to show here.

tests/Test/Compiler.hsnew file+247

This diff is too big to show here.

tests/Test/Property.hsnew file+68

This diff is too big to show here.

tests/Test/Property/Arbitrary.hsnew file+193

This diff is too big to show here.

tests/test-files/bad/BBTArgsnew file+1

This diff is too big to show here.

tests/test-files/bad/IncompletePatternMatch.elmnew file+17

This diff is too big to show here.

tests/test-files/bad/InfiniteType.elmnew file+2

This diff is too big to show here.

tests/test-files/bad/NonElementMain.elmnew file+2

This diff is too big to show here.

tests/test-files/bad/RepeatedArgument.elmnew file+4

This diff is too big to show here.

tests/test-files/bad/Strings/ExtraClose.elmnew file+4

This diff is too big to show here.

tests/test-files/good-expected-js/Cases/CharCase.elm.jsnew file+8

This diff is too big to show here.

tests/test-files/good-expected-js/Cases/ListZip.elm.jsnew file+21

This diff is too big to show here.

tests/test-files/good-expected-js/CodeGenBugs/CommentInterpretedAsInfix.elm.jsnew file+13

This diff is too big to show here.

tests/test-files/good-expected-js/CodeGenBugs/NestedPatternMatch.elm.jsnew file+4

This diff is too big to show here.

tests/test-files/good-expected-js/CodeGenBugs/Shadowing.elm.jsnew file+16

This diff is too big to show here.

tests/test-files/good-expected-js/CodeGenBugs/Shadowing2.elm.jsnew file+13

This diff is too big to show here.

tests/test-files/good-expected-js/CodeGenBugs/TailRecursion_ListAny.elm.jsnew file+20

This diff is too big to show here.

tests/test-files/good-expected-js/Crash/CrashCase.elm.jsnew file+14

This diff is too big to show here.

tests/test-files/good-expected-js/Crash/CrashIf.elm.jsnew file+8

This diff is too big to show here.

tests/test-files/good-expected-js/Declarations/NoDefinitions.elm.jsnew file

No changes to the content.

tests/test-files/good-expected-js/Lists/EmptyList.elm.jsnew file+1

This diff is too big to show here.

tests/test-files/good-expected-js/Lists/NonEmptyList.elm.jsnew file+13

This diff is too big to show here.

tests/test-files/good-expected-js/Literals/Multiline.elm.jsnew file+1

This diff is too big to show here.

tests/test-files/good-expected-js/Literals/Negatives.elm.jsnew file+22

This diff is too big to show here.

tests/test-files/good-expected-js/Literals/Numbers.elm.jsnew file+14

This diff is too big to show here.

tests/test-files/good-expected-js/Literals/QuotesAndComments.elm.jsnew file+3

This diff is too big to show here.

tests/test-files/good-expected-js/Records/Access.elm.jsnew file+19

This diff is too big to show here.

tests/test-files/good-expected-js/Records/AliasSubstitution.elm.jsnew file+3

This diff is too big to show here.

tests/test-files/good-expected-js/Records/NonHomogeneousRecords.elm.jsnew file+9

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/Apply.elm.jsnew file+6

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/ApplyAnnotated.elm.jsnew file+6

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/Id.elm.jsnew file+6

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/IdAnnotated.elm.jsnew file+6

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/SpecificAnnotationInt.elm.jsnew file+3

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/SpecificAnnotationNumber.elm.jsnew file+3

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/TrickyId.elm.jsnew file+4

This diff is too big to show here.

tests/test-files/good-expected-js/Soundness/TrickyIdAnnotated.elm.jsnew file+4

This diff is too big to show here.

tests/test-files/good/Cases/CharCase.elmnew file+8

This diff is too big to show here.

tests/test-files/good/Cases/ListZip.elmnew file+17

This diff is too big to show here.

tests/test-files/good/CodeGenBugs/CommentInterpretedAsInfix.elmnew file+12

This diff is too big to show here.

tests/test-files/good/CodeGenBugs/NestedPatternMatch.elmnew file+5

This diff is too big to show here.

tests/test-files/good/CodeGenBugs/Shadowing.elmnew file+22

This diff is too big to show here.

tests/test-files/good/CodeGenBugs/Shadowing2.elmnew file+25

This diff is too big to show here.

tests/test-files/good/CodeGenBugs/TailRecursion_ListAny.elmnew file+12

This diff is too big to show here.

tests/test-files/good/Crash/CrashCase.elmnew file+9

This diff is too big to show here.

tests/test-files/good/Crash/CrashIf.elmnew file+8

This diff is too big to show here.

tests/test-files/good/Declarations/NoDefinitions.elmnew file+3

This diff is too big to show here.

tests/test-files/good/Lists/EmptyList.elmnew file+2

This diff is too big to show here.

tests/test-files/good/Lists/NonEmptyList.elmnew file+2

This diff is too big to show here.

tests/test-files/good/Literals/Multiline.elmnew file+4

This diff is too big to show here.

tests/test-files/good/Literals/Negatives.elmnew file+17

This diff is too big to show here.

tests/test-files/good/Literals/Numbers.elmnew file+18

This diff is too big to show here.

tests/test-files/good/Literals/QuotesAndComments.elmnew file+10

This diff is too big to show here.

tests/test-files/good/Records/Access.elmnew file+22

This diff is too big to show here.

tests/test-files/good/Records/AliasSubstitution.elmnew file+13

This diff is too big to show here.

tests/test-files/good/Records/NonHomogeneousRecords.elmnew file+14

This diff is too big to show here.

tests/test-files/good/Soundness/Apply.elmnew file+3

This diff is too big to show here.

tests/test-files/good/Soundness/ApplyAnnotated.elmnew file+4

This diff is too big to show here.

tests/test-files/good/Soundness/Id.elmnew file+3

This diff is too big to show here.

tests/test-files/good/Soundness/IdAnnotated.elmnew file+4

This diff is too big to show here.

tests/test-files/good/Soundness/SpecificAnnotationInt.elmnew file+4

This diff is too big to show here.

tests/test-files/good/Soundness/SpecificAnnotationNumber.elmnew file+4

This diff is too big to show here.

tests/test-files/good/Soundness/TrickyId.elmnew file+2

This diff is too big to show here.

tests/test-files/good/Soundness/TrickyIdAnnotated.elmnew file+3

This diff is too big to show here.

worker/elm.cabaldeleted−210

This diff is too big to show here.

worker/elm.jsondeleted−26

This diff is too big to show here.

worker/nginx.confdeleted−22

This diff is too big to show here.

worker/outlines/compile/elm.jsondeleted−32

This diff is too big to show here.

worker/outlines/repl/elm.jsondeleted−19

This diff is too big to show here.

worker/src/Artifacts.hsdeleted−155

This diff is too big to show here.

worker/src/Cors.hsdeleted−48

This diff is too big to show here.

worker/src/Endpoint/Compile.hsdeleted−323

This diff is too big to show here.

worker/src/Endpoint/Quotes.hsdeleted−114

This diff is too big to show here.

worker/src/Endpoint/Repl.hsdeleted−244

This diff is too big to show here.

worker/src/Errors.elmdeleted−217

This diff is too big to show here.

worker/src/Main.hsdeleted−73

This diff is too big to show here.