Stabel

Check-in [8a392255da]
Login
Overview
Comment:Parser now understands module referenced types in pattern matches.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 8a392255dada5339d61af28a561d32fc5d6298350e5c4966bdc40e6cea16b48d
User & Date: robin.hansen on 2021-05-21 14:42:22
Other Links: branch diff | manifest | tags
Context
2021-05-23
11:15
Qualifier can qualify type references to internal packages. Missing test for member types with inter... check-in: 18cd6199cb user: robin.hansen tags: module-definition
2021-05-21
14:42
Parser now understands module referenced types in pattern matches. check-in: 8a392255da user: robin.hansen tags: module-definition
2021-05-20
16:23
Parser now understands internal and external references in type signature. check-in: 4a96b863d6 user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Parser.elm from [5d132bcc2b] to [d5fc080542].

447
448
449
450
451
452
453





















454
455
456
457
458
459
460
...
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
            |. Parser.symbol (Token "(" ExpectedLeftParen)
            |. noiseParser
            |= Parser.lazy (\_ -> typeRefParser)
            |. Parser.symbol (Token ")" ExpectedRightParen)
            |. noiseParser
        ]























modularizedTypeRefParser :
    List String
    -> Parser (Parser.Step (List String) ( List String, String ))
modularizedTypeRefParser reversedPath =
    let
        onType type_ =
................................................................................
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse reverseTypes))
        ]


typeMatchParser : Parser TypeMatch
typeMatchParser =
    Parser.oneOf
        [ Parser.succeed (\startLoc type_ conds endLoc -> TypeMatch (SourceLocationRange startLoc endLoc) type_ conds)
            |= sourceLocationParser
            |= typeParser
            |= Parser.oneOf
                [ Parser.succeed identity
                    |. Parser.symbol (Token "(" ExpectedLeftParen)
                    |. noiseParser
                    |= Parser.loop [] typeMatchConditionParser
                    |. Parser.symbol (Token ")" ExpectedRightParen)
                , Parser.succeed []
                ]
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (\startLoc sym endLoc -> TypeMatch (SourceLocationRange startLoc endLoc) (Generic sym) [])
            |= sourceLocationParser
            |= genericParser
            |= sourceLocationParser
        , Parser.succeed (\startLoc typ endLoc -> TypeMatch (SourceLocationRange startLoc endLoc) typ [])
            |= sourceLocationParser
            |= typeRefParser
            |= sourceLocationParser
        ]


typeMatchConditionParser : List ( String, TypeMatchValue ) -> Parser (Parser.Step (List ( String, TypeMatchValue )) (List ( String, TypeMatchValue )))
typeMatchConditionParser nodes =
    Parser.oneOf
        [ Parser.succeed (\name value -> Parser.Loop (( name, value ) :: nodes))
            |= symbolParser







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







 







<
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<







447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995
996
997
998
999









1000
1001
1002
1003
1004
1005
1006
            |. Parser.symbol (Token "(" ExpectedLeftParen)
            |. noiseParser
            |= Parser.lazy (\_ -> typeRefParser)
            |. Parser.symbol (Token ")" ExpectedRightParen)
            |. noiseParser
        ]


typeMatchTypeParser : Parser PossiblyQualifiedType
typeMatchTypeParser =
    Parser.oneOf
        [ Parser.succeed (\name -> LocalRef name [])
            |= typeNameParser
        , Parser.succeed (\( path, name ) -> ExternalRef path name [])
            |. Parser.symbol (Token "/" NoProblem)
            |= Parser.loop [] modularizedTypeRefParser
        , Parser.succeed (\( path, name ) -> InternalRef path name [])
            |= Parser.loop [] modularizedTypeRefParser
        , Parser.succeed Generic
            |= genericParser
        , Parser.succeed identity
            |. Parser.symbol (Token "(" ExpectedLeftParen)
            |. noiseParser
            |= typeRefParser
            |. Parser.symbol (Token ")" ExpectedRightParen)
            |. noiseParser
        ]


modularizedTypeRefParser :
    List String
    -> Parser (Parser.Step (List String) ( List String, String ))
modularizedTypeRefParser reversedPath =
    let
        onType type_ =
................................................................................
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse reverseTypes))
        ]


typeMatchParser : Parser TypeMatch
typeMatchParser =

    Parser.succeed (\startLoc type_ conds endLoc -> TypeMatch (SourceLocationRange startLoc endLoc) type_ conds)
        |= sourceLocationParser
        |= typeMatchTypeParser
        |= Parser.oneOf
            [ Parser.succeed identity
                |. Parser.symbol (Token "(" ExpectedLeftParen)
                |. noiseParser
                |= Parser.loop [] typeMatchConditionParser
                |. Parser.symbol (Token ")" ExpectedRightParen)
            , Parser.succeed []
            ]
        |= sourceLocationParser
        |. noiseParser











typeMatchConditionParser : List ( String, TypeMatchValue ) -> Parser (Parser.Step (List ( String, TypeMatchValue )) (List ( String, TypeMatchValue )))
typeMatchConditionParser nodes =
    Parser.oneOf
        [ Parser.succeed (\name value -> Parser.Loop (( name, value ) :: nodes))
            |= symbolParser

Modified tests/Test/Parser.elm from [0d58f89141] to [b3a7642149].

971
972
973
974
975
976
977
































































































978
979
980
981
982
983
984
                                            SoloImpl
                                                [ AST.Word emptyRange "drop"
                                                , AST.Integer emptyRange 1
                                                ]
                                      }
                                    ]
                            }
































































































                    in
                    case compile source of
                        Err err ->
                            Expect.fail <| "Did not expect parsing to fail: " ++ Debug.toString err

                        Ok ast ->
                            Expect.equal expectedAst ast







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







971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
                                            SoloImpl
                                                [ AST.Word emptyRange "drop"
                                                , AST.Integer emptyRange 1
                                                ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err err ->
                            Expect.fail <| "Did not expect parsing to fail: " ++ Debug.toString err

                        Ok ast ->
                            Expect.equal expectedAst ast
            , test "External type in multifn" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: test
                            type: /external/Tipe -- Int
                            : /external/Tipe( value 1 )
                              drop 1
                            else:
                              drop 0
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , typeSignature =
                                            UserProvided
                                                { input = [ ExternalRef [ "external" ] "Tipe" [] ]
                                                , output = [ LocalRef "Int" [] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (ExternalRef [ "external" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                                  , [ AST.Word emptyRange "drop"
                                                    , AST.Integer emptyRange 1
                                                    ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "drop"
                                                , AST.Integer emptyRange 0
                                                ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err err ->
                            Expect.fail <| "Did not expect parsing to fail: " ++ Debug.toString err

                        Ok ast ->
                            Expect.equal expectedAst ast
            , test "Internal type in multifn" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: test
                            type: internal/Tipe -- Int
                            : internal/Tipe( value 1 )
                              drop 1
                            else:
                              drop 0
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , typeSignature =
                                            UserProvided
                                                { input = [ InternalRef [ "internal" ] "Tipe" [] ]
                                                , output = [ LocalRef "Int" [] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (InternalRef [ "internal" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                                  , [ AST.Word emptyRange "drop"
                                                    , AST.Integer emptyRange 1
                                                    ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "drop"
                                                , AST.Integer emptyRange 0
                                                ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err err ->
                            Expect.fail <| "Did not expect parsing to fail: " ++ Debug.toString err

                        Ok ast ->
                            Expect.equal expectedAst ast