Stabel

Check-in [e702dc606e]
Login
Overview
Comment:Parser now understands array literals.
Timelines: family | ancestors | descendants | both | arrays
Files: files | file ages | folders
SHA3-256: e702dc606ec10a39d5519324ecf13434dfb3d7bed5eaad4647219c3c4672f4b1
User & Date: robin.hansen on 2021-08-18 18:05:35
Other Links: branch diff | manifest | tags
Context
2021-08-20
17:09
Qualify nodes in an array. check-in: d2e7b4771d user: robin.hansen tags: arrays
2021-08-18
18:05
Parser now understands array literals. check-in: e702dc606e user: robin.hansen tags: arrays
17:33
Create new branch named "arrays" check-in: 62216173e8 user: robin.hansen tags: arrays
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Parser.elm from [3686af24e9] to [040268e985].

81
82
83
84
85
86
87

88
89
90
91
92
93
94
....
1044
1045
1046
1047
1048
1049
1050








1051
1052
1053
1054
1055
1056
1057
    | Function SourceLocationRange String
    | PackageFunction SourceLocationRange (List String) String
    | ExternalFunction SourceLocationRange (List String) String
    | InlineFunction SourceLocationRange (List AstNode)
    | ConstructType String
    | GetMember String String
    | SetMember String String



run : String -> String -> Result (List (Parser.DeadEnd Context Problem)) AST
run ref sourceCode =
    Parser.run (parser ref) sourceCode


................................................................................
        , Parser.succeed (\startLoc quotImpl endLoc -> Parser.Loop (InlineFunction (SourceLocationRange startLoc endLoc) quotImpl :: nodes))
            |= sourceLocationParser
            |. Parser.symbol (Token "[" ExpectedLeftBracket)
            |. noiseParser
            |= implementationParser
            |. Parser.symbol (Token "]" ExpectedRightBracket)
            |= sourceLocationParser








            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse nodes))
        ]


nodeParser : Parser AstNode
nodeParser =







>







 







>
>
>
>
>
>
>
>







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
....
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
    | Function SourceLocationRange String
    | PackageFunction SourceLocationRange (List String) String
    | ExternalFunction SourceLocationRange (List String) String
    | InlineFunction SourceLocationRange (List AstNode)
    | ConstructType String
    | GetMember String String
    | SetMember String String
    | ArrayLiteral SourceLocationRange (List AstNode)


run : String -> String -> Result (List (Parser.DeadEnd Context Problem)) AST
run ref sourceCode =
    Parser.run (parser ref) sourceCode


................................................................................
        , Parser.succeed (\startLoc quotImpl endLoc -> Parser.Loop (InlineFunction (SourceLocationRange startLoc endLoc) quotImpl :: nodes))
            |= sourceLocationParser
            |. Parser.symbol (Token "[" ExpectedLeftBracket)
            |. noiseParser
            |= implementationParser
            |. Parser.symbol (Token "]" ExpectedRightBracket)
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (\startLoc arrContent endLoc -> Parser.Loop (ArrayLiteral (SourceLocationRange startLoc endLoc) arrContent :: nodes))
            |= sourceLocationParser
            |. Parser.symbol (Token "{" ExpectedLeftCurly)
            |. noiseParser
            |= implementationParser
            |. Parser.symbol (Token "}" ExpectedRightCurly)
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse nodes))
        ]


nodeParser : Parser AstNode
nodeParser =

Modified src/Stabel/Parser/Problem.elm from [de8ce45cbd] to [11e01b8df9].

40
41
42
43
44
45
46


47
48
49
50
51
52
53
...
216
217
218
219
220
221
222






223
224
225
226
227
228
229
    | UnexpectedMetadata
    | ExpectedLeftParen
    | ExpectedRightParen
    | ExpectedEndOfFile
    | ExpectedTypeSeperator
    | ExpectedLeftBracket
    | ExpectedRightBracket


    | FunctionAlreadyDefined String (Maybe SourceLocationRange)
    | TypeAlreadyDefined String SourceLocationRange
    | UnknownMetadata String
    | InvalidModulePath String
    | ModuleIsEmpty
    | BadDefinition String

................................................................................

        ExpectedLeftBracket ->
            "Expected opening bracket"

        ExpectedRightBracket ->
            "Expected closing bracket"







        FunctionAlreadyDefined functionName maybePreviousDefinitionRange ->
            case maybePreviousDefinitionRange of
                Nothing ->
                    "You're trying to define a new function called '"
                        ++ functionName
                        ++ "', but this function has already been defined."








>
>







 







>
>
>
>
>
>







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
    | UnexpectedMetadata
    | ExpectedLeftParen
    | ExpectedRightParen
    | ExpectedEndOfFile
    | ExpectedTypeSeperator
    | ExpectedLeftBracket
    | ExpectedRightBracket
    | ExpectedLeftCurly
    | ExpectedRightCurly
    | FunctionAlreadyDefined String (Maybe SourceLocationRange)
    | TypeAlreadyDefined String SourceLocationRange
    | UnknownMetadata String
    | InvalidModulePath String
    | ModuleIsEmpty
    | BadDefinition String

................................................................................

        ExpectedLeftBracket ->
            "Expected opening bracket"

        ExpectedRightBracket ->
            "Expected closing bracket"

        ExpectedLeftCurly ->
            "Expected opening curly brace"

        ExpectedRightCurly ->
            "Expected closing curly brace"

        FunctionAlreadyDefined functionName maybePreviousDefinitionRange ->
            case maybePreviousDefinitionRange of
                Nothing ->
                    "You're trying to define a new function called '"
                        ++ functionName
                        ++ "', but this function has already been defined."

Modified src/Stabel/Qualifier.elm from [d0e65cfa74] to [7b4d8df174].

1408
1409
1410
1411
1412
1413
1414



1415
1416
1417
1418
1419
1420
1421
                            acc.inlineFunctionNames
                                |> Set.union qualifyNodeResult.inlineFunctionNames
                                |> Set.insert inlineFuncName
                    }

                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }





isMultiFunction : Parser.FunctionDefinition -> Bool
isMultiFunction def =
    case def.implementation of
        Parser.SoloImpl _ ->
            False







>
>
>







1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
                            acc.inlineFunctionNames
                                |> Set.union qualifyNodeResult.inlineFunctionNames
                                |> Set.insert inlineFuncName
                    }

                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }

        Parser.ArrayLiteral _ _ ->
            acc


isMultiFunction : Parser.FunctionDefinition -> Bool
isMultiFunction def =
    case def.implementation of
        Parser.SoloImpl _ ->
            False

Modified tests/Test/Parser.elm from [736941670b] to [7f783df7cb].

891
892
893
894
895
896
897









































898
899
900
901
902
903
904
                                                [ AST.Function emptyRange "False" ]
                                      }
                                    ]
                            }
                    in
                    expectAst source expectedAst
            ]









































        , test "Definition without implementation should be legal" <|
            \_ ->
                expectCompiles
                    """
                    def: somefunc
                    """
        , test "Support code comments" <|







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







891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
                                                [ AST.Function emptyRange "False" ]
                                      }
                                    ]
                            }
                    in
                    expectAst source expectedAst
            ]
        , test "Array" <|
            \_ ->
                let
                    source =
                        """
                        def: some-array
                        : { 1 2 /ext/func fn 5 { 1 2 } }
                        """

                    expectedAst =
                        { sourceReference = ""
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "some-array"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ArrayLiteral emptyRange
                                                [ AST.Integer emptyRange 1
                                                , AST.Integer emptyRange 2
                                                , AST.ExternalFunction emptyRange
                                                    [ "ext" ]
                                                    "func"
                                                , AST.Function emptyRange "fn"
                                                , AST.Integer emptyRange 5
                                                , AST.ArrayLiteral emptyRange
                                                    [ AST.Integer emptyRange 1
                                                    , AST.Integer emptyRange 2
                                                    ]
                                                ]
                                            ]
                                  }
                                ]
                        }
                in
                expectAst source expectedAst
        , test "Definition without implementation should be legal" <|
            \_ ->
                expectCompiles
                    """
                    def: somefunc
                    """
        , test "Support code comments" <|

Modified tests/Test/Parser/Util.elm from [6df7bbdd46] to [38c3a75d10].

78
79
80
81
82
83
84



85
86
87
88
89
90
91

        AST.ExternalFunction _ path val ->
            AST.ExternalFunction emptyRange path val

        AST.InlineFunction _ val ->
            AST.InlineFunction emptyRange (List.map stripNodeLocation val)




        _ ->
            node


stripMultiWordBranchLocation : ( TypeMatch, List AstNode ) -> ( TypeMatch, List AstNode )
stripMultiWordBranchLocation ( typeMatch, nodes ) =
    ( stripTypeMatchLocation typeMatch







>
>
>







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

        AST.ExternalFunction _ path val ->
            AST.ExternalFunction emptyRange path val

        AST.InlineFunction _ val ->
            AST.InlineFunction emptyRange (List.map stripNodeLocation val)

        AST.ArrayLiteral _ val ->
            AST.ArrayLiteral emptyRange (List.map stripNodeLocation val)

        _ ->
            node


stripMultiWordBranchLocation : ( TypeMatch, List AstNode ) -> ( TypeMatch, List AstNode )
stripMultiWordBranchLocation ( typeMatch, nodes ) =
    ( stripTypeMatchLocation typeMatch