Stabel

Check-in [b9aa49ac53]
Login
Overview
Comment:Add more contexts.
Timelines: family | ancestors | descendants | both | integer-syntax-improvements
Files: files | file ages | folders
SHA3-256: b9aa49ac5370c8911249ef76e1214425c544ccbb4cf546da2ce13ae14a2c4985
User & Date: robin.hansen on 2021-09-13 18:37:26
Other Links: branch diff | manifest | tags
Context
2021-09-13
19:20
Allow underscores to group large integers. check-in: df946f0acc user: robin.hansen tags: integer-syntax-improvements
18:37
Add more contexts. check-in: b9aa49ac53 user: robin.hansen tags: integer-syntax-improvements
18:27
Fail integer parsing when it contains an non-digit character. check-in: 99cbabf9ff user: robin.hansen tags: integer-syntax-improvements
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Parser.elm from [d93f30a5a3] to [f7bb614a2e].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
...
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
...
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
....
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
....
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
....
1247
1248
1249
1250
1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268

import Dict exposing (Dict)
import Dict.Extra as Dict
import Parser.Advanced as Parser exposing ((|.), (|=), Token(..))
import Set exposing (Set)
import Stabel.Parser.AssociatedFunctionSignature as AssociatedFunctionSignature exposing (AssociatedFunctionSignature)
import Stabel.Parser.ModuleDefinition as ModuleDefinition exposing (ModuleDefinition)
import Stabel.Parser.Problem as Problem exposing (..)
import Stabel.Parser.SourceLocation exposing (SourceLocation, SourceLocationRange)
import Stabel.Parser.Type
    exposing
        ( FunctionSignature
        , PossiblyQualifiedType(..)
        , PossiblyQualifiedTypeOrStackRange(..)
        )
................................................................................
                        if isNegative then
                            num * -1

                        else
                            num

                Nothing ->
                    Parser.problem ExpectedInt
    in

    Parser.succeed Tuple.pair
        |= Parser.variable
            { start = Char.isDigit
            , inner = Char.isDigit
            , reserved = Set.empty
            , expecting = ExpectedInt
            }
        |= Parser.oneOf
            [ Parser.succeed True
                |. Parser.symbol (Token "-" UnknownError)
            , Parser.succeed False
            ]
        |. Parser.oneOf
            [ Parser.chompIf (\c -> Set.member c whitespaceChars) ExpectedWhitespace
            , Parser.succeed ()
                |. Parser.end ExpectedEndOfFile
            ]
        |> Parser.andThen helper



sourceLocationParser : Parser SourceLocation
sourceLocationParser =
    Parser.succeed SourceLocation
        |= Parser.getRow
        |= Parser.getCol
................................................................................
textParser =
    Parser.chompWhile (\c -> not <| Set.member c whitespaceChars)
        |> Parser.getChompedString


stringParser : Parser String
stringParser =

    Parser.oneOf
        [ Parser.succeed stripMultilineStringWhitespace
            |. Parser.symbol (Token "\"\"\"" UnknownError)
            |= Parser.loop (Just "") multilineStringParserLoop
        , Parser.succeed identity
            |. Parser.symbol (Token "\"" UnknownError)
            |= Parser.loop (Just "") stringParserLoop
        ]



stringParserLoop : Maybe String -> Parser (Parser.Step (Maybe String) String)
stringParserLoop maybeStr =
    case maybeStr of
        Nothing ->
            -- Work around bug in elm/parser
................................................................................
            ]
        |. Parser.end ExpectedEndOfFile
        |> Parser.andThen checkIfEmpty


moduleDefinitionParser : Parser ModuleDefinition
moduleDefinitionParser =
    Parser.inContext ModuleDefinition
        (Parser.succeed identity
            |. Parser.keyword (Token "defmodule:" UnknownError)
            |. noiseParser
            |= Parser.loop ModuleDefinition.emptyDefinition moduleDefinitionMetaParser
            |> Parser.map ModuleDefinition.Defined
        )


moduleDefinitionMetaParser :
    ModuleDefinition.Definition
    -> Parser (Parser.Step ModuleDefinition.Definition ModuleDefinition.Definition)
moduleDefinitionMetaParser def =
    Parser.oneOf
        [ Parser.inContext AliasKeyword
            (Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
            )
        , Parser.inContext ImportKeyword
            (Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= Parser.loop [] symbolImplListParser
                |. noiseParser
            )
        , Parser.inContext ExposingKeyword
            (Parser.succeed (\exposings -> Parser.Loop { def | exposes = exposings })
                |. Parser.keyword (Token "exposing:" UnknownError)
                |. noiseParser
                |= (Parser.loop [] symbolImplListParser |> Parser.map Set.fromList)
                |. noiseParser
            )
        , Parser.succeed (\str -> Parser.Loop { def | documentation = str })
................................................................................
                    |= Parser.loop emptyDef functionMetadataParser
                    |= sourceLocationParser


functionMetadataParser : FunctionDefinition -> Parser (Parser.Step FunctionDefinition FunctionDefinition)
functionMetadataParser def =
    Parser.oneOf
        [ Parser.inContext TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
        , Parser.inContext ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= Parser.loop [] symbolImplListParser
                |. noiseParser
        , Parser.inContext ImplementationKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = SoloImpl impl })
                |. Parser.keyword (Token ":" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
................................................................................
                MultiImpl whens _ ->
                    MultiImpl whens impl

                SoloImpl _ ->
                    MultiImpl [] impl
    in
    Parser.oneOf
        [ Parser.inContext TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext ElseKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = setDefaultImpl impl })
                |. Parser.keyword (Token "else:" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.inContext AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
        , Parser.inContext ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= Parser.loop [] symbolImplListParser
                |. noiseParser
        , Parser.inContext ImplementationKeyword <|
            Parser.succeed (\type_ impl -> Parser.Loop { def | implementation = addWhenImpl ( type_, impl ) })
                |. Parser.keyword (Token ":" UnknownError)
                |. noiseParser
                |= typeMatchParser
                |. noiseParser
                |= implementationParser
        , Parser.succeed UnknownMetadata
................................................................................
                            setter.name
                            setter.sourceLocationRange

                ( Nothing, Nothing ) ->
                    Parser.succeed name
    in
    Parser.oneOf
        [ Parser.inContext MemberKeyword <|
            Parser.succeed (\name type_ -> Parser.Loop { result | members = ( name, type_ ) :: result.members })
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= Parser.andThen alreadyDefinedCheck symbolParser
                |. noiseParser
                |= typeRefParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { result | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
................................................................................


unionTypeMemberParser :
    UnionMembersParserResult
    -> Parser (Parser.Step UnionMembersParserResult UnionMembersParserResult)
unionTypeMemberParser result =
    Parser.oneOf
        [ Parser.inContext MemberKeyword <|
            Parser.succeed (\type_ -> Parser.Loop { result | types = type_ :: result.types })
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= typeRefParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { result | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
................................................................................
            |= 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 (\startLoc strContent endLoc -> Parser.Loop (StringLiteral (SourceLocationRange startLoc endLoc) strContent :: nodes))
            |= sourceLocationParser
            |= stringParser
            -- stringParser chomps the final "
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse nodes))







|







 







|

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







 







>
|
|
|
|
|
|
|
|
>







 







|













|








|








|







 







|




|





|







|







|







 







|




|





|




|







|







|







 







|






|







 







|




|







 







>
|
|
|
|
|
|
|
|
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
...
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
...
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
....
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
....
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
....
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274

import Dict exposing (Dict)
import Dict.Extra as Dict
import Parser.Advanced as Parser exposing ((|.), (|=), Token(..))
import Set exposing (Set)
import Stabel.Parser.AssociatedFunctionSignature as AssociatedFunctionSignature exposing (AssociatedFunctionSignature)
import Stabel.Parser.ModuleDefinition as ModuleDefinition exposing (ModuleDefinition)
import Stabel.Parser.Problem as Problem exposing (Context, Problem(..))
import Stabel.Parser.SourceLocation exposing (SourceLocation, SourceLocationRange)
import Stabel.Parser.Type
    exposing
        ( FunctionSignature
        , PossiblyQualifiedType(..)
        , PossiblyQualifiedTypeOrStackRange(..)
        )
................................................................................
                        if isNegative then
                            num * -1

                        else
                            num

                Nothing ->
                    Parser.problem Problem.ExpectedInt
    in
    Parser.inContext Problem.IntegerLiteral
        (Parser.succeed Tuple.pair
            |= Parser.variable
                { start = Char.isDigit
                , inner = Char.isDigit
                , reserved = Set.empty
                , expecting = ExpectedInt
                }
            |= Parser.oneOf
                [ Parser.succeed True
                    |. Parser.symbol (Token "-" UnknownError)
                , Parser.succeed False
                ]
            |. Parser.oneOf
                [ Parser.chompIf (\c -> Set.member c whitespaceChars) ExpectedWhitespace
                , Parser.succeed ()
                    |. Parser.end ExpectedEndOfFile
                ]
            |> Parser.andThen helper
        )


sourceLocationParser : Parser SourceLocation
sourceLocationParser =
    Parser.succeed SourceLocation
        |= Parser.getRow
        |= Parser.getCol
................................................................................
textParser =
    Parser.chompWhile (\c -> not <| Set.member c whitespaceChars)
        |> Parser.getChompedString


stringParser : Parser String
stringParser =
    Parser.inContext Problem.StringLiteral
        (Parser.oneOf
            [ Parser.succeed stripMultilineStringWhitespace
                |. Parser.symbol (Token "\"\"\"" UnknownError)
                |= Parser.loop (Just "") multilineStringParserLoop
            , Parser.succeed identity
                |. Parser.symbol (Token "\"" UnknownError)
                |= Parser.loop (Just "") stringParserLoop
            ]
        )


stringParserLoop : Maybe String -> Parser (Parser.Step (Maybe String) String)
stringParserLoop maybeStr =
    case maybeStr of
        Nothing ->
            -- Work around bug in elm/parser
................................................................................
            ]
        |. Parser.end ExpectedEndOfFile
        |> Parser.andThen checkIfEmpty


moduleDefinitionParser : Parser ModuleDefinition
moduleDefinitionParser =
    Parser.inContext Problem.ModuleDefinition
        (Parser.succeed identity
            |. Parser.keyword (Token "defmodule:" UnknownError)
            |. noiseParser
            |= Parser.loop ModuleDefinition.emptyDefinition moduleDefinitionMetaParser
            |> Parser.map ModuleDefinition.Defined
        )


moduleDefinitionMetaParser :
    ModuleDefinition.Definition
    -> Parser (Parser.Step ModuleDefinition.Definition ModuleDefinition.Definition)
moduleDefinitionMetaParser def =
    Parser.oneOf
        [ Parser.inContext Problem.AliasKeyword
            (Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
            )
        , Parser.inContext Problem.ImportKeyword
            (Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= Parser.loop [] symbolImplListParser
                |. noiseParser
            )
        , Parser.inContext Problem.ExposingKeyword
            (Parser.succeed (\exposings -> Parser.Loop { def | exposes = exposings })
                |. Parser.keyword (Token "exposing:" UnknownError)
                |. noiseParser
                |= (Parser.loop [] symbolImplListParser |> Parser.map Set.fromList)
                |. noiseParser
            )
        , Parser.succeed (\str -> Parser.Loop { def | documentation = str })
................................................................................
                    |= Parser.loop emptyDef functionMetadataParser
                    |= sourceLocationParser


functionMetadataParser : FunctionDefinition -> Parser (Parser.Step FunctionDefinition FunctionDefinition)
functionMetadataParser def =
    Parser.oneOf
        [ Parser.inContext Problem.TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser
        , Parser.inContext Problem.DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext Problem.AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
        , Parser.inContext Problem.ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= Parser.loop [] symbolImplListParser
                |. noiseParser
        , Parser.inContext Problem.ImplementationKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = SoloImpl impl })
                |. Parser.keyword (Token ":" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
................................................................................
                MultiImpl whens _ ->
                    MultiImpl whens impl

                SoloImpl _ ->
                    MultiImpl [] impl
    in
    Parser.oneOf
        [ Parser.inContext Problem.TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser
        , Parser.inContext Problem.DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext Problem.ElseKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = setDefaultImpl impl })
                |. Parser.keyword (Token "else:" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.inContext Problem.AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
        , Parser.inContext Problem.ImportKeyword <|
            Parser.succeed (\mod vals -> Parser.Loop { def | imports = Dict.insert mod vals def.imports })
                |. Parser.keyword (Token "import:" UnknownError)
                |. noiseParser
                |= modulePathStringParser
                |. noiseParser
                |= Parser.loop [] symbolImplListParser
                |. noiseParser
        , Parser.inContext Problem.ImplementationKeyword <|
            Parser.succeed (\type_ impl -> Parser.Loop { def | implementation = addWhenImpl ( type_, impl ) })
                |. Parser.keyword (Token ":" UnknownError)
                |. noiseParser
                |= typeMatchParser
                |. noiseParser
                |= implementationParser
        , Parser.succeed UnknownMetadata
................................................................................
                            setter.name
                            setter.sourceLocationRange

                ( Nothing, Nothing ) ->
                    Parser.succeed name
    in
    Parser.oneOf
        [ Parser.inContext Problem.MemberKeyword <|
            Parser.succeed (\name type_ -> Parser.Loop { result | members = ( name, type_ ) :: result.members })
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= Parser.andThen alreadyDefinedCheck symbolParser
                |. noiseParser
                |= typeRefParser
        , Parser.inContext Problem.DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { result | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
................................................................................


unionTypeMemberParser :
    UnionMembersParserResult
    -> Parser (Parser.Step UnionMembersParserResult UnionMembersParserResult)
unionTypeMemberParser result =
    Parser.oneOf
        [ Parser.inContext Problem.MemberKeyword <|
            Parser.succeed (\type_ -> Parser.Loop { result | types = type_ :: result.types })
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= typeRefParser
        , Parser.inContext Problem.DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { result | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
................................................................................
            |= sourceLocationParser
            |. Parser.symbol (Token "[" ExpectedLeftBracket)
            |. noiseParser
            |= implementationParser
            |. Parser.symbol (Token "]" ExpectedRightBracket)
            |= sourceLocationParser
            |. noiseParser
        , Parser.inContext Problem.ArrayLiteral
            (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 (\startLoc strContent endLoc -> Parser.Loop (StringLiteral (SourceLocationRange startLoc endLoc) strContent :: nodes))
            |= sourceLocationParser
            |= stringParser
            -- stringParser chomps the final "
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse nodes))

Modified src/Stabel/Parser/Problem.elm from [c2792cae36] to [f7612d9509].

23
24
25
26
27
28
29



30
31
32
33
34
35
36
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
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
...
150
151
152
153
154
155
156









157
158
159
160
161
162
163
    | ImportKeyword
    | ExposingKeyword
    | TypeKeyword
    | DocKeyword
    | MemberKeyword
    | ImplementationKeyword
    | ElseKeyword





type Problem
    = ExpectedInt
    | ExpectedSymbol
    | ExpectedMetadata
    | ExpectedGeneric
................................................................................
    | StringNotTerminated


toString : String -> String -> DeadEnd Context Problem -> String
toString sourceRef source deadEnd =
    let
        contextExplination =
            contextStackExplination deadEnd

        lineOfProblem =
            deadEnd.row

        lineOfContext =
            firstContextRow deadEnd
                |> Maybe.withDefault lineOfProblem
................................................................................
    , codeBlock
    , problemDetail
    ]
        |> List.filter (not << String.isEmpty)
        |> String.join "\n\n"


contextStackExplination : DeadEnd Context Problem -> String
contextStackExplination deadEnd =
    case deadEnd.contextStack of



        contextFrame :: [] ->
            "I came across a problem while parsing the "
                ++ contextToString contextFrame.context

        contextFrame1 :: contextFrame2 :: _ ->
            "I came across a problem while parsing the "
                ++ contextToString contextFrame1.context
                ++ " of the "
                ++ contextToString contextFrame2.context

        _ ->
            "I came across a problem"



contextToString : Context -> String
contextToString context =
    case context of
        ModuleDefinition ->
            "module definition"
................................................................................
            "member"

        ImplementationKeyword ->
            "implementation"

        ElseKeyword ->
            "else branch"











firstContextRow : DeadEnd Context Problem -> Maybe Int
firstContextRow deadEnd =
    case deadEnd.contextStack of
        frame :: _ ->
            case frame.context of







>
>
>







 







|







 







|
|
|
>
>
>




|
|
|
|
|
|
|
|
>







 







>
>
>
>
>
>
>
>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
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
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    | ImportKeyword
    | ExposingKeyword
    | TypeKeyword
    | DocKeyword
    | MemberKeyword
    | ImplementationKeyword
    | ElseKeyword
    | IntegerLiteral
    | ArrayLiteral
    | StringLiteral


type Problem
    = ExpectedInt
    | ExpectedSymbol
    | ExpectedMetadata
    | ExpectedGeneric
................................................................................
    | StringNotTerminated


toString : String -> String -> DeadEnd Context Problem -> String
toString sourceRef source deadEnd =
    let
        contextExplination =
            contextStackExplination deadEnd.contextStack

        lineOfProblem =
            deadEnd.row

        lineOfContext =
            firstContextRow deadEnd
                |> Maybe.withDefault lineOfProblem
................................................................................
    , codeBlock
    , problemDetail
    ]
        |> List.filter (not << String.isEmpty)
        |> String.join "\n\n"


contextStackExplination : List { row : Int, col : Int, context : Context } -> String
contextStackExplination contextStack =
    case contextStack of
        [] ->
            "I came across a problem"

        contextFrame :: [] ->
            "I came across a problem while parsing the "
                ++ contextToString contextFrame.context

        _ ->
            let
                contextStrings =
                    contextStack
                        |> List.map (.context >> contextToString)
                        |> String.join " of the "
            in
            "I came across a problem while parsing the "
                ++ contextStrings


contextToString : Context -> String
contextToString context =
    case context of
        ModuleDefinition ->
            "module definition"
................................................................................
            "member"

        ImplementationKeyword ->
            "implementation"

        ElseKeyword ->
            "else branch"

        IntegerLiteral ->
            "integer"

        ArrayLiteral ->
            "array"

        StringLiteral ->
            "string"


firstContextRow : DeadEnd Context Problem -> Maybe Int
firstContextRow deadEnd =
    case deadEnd.contextStack of
        frame :: _ ->
            case frame.context of