Stabel

Check-in [83e76bc143]
Login
Overview
Comment:Refactored ModuleDefinition to be a custom type of either Defined or Undefined.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 83e76bc1433a920d9401ec06a1e947d5a00311819650a7098d91cd4c4cdea4c6
User & Date: robin.hansen on 2021-05-07 08:07:48
Other Links: branch diff | manifest | tags
Context
2021-05-07
08:41
Store in metadata whether a function is exposed or not. check-in: ecc08d85a0 user: robin.hansen tags: module-definition
08:07
Refactored ModuleDefinition to be a custom type of either Defined or Undefined. check-in: 83e76bc143 user: robin.hansen tags: module-definition
2021-05-06
15:37
Qualifier now understands imports. check-in: 7514c3ede5 user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Parser.elm from [53bc1d6feb] to [824d248e3d].

1
2
3
4
5
6
7
8
9
10
11
..
30
31
32
33
34
35
36





37
38
39
40
41
42
43
44
..
87
88
89
90
91
92
93





94
95
96
97
98
99
100
...
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
module Play.Parser exposing
    ( AST
    , AstNode(..)
    , ModuleDefinition
    , TypeDefinition(..)
    , TypeMatch(..)
    , TypeMatchValue(..)
    , WordDefinition
    , WordImplementation(..)
    , emptyModuleDefinition
    , run
................................................................................
type alias AST =
    { moduleDefinition : ModuleDefinition
    , types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }







type alias ModuleDefinition =
    { aliases : Dict String String
    , imports : Dict String (List String)
    , exposes : Set String
    }


type TypeDefinition
................................................................................


-- ATOMS


emptyModuleDefinition : ModuleDefinition
emptyModuleDefinition =





    { aliases = Dict.empty
    , imports = Dict.empty
    , exposes = Set.empty
    }


validSymbolChar : Char -> Bool
................................................................................


moduleDefinitionParser : Parser ModuleDefinition
moduleDefinitionParser =
    Parser.succeed identity
        |. Parser.keyword (Token "defmodule:" NoProblem)
        |. noiseParser
        |= Parser.loop emptyModuleDefinition moduleDefinitionMetaParser


moduleDefinitionMetaParser : ModuleDefinition -> Parser (Parser.Step ModuleDefinition ModuleDefinition)
moduleDefinitionMetaParser def =
    Parser.oneOf
        [ Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
            |. Parser.keyword (Token "alias:" NoProblem)
            |. noiseParser
            |= symbolParser
            |. noiseParser



|







 







>
>
>
>
>
|







 







>
>
>
>
>







 







|


|







1
2
3
4
5
6
7
8
9
10
11
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
module Play.Parser exposing
    ( AST
    , AstNode(..)
    , ModuleDefinition(..)
    , TypeDefinition(..)
    , TypeMatch(..)
    , TypeMatchValue(..)
    , WordDefinition
    , WordImplementation(..)
    , emptyModuleDefinition
    , run
................................................................................
type alias AST =
    { moduleDefinition : ModuleDefinition
    , types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }


type ModuleDefinition
    = Undefined
    | Defined ModuleDefinitionRec


type alias ModuleDefinitionRec =
    { aliases : Dict String String
    , imports : Dict String (List String)
    , exposes : Set String
    }


type TypeDefinition
................................................................................


-- ATOMS


emptyModuleDefinition : ModuleDefinition
emptyModuleDefinition =
    Undefined


emptyModuleDefinitionRec : ModuleDefinitionRec
emptyModuleDefinitionRec =
    { aliases = Dict.empty
    , imports = Dict.empty
    , exposes = Set.empty
    }


validSymbolChar : Char -> Bool
................................................................................


moduleDefinitionParser : Parser ModuleDefinition
moduleDefinitionParser =
    Parser.succeed identity
        |. Parser.keyword (Token "defmodule:" NoProblem)
        |. noiseParser
        |= Parser.map Defined (Parser.loop emptyModuleDefinitionRec moduleDefinitionMetaParser)


moduleDefinitionMetaParser : ModuleDefinitionRec -> Parser (Parser.Step ModuleDefinitionRec ModuleDefinitionRec)
moduleDefinitionMetaParser def =
    Parser.oneOf
        [ Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
            |. Parser.keyword (Token "alias:" NoProblem)
            |. noiseParser
            |= symbolParser
            |. noiseParser

Modified src/Play/Qualifier.elm from [a33356266b] to [02ca7b631a].

253
254
255
256
257
258
259
260
261

262
263
264




265
266
267
268
269
270
271
272
273
...
776
777
778
779
780
781
782
783





784
785
786
787
788
789
790
791


792
793



794
795
796
797
798
799
800
                Parser.SoloImpl defImpl ->
                    ( [], defImpl )

                Parser.MultiImpl whenImpl defImpl ->
                    ( whenImpl, defImpl )

        moduleReferences =
            { aliases =
                config.ast.moduleDefinition.aliases

                    |> Dict.union unqualifiedWord.metadata.aliases
            , imports =
                config.ast.moduleDefinition.imports




                    |> Dict.union unqualifiedWord.metadata.imports
            }

        ( newWordsAfterWhens, qualifiedWhensResult ) =
            whens
                |> List.foldr (qualifyWhen config qualifiedTypes unqualifiedWord.name moduleReferences) ( acc, [] )
                |> Tuple.mapSecond Result.combine

        ( newWordsAfterImpl, qualifiedImplementationResult ) =
................................................................................
    }


requiredModules : RequiredModulesConfig -> Set String
requiredModules config =
    let
        topLevelAliases =
            config.ast.moduleDefinition.aliases






        topLevelAliasTargets =
            topLevelAliases
                |> Dict.values
                |> Set.fromList

        topLevelImports =
            config.ast.moduleDefinition.imports


                |> Dict.keys
                |> Set.fromList




        wordRequirements =
            config.ast.words
                |> Dict.foldl
                    (\_ w acc -> Set.union (requiredModulesOfWord topLevelAliases w) acc)
                    Set.empty








<
|
>
|
|
<
>
>
>
>
|
|







 







|
>
>
>
>
>







|
>
>
|
|
>
>
>







253
254
255
256
257
258
259

260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
...
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
                Parser.SoloImpl defImpl ->
                    ( [], defImpl )

                Parser.MultiImpl whenImpl defImpl ->
                    ( whenImpl, defImpl )

        moduleReferences =

            case config.ast.moduleDefinition of
                Parser.Defined def ->
                    { aliases = Dict.union unqualifiedWord.metadata.aliases def.aliases
                    , imports = Dict.union unqualifiedWord.metadata.imports def.imports

                    }

                Parser.Undefined ->
                    { aliases = unqualifiedWord.metadata.aliases
                    , imports = unqualifiedWord.metadata.imports
                    }

        ( newWordsAfterWhens, qualifiedWhensResult ) =
            whens
                |> List.foldr (qualifyWhen config qualifiedTypes unqualifiedWord.name moduleReferences) ( acc, [] )
                |> Tuple.mapSecond Result.combine

        ( newWordsAfterImpl, qualifiedImplementationResult ) =
................................................................................
    }


requiredModules : RequiredModulesConfig -> Set String
requiredModules config =
    let
        topLevelAliases =
            case config.ast.moduleDefinition of
                Parser.Defined def ->
                    def.aliases

                Parser.Undefined ->
                    Dict.empty

        topLevelAliasTargets =
            topLevelAliases
                |> Dict.values
                |> Set.fromList

        topLevelImports =
            case config.ast.moduleDefinition of
                Parser.Defined def ->
                    def.imports
                        |> Dict.keys
                        |> Set.fromList

                Parser.Undefined ->
                    Set.empty

        wordRequirements =
            config.ast.words
                |> Dict.foldl
                    (\_ w acc -> Set.union (requiredModulesOfWord topLevelAliases w) acc)
                    Set.empty

Modified tests/Test/Parser.elm from [957dee712d] to [9fc7acb122].

1058
1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084

                            def: inc
                            : 1 +
                            """

                        expectedAst =
                            { moduleDefinition =

                                { aliases =
                                    Dict.fromList
                                        [ ( "other", "/some/mod" )
                                        , ( "moar", "local/mod" )
                                        ]
                                , imports =
                                    Dict.fromList
                                        [ ( "/some/other/mod", [ "test1", "word2" ] )
                                        , ( "internals", [ "foo" ] )
                                        , ( "internal/mod", [] )
                                        ]
                                , exposes = Set.fromList [ "inc" ]
                                }
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef
                                        emptyRange
                                        "Pair"
                                        [ "a", "b" ]
                                        [ ( "first", Type.Generic "a" )







>
|
|
|
|
|
|
|
|
|
|
|
|
|







1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085

                            def: inc
                            : 1 +
                            """

                        expectedAst =
                            { moduleDefinition =
                                Defined
                                    { aliases =
                                        Dict.fromList
                                            [ ( "other", "/some/mod" )
                                            , ( "moar", "local/mod" )
                                            ]
                                    , imports =
                                        Dict.fromList
                                            [ ( "/some/other/mod", [ "test1", "word2" ] )
                                            , ( "internals", [ "foo" ] )
                                            , ( "internal/mod", [] )
                                            ]
                                    , exposes = Set.fromList [ "inc" ]
                                    }
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef
                                        emptyRange
                                        "Pair"
                                        [ "a", "b" ]
                                        [ ( "first", Type.Generic "a" )

Modified tests/Test/Qualifier.elm from [67a8298dfc] to [386043c227].

1035
1036
1037
1038
1039
1040
1041

1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
....
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
....
1374
1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
....
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
....
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
                in
                QualifierUtil.expectModuleOutput unqualifiedAst expectedAst
        , test "Retrieve dependant modules" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition =

                            { aliases =
                                Dict.fromList
                                    [ ( "html", "/external/html" ) ]
                            , imports =
                                Dict.fromList
                                    [ ( "/external/module", [] ) ]
                            , exposes = Set.fromList []
                            }
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "call-external"
                                  , metadata = Metadata.default
                                  , implementation =
                                        AST.MultiImpl
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module alias" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =

                                { aliases =
                                    Dict.fromList
                                        [ ( "ext", "/mod" )
                                        , ( "internal", "internal/mod" )
                                        ]
                                , imports = Dict.empty
                                , exposes = Set.empty
                                }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module and function aliases" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =

                                { aliases =
                                    Dict.fromList
                                        [ ( "ext", "/mod" ) ]
                                , imports = Dict.empty
                                , exposes = Set.empty
                                }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withAlias "internal" "internal/mod"
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module imports" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =

                                { aliases = Dict.empty
                                , imports =
                                    Dict.fromList
                                        [ ( "/mod", [ "add" ] )
                                        , ( "internal/mod", [] )
                                        ]
                                , exposes = Set.empty
                                }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module and function imports" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =

                                { aliases = Dict.empty
                                , imports =
                                    Dict.fromList
                                        [ ( "internal/mod", [] )
                                        ]
                                , exposes = Set.empty
                                }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withImport "/mod" [ "add" ]







>
|
|
|
|
|
|
|
|







 







>
|
|
|
|
|
|
|
|







 







>
|
|
|
|
|
|







 







>
|
|
|
|
|
|
|
|







 







>
|
|
|
|
|
|
|







1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
....
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
....
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
....
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
....
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
                in
                QualifierUtil.expectModuleOutput unqualifiedAst expectedAst
        , test "Retrieve dependant modules" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition =
                            AST.Defined
                                { aliases =
                                    Dict.fromList
                                        [ ( "html", "/external/html" ) ]
                                , imports =
                                    Dict.fromList
                                        [ ( "/external/module", [] ) ]
                                , exposes = Set.fromList []
                                }
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "call-external"
                                  , metadata = Metadata.default
                                  , implementation =
                                        AST.MultiImpl
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module alias" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases =
                                        Dict.fromList
                                            [ ( "ext", "/mod" )
                                            , ( "internal", "internal/mod" )
                                            ]
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module and function aliases" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases =
                                        Dict.fromList
                                            [ ( "ext", "/mod" ) ]
                                    , imports = Dict.empty
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withAlias "internal" "internal/mod"
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module imports" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases = Dict.empty
                                    , imports =
                                        Dict.fromList
                                            [ ( "/mod", [ "add" ] )
                                            , ( "internal/mod", [] )
                                            ]
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
................................................................................
                        unqualifiedAst
                        expectedAst
            , test "Module and function imports" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases = Dict.empty
                                    , imports =
                                        Dict.fromList
                                            [ ( "internal/mod", [] )
                                            ]
                                    , exposes = Set.empty
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withImport "/mod" [ "add" ]