Play

Check-in [c20bd81f06]
Login
Overview
Comment:PackageLoader now provides Qualifier with information about available external modules.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: c20bd81f069782baca6cb1500ca21bd0ec33a7fd1c5adf6fa0ad9525f0318b79
User & Date: robin.hansen on 2021-03-28 09:45:06
Other Links: branch diff | manifest | tags
Context
2021-03-28
11:18
PackageLoader now successfully generates Qualified AST for a multi-module project. Skips validation,... Closed-Leaf check-in: 6eb1210a51 user: robin.hansen tags: modules
09:45
PackageLoader now provides Qualifier with information about available external modules. check-in: c20bd81f06 user: robin.hansen tags: modules
2021-03-27
11:07
PackageLoader now attempts to parse and qualify first read module. Fails because loading dependant m... check-in: 19fdcbebbe user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/PackageLoader.elm from [43234ba93c] to [4a1bef494c].

38
39
40
41
42
43
44

45
46
47
48
49
50
51
..
54
55
56
57
58
59
60

61
62
63
64
65
66
67
...
287
288
289
290
291
292
293



294
295



296
297

298


299
300
301
302
303
304
305
...
337
338
339
340
341
342
343
















344
345
346
347
348
349
350
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376


type alias State =
    { rootPackage : PackageInfo
    , dependencies : Dict String SemanticVersion
    , dependentPackages : Dict String PackageInfo
    , filePathToModule : Dict String ( PackageName, ModuleName )

    }


type alias PackageInfo =
    { path : String
    , metadata : PackageMetadata
    , modules : List ModuleName
................................................................................

emptyState : PackageInfo -> State
emptyState rootPackage =
    { rootPackage = rootPackage
    , dependencies = rootPackage.metadata.dependencies
    , dependentPackages = Dict.empty
    , filePathToModule = Dict.empty

    }


type Msg
    = FileContents String String String
    | ResolvedDirectories String (List PackagePath)
    | ResolvedPackageModules String (List String)
................................................................................

        firstExposedModule :: remModules ->
            if List.member firstExposedModule state.rootPackage.modules then
                let
                    ( path, fileName ) =
                        readModuleFromDisk state.rootPackage.path firstExposedModule




                    pathsToModuleNames =
                        List.foldl pathsOfModules Dict.empty (state.rootPackage :: Dict.values state.dependentPackages)



                in
                Compiling

                    { state | filePathToModule = pathsToModuleNames }


                    remModules
                    (ReadFile path fileName)

            else
                Failed (ModuleNotFound (ModuleName.toString firstExposedModule))


................................................................................
                ( path, fileName ) =
                    readModuleFromDisk package.path moduleName
            in
            path ++ "/" ++ fileName
    in
    Dict.union acc modulePaths


















compilingUpdate : Msg -> State -> List ModuleName -> Model
compilingUpdate msg state remainingModules =
    case Debug.log "msg" msg of
        FileContents path fileName content ->
            let
                fullPath =
................................................................................
                ( Just ( packageName, moduleName ), Ok parserAst ) ->
                    let
                        qualifierResult =
                            Qualifier.run
                                { packageName = PackageName.toString packageName
                                , modulePath = ModuleName.toString moduleName
                                , ast = parserAst
                                , externalModules = Dict.empty
                                }
                    in
                    Failed <| InternalError <| "U" ++ Debug.toString qualifierResult

                ( Nothing, _ ) ->
                    Failed <| InternalError <| "Don't know why we read file: " ++ fullPath

        _ ->
            Failed <| InternalError <| "Unknown message for compile stage: " ++ Debug.toString msg







>







 







>







 







>
>
>

|
>
>
>


>
|
>
>







 







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







 







|









38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
...
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403


type alias State =
    { rootPackage : PackageInfo
    , dependencies : Dict String SemanticVersion
    , dependentPackages : Dict String PackageInfo
    , filePathToModule : Dict String ( PackageName, ModuleName )
    , moduleNameToPackageName : Dict String String
    }


type alias PackageInfo =
    { path : String
    , metadata : PackageMetadata
    , modules : List ModuleName
................................................................................

emptyState : PackageInfo -> State
emptyState rootPackage =
    { rootPackage = rootPackage
    , dependencies = rootPackage.metadata.dependencies
    , dependentPackages = Dict.empty
    , filePathToModule = Dict.empty
    , moduleNameToPackageName = Dict.empty
    }


type Msg
    = FileContents String String String
    | ResolvedDirectories String (List PackagePath)
    | ResolvedPackageModules String (List String)
................................................................................

        firstExposedModule :: remModules ->
            if List.member firstExposedModule state.rootPackage.modules then
                let
                    ( path, fileName ) =
                        readModuleFromDisk state.rootPackage.path firstExposedModule

                    allPackages =
                        state.rootPackage :: Dict.values state.dependentPackages

                    pathsToModuleNames =
                        List.foldl pathsOfModules Dict.empty allPackages

                    moduleNameToPackageName =
                        List.foldl absolutePathsOfModules Dict.empty allPackages
                in
                Compiling
                    { state
                        | filePathToModule = pathsToModuleNames
                        , moduleNameToPackageName = moduleNameToPackageName
                    }
                    remModules
                    (ReadFile path fileName)

            else
                Failed (ModuleNotFound (ModuleName.toString firstExposedModule))


................................................................................
                ( path, fileName ) =
                    readModuleFromDisk package.path moduleName
            in
            path ++ "/" ++ fileName
    in
    Dict.union acc modulePaths


absolutePathsOfModules : PackageInfo -> Dict String String -> Dict String String
absolutePathsOfModules package acc =
    let
        absolutePathsForModule =
            List.map
                (\moduleName ->
                    ( "/" ++ ModuleName.toString moduleName
                    , PackageName.toString package.metadata.name
                    )
                )
                package.modules
                |> Dict.fromList
    in
    Dict.union acc absolutePathsForModule


compilingUpdate : Msg -> State -> List ModuleName -> Model
compilingUpdate msg state remainingModules =
    case Debug.log "msg" msg of
        FileContents path fileName content ->
            let
                fullPath =
................................................................................
                ( Just ( packageName, moduleName ), Ok parserAst ) ->
                    let
                        qualifierResult =
                            Qualifier.run
                                { packageName = PackageName.toString packageName
                                , modulePath = ModuleName.toString moduleName
                                , ast = parserAst
                                , externalModules = state.moduleNameToPackageName
                                }
                    in
                    Failed <| InternalError <| "U" ++ Debug.toString qualifierResult

                ( Nothing, _ ) ->
                    Failed <| InternalError <| "Don't know why we read file: " ++ fullPath

        _ ->
            Failed <| InternalError <| "Unknown message for compile stage: " ++ Debug.toString msg