Stabel

Check-in [742e0c8355]
Login
Overview
Comment:Format errors from CLI.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 742e0c835508fb43acd82bca22427328ec4022ab0554a8e121871ed37e8b2776
User & Date: robin.hansen on 2021-06-02 09:59:33
Other Links: branch diff | manifest | tags
Context
2021-06-02
10:02
Add support for modules. Fixes [57c2233d50] and [abaac5803b] check-in: e155197c9a user: robin.hansen tags: trunk
09:59
Format errors from CLI. Closed-Leaf check-in: 742e0c8355 user: robin.hansen tags: module-definition
09:23
, is now a valid function name. check-in: 8e8bc32982 user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/CLI.elm from [2a2a2f3219] to [c955eddac9].

90
91
92
93
94
95
96

97

98
99
100
101
102
103
104
                                Err error ->
                                    ( model
                                    , outgoingPort <| encodeCompilationFailure error
                                    )

                        PackageLoader.Failed error ->
                            ( model

                            , outgoingPort <| encodeCompilationFailure <| Debug.toString error

                            )

                        _ ->
                            ( updatedModel
                            , sendSideEffectFromModel updatedModel
                            )








>
|
>







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
                                Err error ->
                                    ( model
                                    , outgoingPort <| encodeCompilationFailure error
                                    )

                        PackageLoader.Failed error ->
                            ( model
                            , outgoingPort <|
                                encodeCompilationFailure <|
                                    PackageLoader.problemToString error
                            )

                        _ ->
                            ( updatedModel
                            , sendSideEffectFromModel updatedModel
                            )

Modified src/Play/PackageLoader.elm from [cfb8a0b60d] to [2e56b7cc2e].

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20

21

22
23
24
25
26
27
28
29
30


31
32





























33
34
35
36
37
38
39
..
68
69
70
71
72
73
74

75
76
77
78
79
80
81
...
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
...
464
465
466
467
468
469
470

471
472
473
474
475
476
477
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
module Play.PackageLoader exposing
    ( Model(..)
    , Msg(..)
    , Problem(..)
    , SideEffect(..)
    , getSideEffect
    , init

    , update
    )

import Dict exposing (Dict)
import Json.Decode as Json
import List.Extra as List
import Play.Data.Metadata as Metadata
import Play.Data.ModuleName as ModuleName exposing (ModuleName)
import Play.Data.PackageMetadata as PackageMetadata exposing (PackageMetadata)
import Play.Data.PackageName as PackageName exposing (PackageName)
import Play.Data.PackagePath as PackagePath exposing (PackagePath)
import Play.Data.SemanticVersion as SemanticVersion exposing (SemanticVersion)
import Play.Parser as Parser

import Play.Qualifier as Qualifier

import Result.Extra as Result
import Set exposing (Set)


type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | NoExposedModulesInRootProject
    | ModuleNotFound String


    | InternalError String































type alias InitOptions =
    { projectDirPath : String
    , stdLibPath : String
    , possibleEntryPoint : Maybe String
    }

................................................................................


type alias ParsedModuleInfo =
    { packageName : PackageName
    , modulePath : ModuleName
    , ast : Parser.AST
    , requiredModules : Set String

    }


emptyState : InitOptions -> PackageInfo -> State
emptyState initOptions rootPackage =
    { possibleEntryPoint = initOptions.possibleEntryPoint
    , rootPackage = rootPackage
................................................................................
                    path ++ "/" ++ fileName

                possibleModuleInfo =
                    Dict.get fullPath state.filePathToModule
            in
            case ( possibleModuleInfo, Parser.run content ) of
                ( _, Err parserError ) ->
                    Failed <| InternalError <| "Parser error: " ++ Debug.toString parserError

                ( Just ( packageName, moduleName ), Ok parserAst ) ->
                    let
                        fullModuleName =
                            absoluteModuleName packageName moduleName

                        updatedParsedModules =
................................................................................
                            { state
                                | parsedModuleNames = updatedParsedModules
                                , parsedModules =
                                    { packageName = packageName
                                    , modulePath = moduleName
                                    , ast = parserAst
                                    , requiredModules = requiredModules

                                    }
                                        :: state.parsedModules
                            }

                        modulesQueuedForOrAlreadyParsed =
                            remainingModules
                                |> List.map (\( pInfo, mName ) -> absoluteModuleName pInfo.metadata.name mName)
................................................................................
                                , externalModules = state.moduleNameToPackageName
                                , inProgressAST = qast
                                }
                    in
                    case qualifierResult of
                        Err qualifierError ->
                            ( qast
                            , (InternalError <| "Qualifier error: " ++ Debug.toString qualifierError) :: es
                            )

                        Ok qualifiedAST ->
                            let
                                mergedQualifiedAst =
                                    { types = Dict.union qast.types qualifiedAST.types
                                    , words = Dict.union qast.words qualifiedAST.words
................................................................................
            case errs of
                [] ->
                    Done
                        { types = qualifiedAst.types
                        , words = wordsWithEntryPoint
                        }

                _ ->
                    Failed <| InternalError <| "Qualification failed with error: " ++ Debug.toString errs

        ( packageInfo, moduleName ) :: otherModules ->
            let
                ( path, fileName ) =
                    readModuleFromDisk packageInfo.path moduleName
            in
            Parsing state otherModules (ReadFile path fileName)







>













>

>









>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







|







 







>







 







|







 







|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
...
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
...
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
...
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
module Play.PackageLoader exposing
    ( Model(..)
    , Msg(..)
    , Problem(..)
    , SideEffect(..)
    , getSideEffect
    , init
    , problemToString
    , update
    )

import Dict exposing (Dict)
import Json.Decode as Json
import List.Extra as List
import Play.Data.Metadata as Metadata
import Play.Data.ModuleName as ModuleName exposing (ModuleName)
import Play.Data.PackageMetadata as PackageMetadata exposing (PackageMetadata)
import Play.Data.PackageName as PackageName exposing (PackageName)
import Play.Data.PackagePath as PackagePath exposing (PackagePath)
import Play.Data.SemanticVersion as SemanticVersion exposing (SemanticVersion)
import Play.Parser as Parser
import Play.Parser.Problem as ParserProblem
import Play.Qualifier as Qualifier
import Play.Qualifier.Problem as QualifierProblem
import Result.Extra as Result
import Set exposing (Set)


type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | NoExposedModulesInRootProject
    | ModuleNotFound String
    | ParserError String (List ParserProblem.Problem)
    | QualifierError String (List QualifierProblem.Problem)
    | InternalError String


problemToString : Problem -> String
problemToString problem =
    case problem of
        InvalidPackageMetadata path err ->
            "Something is wrong with file located at '" ++ path ++ "':\n\n" ++ err

        UnknownMessageForState msg ->
            "Unknown message for state: " ++ msg

        NoExposedModulesInRootProject ->
            "No exposed modules in root project"

        ModuleNotFound mod ->
            "Failed to locate module '" ++ mod ++ "' on disk"

        ParserError source errs ->
            errs
                |> List.map (ParserProblem.toString source)
                |> String.join "\n\n"

        QualifierError source errs ->
            errs
                |> List.map (QualifierProblem.toString source)
                |> String.join "\n\n"

        InternalError msg ->
            "Internal error: " ++ msg


type alias InitOptions =
    { projectDirPath : String
    , stdLibPath : String
    , possibleEntryPoint : Maybe String
    }

................................................................................


type alias ParsedModuleInfo =
    { packageName : PackageName
    , modulePath : ModuleName
    , ast : Parser.AST
    , requiredModules : Set String
    , source : String
    }


emptyState : InitOptions -> PackageInfo -> State
emptyState initOptions rootPackage =
    { possibleEntryPoint = initOptions.possibleEntryPoint
    , rootPackage = rootPackage
................................................................................
                    path ++ "/" ++ fileName

                possibleModuleInfo =
                    Dict.get fullPath state.filePathToModule
            in
            case ( possibleModuleInfo, Parser.run content ) of
                ( _, Err parserError ) ->
                    Failed <| ParserError content parserError

                ( Just ( packageName, moduleName ), Ok parserAst ) ->
                    let
                        fullModuleName =
                            absoluteModuleName packageName moduleName

                        updatedParsedModules =
................................................................................
                            { state
                                | parsedModuleNames = updatedParsedModules
                                , parsedModules =
                                    { packageName = packageName
                                    , modulePath = moduleName
                                    , ast = parserAst
                                    , requiredModules = requiredModules
                                    , source = content
                                    }
                                        :: state.parsedModules
                            }

                        modulesQueuedForOrAlreadyParsed =
                            remainingModules
                                |> List.map (\( pInfo, mName ) -> absoluteModuleName pInfo.metadata.name mName)
................................................................................
                                , externalModules = state.moduleNameToPackageName
                                , inProgressAST = qast
                                }
                    in
                    case qualifierResult of
                        Err qualifierError ->
                            ( qast
                            , QualifierError parsedModInfo.source qualifierError :: es
                            )

                        Ok qualifiedAST ->
                            let
                                mergedQualifiedAst =
                                    { types = Dict.union qast.types qualifiedAST.types
                                    , words = Dict.union qast.words qualifiedAST.words
................................................................................
            case errs of
                [] ->
                    Done
                        { types = qualifiedAst.types
                        , words = wordsWithEntryPoint
                        }

                err :: _ ->
                    Failed <| err

        ( packageInfo, moduleName ) :: otherModules ->
            let
                ( path, fileName ) =
                    readModuleFromDisk packageInfo.path moduleName
            in
            Parsing state otherModules (ReadFile path fileName)