Play

Check-in [6bae4df17f]
Login
Overview
Comment:Add (untested) parser for module definitions.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 6bae4df17f6efda751e95cd6ff530139ec78935ab4cc5787a9a13e4aa95d4015
User & Date: robin.hansen on 2021-04-21 08:26:14
Other Links: branch diff | manifest | tags
Context
2021-04-29
13:10
Write test for parsing module definitions, and fix for the discovered bugs. check-in: 8ef7064bf4 user: robin.hansen tags: module-definition
2021-04-21
08:26
Add (untested) parser for module definitions. check-in: 6bae4df17f user: robin.hansen tags: module-definition
2021-04-17
11:05
First implementation of the standard library. Leaf check-in: 7e9c8cf531 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Parser.elm from [f9f02c0303] to [8d3a0e8e1f].

1
2
3

4
5
6
7
8

9
10
11
12
13
14
15
..
22
23
24
25
26
27
28

29
30
31
32







33
34
35
36
37
38
39
..
74
75
76
77
78
79
80








81
82
83
84
85
86
87
...
177
178
179
180
181
182
183










184
185
186
187
188
189
190
...
232
233
234
235
236
237
238






239
240
241
242
243
244
245
...
379
380
381
382
383
384
385



386

387
388
389
390
391
392




393



394
395





































396
397
398
399
400
401
402
module Play.Parser exposing
    ( AST
    , AstNode(..)

    , TypeDefinition(..)
    , TypeMatch(..)
    , TypeMatchValue(..)
    , WordDefinition
    , WordImplementation(..)

    , run
    , typeDefinitionName
    )

import Dict exposing (Dict)
import Dict.Extra as Dict
import Parser.Advanced as Parser exposing ((|.), (|=), Token(..))
................................................................................


type alias Parser a =
    Parser.Parser () Problem a


type alias AST =

    { types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }









type TypeDefinition
    = CustomTypeDef SourceLocationRange String (List String) (List ( String, Type ))
    | UnionTypeDef SourceLocationRange String (List String) (List Type)


type alias WordDefinition =
................................................................................
    Parser.run parser sourceCode
        |> Result.mapError (List.map .problem)



-- ATOMS










validSymbolChar : Char -> Bool
validSymbolChar c =
    not <| Set.member c invalidSymbolChars


invalidSymbolChars : Set Char
................................................................................
            [ Parser.succeed identity
                |. Parser.symbol (Token ":" NotMetadata)
                |> Parser.andThen (\_ -> Parser.problem FoundMetadata)
            , Parser.succeed identity
            ]
        |> Parser.backtrackable












symbolImplParser2 : Parser (SourceLocationRange -> AstNode)
symbolImplParser2 =
    let
        externalBuilder firstSymbol (( partialPath, reference ) as modulePathResult) =
            let
                path =
................................................................................
                [ Parser.loop [] modulePathParser
                , Parser.succeed ( [], "" )
                ]
        ]
        |. noiseParser
        |> Parser.andThen identity








modulePathParser : List String -> Parser (Parser.Step (List String) ( List String, String ))
modulePathParser symbols =
    Parser.oneOf
        [ Parser.succeed (\name -> Parser.Loop (name :: symbols))
            |. Parser.symbol (Token "/" NotMetadata)
            |= symbolImplParser
................................................................................

-- Grammar


parser : Parser AST
parser =
    let



        emptyAst =

            { types = Dict.empty
            , words = Dict.empty
            }
    in
    Parser.succeed identity
        |. noiseParser




        |= Parser.loop emptyAst definitionParser



        |. Parser.end ExpectedEnd







































definitionParser : AST -> Parser (Parser.Step AST AST)
definitionParser ast =
    let
        insertWord wordDef =
            case maybeInsertWordProblem wordDef of
                Just problem ->



>





>







 







>
|



>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>







 







>
>
>

>
|





>
>
>
>
|
>
>
>


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







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
...
413
414
415
416
417
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
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
482
483
484
module Play.Parser exposing
    ( AST
    , AstNode(..)
    , ModuleDefinition
    , TypeDefinition(..)
    , TypeMatch(..)
    , TypeMatchValue(..)
    , WordDefinition
    , WordImplementation(..)
    , emptyModuleDefinition
    , run
    , typeDefinitionName
    )

import Dict exposing (Dict)
import Dict.Extra as Dict
import Parser.Advanced as Parser exposing ((|.), (|=), Token(..))
................................................................................


type alias Parser a =
    Parser.Parser () Problem a


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 : List String
    }


type TypeDefinition
    = CustomTypeDef SourceLocationRange String (List String) (List ( String, Type ))
    | UnionTypeDef SourceLocationRange String (List String) (List Type)


type alias WordDefinition =
................................................................................
    Parser.run parser sourceCode
        |> Result.mapError (List.map .problem)



-- ATOMS


emptyModuleDefinition : ModuleDefinition
emptyModuleDefinition =
    { aliases = Dict.empty
    , imports = Dict.empty
    , exposes = []
    }


validSymbolChar : Char -> Bool
validSymbolChar c =
    not <| Set.member c invalidSymbolChars


invalidSymbolChars : Set Char
................................................................................
            [ Parser.succeed identity
                |. Parser.symbol (Token ":" NotMetadata)
                |> Parser.andThen (\_ -> Parser.problem FoundMetadata)
            , Parser.succeed identity
            ]
        |> Parser.backtrackable


symbolImplListParser : List String -> Parser (Parser.Step (List String) (List String))
symbolImplListParser symbols =
    Parser.oneOf
        [ Parser.succeed (\sym -> Parser.Loop (sym :: symbols))
            |= symbolImplParser
            |. noiseParser
        , Parser.succeed (Parser.Done <| List.reverse symbols)
        ]


symbolImplParser2 : Parser (SourceLocationRange -> AstNode)
symbolImplParser2 =
    let
        externalBuilder firstSymbol (( partialPath, reference ) as modulePathResult) =
            let
                path =
................................................................................
                [ Parser.loop [] modulePathParser
                , Parser.succeed ( [], "" )
                ]
        ]
        |. noiseParser
        |> Parser.andThen identity


modulePathStringParser : Parser String
modulePathStringParser =
    Parser.loop [] modulePathParser
        |> Parser.map (\( path, name ) -> String.join "/" (path ++ [ name ]))


modulePathParser : List String -> Parser (Parser.Step (List String) ( List String, String ))
modulePathParser symbols =
    Parser.oneOf
        [ Parser.succeed (\name -> Parser.Loop (name :: symbols))
            |. Parser.symbol (Token "/" NotMetadata)
            |= symbolImplParser
................................................................................

-- Grammar


parser : Parser AST
parser =
    let
        joinParseResults modDef ast =
            { ast | moduleDefinition = modDef }

        emptyAst =
            { moduleDefinition = emptyModuleDefinition
            , types = Dict.empty
            , words = Dict.empty
            }
    in
    Parser.succeed identity
        |. noiseParser
        |= Parser.oneOf
            [ Parser.succeed joinParseResults
                |= moduleDefinitionParser
                |. noiseParser
                |= Parser.loop emptyAst definitionParser
            , Parser.succeed (joinParseResults emptyModuleDefinition)
                |= Parser.loop emptyAst definitionParser
            ]
        |. Parser.end ExpectedEnd


moduleDefinitionParser : Parser ModuleDefinition
moduleDefinitionParser =
    Parser.succeed identity
        |. Parser.keyword (Token "defmodule:" NoProblem)
        |= 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
            |= modulePathStringParser
            |. noiseParser
        , Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
            |. Parser.keyword (Token "import:" NoProblem)
            |. noiseParser
            |= modulePathStringParser
            |. noiseParser
            |= Parser.loop [] symbolImplListParser
            |. noiseParser
        , Parser.succeed (\exposings -> Parser.Loop { def | exposes = exposings })
            |. Parser.keyword (Token "exposing:" NoProblem)
            |. noiseParser
            |= Parser.loop [] symbolImplListParser
            |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done def)
            |. Parser.keyword (Token ":" NoProblem)
        ]


definitionParser : AST -> Parser (Parser.Step AST AST)
definitionParser ast =
    let
        insertWord wordDef =
            case maybeInsertWordProblem wordDef of
                Just problem ->

Modified tests/Test/Parser.elm from [a9f19ae62c] to [64a5198555].

28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
..
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
...
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
...
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
...
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
...
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
...
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
...
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395
...
440
441
442
443
444
445
446

447
448
449
450
451
452
453
454
...
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510
...
551
552
553
554
555
556
557

558
559
560
561
562
563
564
565
...
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
...
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657
...
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701
...
725
726
727
728
729
730
731

732
733
734
735
736
737
738
739
...
753
754
755
756
757
758
759

760
761
762
763
764
765
766
767
...
781
782
783
784
785
786
787

788
789
790
791
792
793
794
795
...
862
863
864
865
866
867
868

869
870
871
872
873
874
875
876

                        def: main
                        entry: true
                        : 1 inc inc dec 2 =
                        """

                    expectedAst =

                        { types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , metadata = Metadata.default
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
................................................................................
                            
                            def: as-int
                            type: True -- Int
                            : 1
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange "True" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "as-int"
                                      , metadata =
................................................................................

                            def: get-age
                            type: Person -- Int
                            : age>
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange
                                        "Person"
                                        []
                                        [ ( "age", Type.Int )
                                        , ( "jobs", Type.Int )
                                        ]
................................................................................
                        source =
                            """
                            defstruct: Box a
                            : element a
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange
                                        "Box"
                                        [ "a" ]
                                        [ ( "element", Type.Generic "a" )
                                        ]
                                    ]
................................................................................
                        """
                        def: over
                        type: a b -- a b a
                        : dup rotate
                        """

                    expectedAst =

                        { types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "over"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Generic "a", Type.Generic "b" ]
................................................................................
                            : True
                              drop 1
                            : False
                              drop 0
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "Bool"
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
................................................................................
                            : a
                              !
                            : Nil
                              drop
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "Maybe"
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
................................................................................
                            : (Box a)
                              !
                            : Nil
                              drop
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "MaybeBox"
                                        [ "a" ]
                                        [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                        , Type.Custom "Nil"
                                        ]
................................................................................
                            : (Box a)
                              !
                            : Nil
                              drop
                            """

                        expectedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "MaybeBox"
                                        [ "a" ]
                                        [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                        , Type.Custom "Nil"
                                        ]
................................................................................

                        def: main
                        entry: true
                        : 1 [ 1 + ] apply-to-num
                        """

                    expectedAst =

                        { types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "apply-to-num"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Int
................................................................................

                        def: main
                        entry: true
                        : 1 [ 1 + ] apply-to-num
                        """

                    expectedAst =

                        { types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "apply-to-num"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.StackRange "a"
................................................................................
                            defmulti: zero?
                            : Int( value 0 )
                              True
                            else: False
                            """

                        expectedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
................................................................................
                            defmulti: pair?
                            : List( tail List( tail Nil ) )
                              True
                            else: False
                            """

                        expectedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "pair?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
................................................................................
                            defmulti: origo?
                            : Pair( first 0 second 0 )
                              True
                            else: False
                            """

                        expectedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "origo?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
................................................................................
                        source =
                            """
                            def: test
                            : some/module/sample
                            """

                        expectedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ AST.PackageWord emptyRange [ "some", "module" ] "sample" ]
................................................................................
                        source =
                            """
                            def: test
                            : /some/module/sample
                            """

                        expectedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ AST.ExternalWord emptyRange [ "some", "module" ] "sample" ]
................................................................................
                        source =
                            """
                            def: test
                            : internal/sample /some/module/sample
                            """

                        expectedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ AST.PackageWord emptyRange [ "internal" ] "sample"
................................................................................
                          False
                        else: True
                        """

                    -- The ending source location for most definitions now ends where the next definition beings
                    -- This is not what we want (it includes too much white space), but it'll do for now.
                    expectedAst =

                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ UnionTypeDef
                                    (SourceLocationRange
                                        (SourceLocation 2 1 1)
                                        (SourceLocation 6 1 32)
                                    )
                                    "Bool"







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
...
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
...
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
...
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
...
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
...
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
...
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
...
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
...
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894

                        def: main
                        entry: true
                        : 1 inc inc dec 2 =
                        """

                    expectedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , metadata = Metadata.default
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
................................................................................
                            
                            def: as-int
                            type: True -- Int
                            : 1
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange "True" [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "as-int"
                                      , metadata =
................................................................................

                            def: get-age
                            type: Person -- Int
                            : age>
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange
                                        "Person"
                                        []
                                        [ ( "age", Type.Int )
                                        , ( "jobs", Type.Int )
                                        ]
................................................................................
                        source =
                            """
                            defstruct: Box a
                            : element a
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange
                                        "Box"
                                        [ "a" ]
                                        [ ( "element", Type.Generic "a" )
                                        ]
                                    ]
................................................................................
                        """
                        def: over
                        type: a b -- a b a
                        : dup rotate
                        """

                    expectedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "over"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Generic "a", Type.Generic "b" ]
................................................................................
                            : True
                              drop 1
                            : False
                              drop 0
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "Bool"
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
................................................................................
                            : a
                              !
                            : Nil
                              drop
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "Maybe"
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
................................................................................
                            : (Box a)
                              !
                            : Nil
                              drop
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "MaybeBox"
                                        [ "a" ]
                                        [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                        , Type.Custom "Nil"
                                        ]
................................................................................
                            : (Box a)
                              !
                            : Nil
                              drop
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ UnionTypeDef emptyRange
                                        "MaybeBox"
                                        [ "a" ]
                                        [ Type.CustomGeneric "Box" [ Type.Generic "a" ]
                                        , Type.Custom "Nil"
                                        ]
................................................................................

                        def: main
                        entry: true
                        : 1 [ 1 + ] apply-to-num
                        """

                    expectedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "apply-to-num"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Int
................................................................................

                        def: main
                        entry: true
                        : 1 [ 1 + ] apply-to-num
                        """

                    expectedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "apply-to-num"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.StackRange "a"
................................................................................
                            defmulti: zero?
                            : Int( value 0 )
                              True
                            else: False
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
................................................................................
                            defmulti: pair?
                            : List( tail List( tail Nil ) )
                              True
                            else: False
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "pair?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
................................................................................
                            defmulti: origo?
                            : Pair( first 0 second 0 )
                              True
                            else: False
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "origo?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
................................................................................
                        source =
                            """
                            def: test
                            : some/module/sample
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ AST.PackageWord emptyRange [ "some", "module" ] "sample" ]
................................................................................
                        source =
                            """
                            def: test
                            : /some/module/sample
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ AST.ExternalWord emptyRange [ "some", "module" ] "sample" ]
................................................................................
                        source =
                            """
                            def: test
                            : internal/sample /some/module/sample
                            """

                        expectedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "test"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ AST.PackageWord emptyRange [ "internal" ] "sample"
................................................................................
                          False
                        else: True
                        """

                    -- The ending source location for most definitions now ends where the next definition beings
                    -- This is not what we want (it includes too much white space), but it'll do for now.
                    expectedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ UnionTypeDef
                                    (SourceLocationRange
                                        (SourceLocation 2 1 1)
                                        (SourceLocation 6 1 32)
                                    )
                                    "Bool"

Modified tests/Test/Parser/Util.elm from [d64d255e03] to [d299e71bfb].

26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
compileRetainLocations str =
    String.unindent str
        |> run


stripLocations : AST -> AST
stripLocations ast =

    { types = Dict.map (\_ t -> stripTypeLocation t) ast.types
    , words = Dict.map (\_ d -> stripWordLocation d) ast.words
    }


stripTypeLocation : TypeDefinition -> TypeDefinition
stripTypeLocation typeDef =
    case typeDef of







>
|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
compileRetainLocations str =
    String.unindent str
        |> run


stripLocations : AST -> AST
stripLocations ast =
    { moduleDefinition = emptyModuleDefinition
    , types = Dict.map (\_ t -> stripTypeLocation t) ast.types
    , words = Dict.map (\_ d -> stripWordLocation d) ast.words
    }


stripTypeLocation : TypeDefinition -> TypeDefinition
stripTypeLocation typeDef =
    case typeDef of

Modified tests/Test/Qualifier.elm from [883b702e60] to [a1f256716f].

18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
..
96
97
98
99
100
101
102

103
104
105
106
107
108
109
110
...
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
...
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
...
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
...
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379
...
437
438
439
440
441
442
443

444
445
446
447
448
449
450
451
...
503
504
505
506
507
508
509

510
511
512
513
514
515
516
517
...
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
...
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
...
867
868
869
870
871
872
873

874
875
876
877
878
879
880
881
....
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
....
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092
....
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1146
....
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208
suite : Test
suite =
    describe "Qualifier"
        [ test "Simple program" <|
            \_ ->
                let
                    unqualifiedAst =

                        { types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , metadata = Metadata.default
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.Integer emptyRange 1
................................................................................
                        }
                in
                QualifierUtil.expectOutput unqualifiedAst expectedAst
        , test "Generic function types" <|
            \_ ->
                let
                    unqualifiedAst =

                        { types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "over"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Generic "a", Type.Generic "b" ]
................................................................................
                        }
                in
                QualifierUtil.expectOutput unqualifiedAst expectedAst
        , test "Union types and multifunctions" <|
            \_ ->
                let
                    unqualifiedAst =

                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "Bool"
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
................................................................................
                in
                QualifierUtil.expectOutput unqualifiedAst expectedAst
        , describe "Quotations"
            [ test "Basic case" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "apply-to-num"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.Int
................................................................................
                            }
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "Quoting a word which hasn't been qualified yet is fine" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "a"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
................................................................................
                            }
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "Quotes within quotes is fine" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
................................................................................
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            ]
        , describe "Pattern matching"
            [ test "Basic example" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef emptyRange
                                        "Bool"
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
................................................................................
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "Generic cases are allowed" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef emptyRange
                                        "Maybe"
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
................................................................................
                    boolUnion =
                        Type.Union
                            [ Type.Custom "True"
                            , Type.Custom "False"
                            ]

                    unqualifiedAst =

                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "Bool"
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
................................................................................
                let
                    qualifiedUsMoneyUnion =
                        [ Type.Custom "/play/test/some/module/Dollar"
                        , Type.Custom "/play/test/some/module/Cent"
                        ]

                    unqualifiedAst =

                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "USMoney"
                                    []
                                    [ Type.Custom "Dollar"
                                    , Type.Custom "Cent"
                                    ]
................................................................................
                let
                    qualifiedUsMoneyUnion =
                        [ Type.Custom "/play/test/some/module/Dollar"
                        , Type.Custom "/play/test/some/module/Cent"
                        ]

                    unqualifiedAst =

                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "USMoney"
                                    []
                                    [ Type.Custom "Dollar"
                                    , Type.Custom "Cent"
                                    ]
................................................................................
                in
                QualifierUtil.expectModuleOutput unqualifiedAst expectedAst
        , describe "Module loading"
            [ test "Detects package reference in simple word" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
................................................................................

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects external reference in simple word" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ExternalWord emptyRange [ "package", "module" ] "sample" ]
................................................................................

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects package reference in multiword" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange Type.Int [ ( "value", AST.LiteralInt 1 ) ]
................................................................................

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects external reference in multiword" <|
                \_ ->
                    let
                        unqualifiedAst =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange Type.Int [ ( "value", AST.LiteralInt 1 ) ]







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







 







>
|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
...
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
...
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
....
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
....
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
....
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
....
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
suite : Test
suite =
    describe "Qualifier"
        [ test "Simple program" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , metadata = Metadata.default
                                  , implementation =
                                        AST.SoloImpl
                                            [ AST.Integer emptyRange 1
................................................................................
                        }
                in
                QualifierUtil.expectOutput unqualifiedAst expectedAst
        , test "Generic function types" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types = Dict.empty
                        , words =
                            Dict.fromListBy .name
                                [ { name = "over"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Generic "a", Type.Generic "b" ]
................................................................................
                        }
                in
                QualifierUtil.expectOutput unqualifiedAst expectedAst
        , test "Union types and multifunctions" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "Bool"
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
................................................................................
                in
                QualifierUtil.expectOutput unqualifiedAst expectedAst
        , describe "Quotations"
            [ test "Basic case" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "apply-to-num"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType
                                                    [ Type.Int
................................................................................
                            }
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "Quoting a word which hasn't been qualified yet is fine" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "a"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
................................................................................
                            }
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "Quotes within quotes is fine" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
................................................................................
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            ]
        , describe "Pattern matching"
            [ test "Basic example" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef emptyRange
                                        "Bool"
                                        []
                                        [ Type.Custom "True"
                                        , Type.Custom "False"
                                        ]
................................................................................
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "Generic cases are allowed" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef emptyRange
                                        "Maybe"
                                        [ "a" ]
                                        [ Type.Generic "a"
                                        , Type.Custom "Nothing"
                                        ]
................................................................................
                    boolUnion =
                        Type.Union
                            [ Type.Custom "True"
                            , Type.Custom "False"
                            ]

                    unqualifiedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "Bool"
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
................................................................................
                let
                    qualifiedUsMoneyUnion =
                        [ Type.Custom "/play/test/some/module/Dollar"
                        , Type.Custom "/play/test/some/module/Cent"
                        ]

                    unqualifiedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "USMoney"
                                    []
                                    [ Type.Custom "Dollar"
                                    , Type.Custom "Cent"
                                    ]
................................................................................
                let
                    qualifiedUsMoneyUnion =
                        [ Type.Custom "/play/test/some/module/Dollar"
                        , Type.Custom "/play/test/some/module/Cent"
                        ]

                    unqualifiedAst =
                        { moduleDefinition = AST.emptyModuleDefinition
                        , types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ AST.UnionTypeDef emptyRange
                                    "USMoney"
                                    []
                                    [ Type.Custom "Dollar"
                                    , Type.Custom "Cent"
                                    ]
................................................................................
                in
                QualifierUtil.expectModuleOutput unqualifiedAst expectedAst
        , describe "Module loading"
            [ test "Detects package reference in simple word" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
................................................................................

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects external reference in simple word" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ExternalWord emptyRange [ "package", "module" ] "sample" ]
................................................................................

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects package reference in multiword" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange Type.Int [ ( "value", AST.LiteralInt 1 ) ]
................................................................................

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects external reference in multiword" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange Type.Int [ ( "value", AST.LiteralInt 1 ) ]

Modified tests/Test/Qualifier/Error.elm from [42c36a26bb] to [22090dd3ba].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
..
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
..
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
...
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
...
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
suite =
    describe "Qualifier errors"
        [ describe "No such reference" <|
            [ test "Word" <|
                \_ ->
                    let
                        ast =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "inc"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
................................................................................
                            }
                    in
                    checkForError (noSuchWordReferenceError "dec") ast
            , test "External" <|
                \_ ->
                    let
                        ast =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
................................................................................
                            }
                    in
                    checkForError (noSuchWordReferenceError "/external/module/inc") ast
            , test "Type" <|
                \_ ->
                    let
                        ast =

                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "inc"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Ints" ] [ Type.Int ]
                                      , implementation =
................................................................................
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Ints") ast
            , test "Wrong reference within union definition" <|
                \_ ->
                    let
                        ast =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef
                                        emptyRange
                                        "USMoney"
                                        []
                                        [ Type.Custom "Dollar"
                                        , Type.Custom "Cent"
................................................................................
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Cent") ast
            , test "Wrong reference within custom type definition" <|
                \_ ->
                    let
                        ast =

                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.CustomTypeDef
                                        emptyRange
                                        "BoxWrapper"
                                        []
                                        [ ( "box", Type.Custom "Box" ) ]
                                    ]







>
|







 







>
|







 







>
|







 







>
|







 







>
|







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
suite =
    describe "Qualifier errors"
        [ describe "No such reference" <|
            [ test "Word" <|
                \_ ->
                    let
                        ast =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "inc"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
................................................................................
                            }
                    in
                    checkForError (noSuchWordReferenceError "dec") ast
            , test "External" <|
                \_ ->
                    let
                        ast =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
................................................................................
                            }
                    in
                    checkForError (noSuchWordReferenceError "/external/module/inc") ast
            , test "Type" <|
                \_ ->
                    let
                        ast =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "inc"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withType [ Type.Custom "Ints" ] [ Type.Int ]
                                      , implementation =
................................................................................
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Ints") ast
            , test "Wrong reference within union definition" <|
                \_ ->
                    let
                        ast =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.UnionTypeDef
                                        emptyRange
                                        "USMoney"
                                        []
                                        [ Type.Custom "Dollar"
                                        , Type.Custom "Cent"
................................................................................
                            }
                    in
                    checkForError (noSuchTypeReferenceError "Cent") ast
            , test "Wrong reference within custom type definition" <|
                \_ ->
                    let
                        ast =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ AST.CustomTypeDef
                                        emptyRange
                                        "BoxWrapper"
                                        []
                                        [ ( "box", Type.Custom "Box" ) ]
                                    ]