Stabel

Check-in [7c8e530718]
Login
Overview
Comment:Aliases can now be implicit [c2996a5e70]
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7c8e5307184d3b0f0bee12b25f185e9051719b6a1196b18eb0541e6780c3c3fb
User & Date: robin.hansen on 2021-09-20 16:33:12
Other Links: manifest | tags
Context
2021-09-24
09:35
Integers can now be represented directly in multifunction pattern matching. [c2996a5e70] check-in: 71f2929943 user: robin.hansen tags: trunk
2021-09-21
17:37
Attempted syntax sugar approach for supporting int literals as pattern match, but it causes codegen ... check-in: 8bbd6d2ddc user: robin.hansen tags: int-literals-in-pattern-match
2021-09-20
16:33
Aliases can now be implicit [c2996a5e70] check-in: 7c8e530718 user: robin.hansen tags: trunk
16:18
Change order of fields for alias: metadata [c2996a5e70]. check-in: 24cb64e9da user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Parser.elm from [ae1250b7de] to [6bb3a2d289].

757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
...
794
795
796
797
798
799
800






























801
802
803
804
805
806
807
...
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
....
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102

moduleDefinitionMetaParser :
    ModuleDefinition.Definition
    -> Parser (Parser.Step ModuleDefinition.Definition ModuleDefinition.Definition)
moduleDefinitionMetaParser def =
    Parser.oneOf
        [ Parser.inContext Problem.AliasKeyword
            (Parser.succeed (\value alias -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= symbolParser
                |. noiseParser
            )
        , Parser.inContext Problem.ImportKeyword
            (Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
................................................................................
            |= metadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done def)
            |. Parser.keyword (Token ":" UnknownError)
            |. noiseParser
        ]
































definitionParser : AST -> Parser (Parser.Step AST AST)
definitionParser ast =
    let
        insertFunction funcDef =
            { ast | functions = Dict.insert funcDef.name funcDef ast.functions }
                |> Parser.Loop
................................................................................
        , Parser.inContext Problem.DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext Problem.AliasKeyword <|
            Parser.succeed (\value alias -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= symbolParser
                |. noiseParser
        , Parser.inContext Problem.ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
................................................................................
                |. noiseParser
        , Parser.inContext Problem.ElseKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = setDefaultImpl impl })
                |. Parser.keyword (Token "else:" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.inContext Problem.AliasKeyword <|
            Parser.succeed (\value alias -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= symbolParser
                |. noiseParser
        , Parser.inContext Problem.ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser







|
<
|
<
<
<







 







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







 







|
<
|
<
<
<







 







|
<
|
<
<
<







757
758
759
760
761
762
763
764

765



766
767
768
769
770
771
772
...
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
....
1001
1002
1003
1004
1005
1006
1007
1008

1009



1010
1011
1012
1013
1014
1015
1016
....
1105
1106
1107
1108
1109
1110
1111
1112

1113



1114
1115
1116
1117
1118
1119
1120

moduleDefinitionMetaParser :
    ModuleDefinition.Definition
    -> Parser (Parser.Step ModuleDefinition.Definition ModuleDefinition.Definition)
moduleDefinitionMetaParser def =
    Parser.oneOf
        [ Parser.inContext Problem.AliasKeyword
            (Parser.succeed (\( value, alias ) -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })

                |= aliasParser



                |. noiseParser
            )
        , Parser.inContext Problem.ImportKeyword
            (Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
................................................................................
            |= metadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done def)
            |. Parser.keyword (Token ":" UnknownError)
            |. noiseParser
        ]


aliasParser : Parser ( String, String )
aliasParser =
    Parser.succeed aliasParserHelp
        |. Parser.keyword (Token "alias:" UnknownError)
        |. noiseParser
        |= modulePathStringParser
        |. noiseParser
        |= Parser.oneOf
            [ Parser.succeed Just
                |= symbolParser
            , Parser.succeed Nothing
            ]


aliasParserHelp : String -> Maybe String -> ( String, String )
aliasParserHelp modulePath maybeAlias =
    case maybeAlias of
        Just alias ->
            ( modulePath, alias )

        Nothing ->
            ( modulePath
            , modulePath
                |> String.split "/"
                |> List.last
                -- will never happen
                |> Maybe.withDefault ""
            )


definitionParser : AST -> Parser (Parser.Step AST AST)
definitionParser ast =
    let
        insertFunction funcDef =
            { ast | functions = Dict.insert funcDef.name funcDef ast.functions }
                |> Parser.Loop
................................................................................
        , Parser.inContext Problem.DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext Problem.AliasKeyword <|
            Parser.succeed (\( value, alias ) -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })

                |= aliasParser



                |. noiseParser
        , Parser.inContext Problem.ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
................................................................................
                |. noiseParser
        , Parser.inContext Problem.ElseKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = setDefaultImpl impl })
                |. Parser.keyword (Token "else:" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.inContext Problem.AliasKeyword <|
            Parser.succeed (\( value, alias ) -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })

                |= aliasParser



                |. noiseParser
        , Parser.inContext Problem.ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser

Modified tests/Test/Parser/ModuleDefinition.elm from [0789548606] to [598f9224a4].

68
69
70
71
72
73
74














































75
76
77
78
79
80
81
                                  , members =
                                        AST.StructMembers
                                            [ ( "first", Generic "a" )
                                            , ( "second", Generic "b" )
                                            ]
                                  }
                                ]














































                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty







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







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
                                  , members =
                                        AST.StructMembers
                                            [ ( "first", Generic "a" )
                                            , ( "second", Generic "b" )
                                            ]
                                  }
                                ]
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "+"
                                            ]
                                  }
                                ]
                        }
                            |> addFunctionsForStructs
                in
                expectAst source expectedAst
        , test "Aliases can be implicit" <|
            \_ ->
                let
                    source =
                        """
                        defmodule:
                        alias: /some/mod 
                        exposing: inc
                        :

                        def: inc
                        : 1 +
                        """

                    expectedAst =
                        { sourceReference = ""
                        , moduleDefinition =
                            ModuleDefinition.Defined
                                { aliases =
                                    Dict.fromList
                                        [ ( "mod", "/some/mod" )
                                        ]
                                , imports = Dict.empty
                                , exposes = Set.fromList [ "inc" ]
                                , documentation = ""
                                }
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty

Modified wasm_tests/module_resolution.test.js from [a03584297b] to [327530c16f].

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
            },
            {
                package: 'author/sample',
                module: 'core',
                source: `
                    defmodule:
                    alias: /mod ext 
                    alias: internal/tope tope 
                    :

                    defstruct: TipeTope
                    : first tope/Tope

                    def: main
                    alias: internal/mod internal 







|







219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
            },
            {
                package: 'author/sample',
                module: 'core',
                source: `
                    defmodule:
                    alias: /mod ext 
                    alias: internal/tope
                    :

                    defstruct: TipeTope
                    : first tope/Tope

                    def: main
                    alias: internal/mod internal