Stabel

Check-in [562f019b23]
Login
Overview
Comment:Fixed parser bug for type signatures with multiple in/out arguments.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 562f019b23f63e6d4c8fd7079204a15616954c066bd1f4fb5fb57a07da2f0d0a
User & Date: robin.hansen on 2021-05-28 09:34:55
Other Links: branch diff | manifest | tags
Context
2021-05-29
16:14
Fixed bug where internal modules wasn't necesarily compiled in correct order. check-in: e91945bdeb user: robin.hansen tags: module-definition
2021-05-28
09:34
Fixed parser bug for type signatures with multiple in/out arguments. check-in: 562f019b23 user: robin.hansen tags: module-definition
2021-05-27
09:57
Added module definition to stdlib/core, and parsing fails. Needs investigation. check-in: 1e4ca8b20d user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Parser.elm from [d5fc080542] to [7fd0d74408].

418
419
420
421
422
423
424
425

426
427
428














429
430
431
432
433
434
435
...
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
                , Parser.succeed (Generic value)
                    |. Parser.chompIf (\c -> Set.member c whitespaceChars) NoProblem
                ]
    in
    Parser.andThen helper genericParser


typeParser : Parser PossiblyQualifiedType

typeParser =
    Parser.succeed (\name -> LocalRef name [])
        |= typeNameParser
















typeRefParser : Parser PossiblyQualifiedType
typeRefParser =
    Parser.oneOf
        [ Parser.succeed LocalRef
            |= typeNameParser
................................................................................
        step type_ =
            Parser.Loop (type_ :: reverseTypes)
    in
    Parser.oneOf
        [ Parser.succeed step
            |= genericOrRangeParser
        , Parser.succeed step
            |= typeRefParser
        , Parser.succeed (\wordType -> step (QuotationType wordType))
            |. Parser.symbol (Token "[" ExpectedLeftBracket)
            |. noiseParser
            |= typeSignatureParser
            |. Parser.symbol (Token "]" ExpectedRightBracket)
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse reverseTypes))







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







 







|







418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
...
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
                , Parser.succeed (Generic value)
                    |. Parser.chompIf (\c -> Set.member c whitespaceChars) NoProblem
                ]
    in
    Parser.andThen helper genericParser


typeSignatureRefParser : Parser PossiblyQualifiedType
typeSignatureRefParser =
    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
        ]


typeRefParser : Parser PossiblyQualifiedType
typeRefParser =
    Parser.oneOf
        [ Parser.succeed LocalRef
            |= typeNameParser
................................................................................
        step type_ =
            Parser.Loop (type_ :: reverseTypes)
    in
    Parser.oneOf
        [ Parser.succeed step
            |= genericOrRangeParser
        , Parser.succeed step
            |= typeSignatureRefParser
        , Parser.succeed (\wordType -> step (QuotationType wordType))
            |. Parser.symbol (Token "[" ExpectedLeftBracket)
            |. noiseParser
            |= typeSignatureParser
            |. Parser.symbol (Token "]" ExpectedRightBracket)
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse reverseTypes))

Modified tests/Test/Parser.elm from [b3a7642149] to [81204d11cf].

84
85
86
87
88
89
90







































91
92
93
94
95
96
97
                                            , AST.Word emptyRange "dec"
                                            , AST.Integer emptyRange 2
                                            , AST.Word emptyRange "="
                                            ]
                                  }
                                ]
                        }







































                in
                case compile source of
                    Err _ ->
                        Expect.fail "Did not expect parsing to fail"

                    Ok ast ->
                        Expect.equal expectedAst ast







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







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
128
129
130
131
132
133
134
135
136
                                            , AST.Word emptyRange "dec"
                                            , AST.Integer emptyRange 2
                                            , AST.Word emptyRange "="
                                            ]
                                  }
                                ]
                        }
                in
                case compile source of
                    Err _ ->
                        Expect.fail "Did not expect parsing to fail"

                    Ok ast ->
                        Expect.equal expectedAst ast
        , test "Multi args and type signature" <|
            \_ ->
                let
                    source =
                        """
                        def: int=
                        type: Int Int -- Bool
                        : - zero?
                        """

                    expectedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "int="
                                  , typeSignature =
                                        AST.UserProvided
                                            { input = [ AST.LocalRef "Int" [], AST.LocalRef "Int" [] ]
                                            , output = [ AST.LocalRef "Bool" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Word emptyRange "-"
                                            , AST.Word emptyRange "zero?"
                                            ]
                                  }
                                ]
                        }
                in
                case compile source of
                    Err _ ->
                        Expect.fail "Did not expect parsing to fail"

                    Ok ast ->
                        Expect.equal expectedAst ast