Stabel

Check-in [c7f7dbae5f]
Login
Overview
Comment:Add source refs to parser problems.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c7f7dbae5f12fcb388b9346c01ffab26f48116f13ce5c04eff45c8d5d92fb569
User & Date: robin.hansen on 2021-08-06 15:17:48
Other Links: manifest | tags
Context
2021-08-06
15:32
Fix all issues reported by elm-review. check-in: ed510a2c32 user: robin.hansen tags: trunk, releases, v0.2.1
15:17
Add source refs to parser problems. check-in: c7f7dbae5f user: robin.hansen tags: trunk
09:39
Fixed known bugs in PackageLoader. check-in: c1e42b8f60 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/PackageLoader.elm from [be88572e7f] to [f78779f213].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
...
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | UnknownMessageForCompile String
    | NoExposedModulesInRootProject
    | ModuleNotFound String
    | ParserError String (List (DeadEnd ParserProblem.Context ParserProblem.Problem))
    | QualifierError String (List QualifierProblem.Problem)
    | InternalError String


problemToString : Problem -> String
problemToString problem =
    case problem of
................................................................................

        NoExposedModulesInRootProject ->
            "No exposed modules in root project"

        ModuleNotFound mod ->
            "Failed to locate module '" ++ mod ++ "' on disk"

        ParserError source errs ->
            errs
                |> List.map (ParserProblem.toString source)
                |> String.join "\n\n"

        QualifierError source errs ->
            errs
                |> List.map (QualifierProblem.toString source)
                |> String.join "\n\n"

................................................................................
                    path ++ "/" ++ fileName

                possibleModuleInfo =
                    Dict.get fullPath state.filePathToModule
            in
            case ( possibleModuleInfo, Parser.run fullPath content ) of
                ( _, Err parserError ) ->
                    Failed <| ParserError content parserError

                ( Just ( packageName, moduleName ), Ok parserAst ) ->
                    let
                        fullModuleName =
                            absoluteModuleName packageName moduleName

                        updatedParsedModules =







|







 







|

|







 







|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
...
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | UnknownMessageForCompile String
    | NoExposedModulesInRootProject
    | ModuleNotFound String
    | ParserError String String (List (DeadEnd ParserProblem.Context ParserProblem.Problem))
    | QualifierError String (List QualifierProblem.Problem)
    | InternalError String


problemToString : Problem -> String
problemToString problem =
    case problem of
................................................................................

        NoExposedModulesInRootProject ->
            "No exposed modules in root project"

        ModuleNotFound mod ->
            "Failed to locate module '" ++ mod ++ "' on disk"

        ParserError ref source errs ->
            errs
                |> List.map (ParserProblem.toString ref source)
                |> String.join "\n\n"

        QualifierError source errs ->
            errs
                |> List.map (QualifierProblem.toString source)
                |> String.join "\n\n"

................................................................................
                    path ++ "/" ++ fileName

                possibleModuleInfo =
                    Dict.get fullPath state.filePathToModule
            in
            case ( possibleModuleInfo, Parser.run fullPath content ) of
                ( _, Err parserError ) ->
                    Failed <| ParserError fullPath content parserError

                ( Just ( packageName, moduleName ), Ok parserAst ) ->
                    let
                        fullModuleName =
                            absoluteModuleName packageName moduleName

                        updatedParsedModules =

Modified src/Stabel/Parser/Problem.elm from [4432596ff2] to [de8ce45cbd].

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
    | TypeAlreadyDefined String SourceLocationRange
    | UnknownMetadata String
    | InvalidModulePath String
    | ModuleIsEmpty
    | BadDefinition String


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

        lineOfProblem =
            deadEnd.row

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

        codeBlock =
            extractFromString source startLoc endLoc

        problemDetail =
            problemToString source deadEnd.problem
    in

    [ contextExplination
    , codeBlock
    , problemDetail
    ]
        |> List.filter (not << String.isEmpty)
        |> String.join "\n\n"









|
|







 







>
|







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    | TypeAlreadyDefined String SourceLocationRange
    | UnknownMetadata String
    | InvalidModulePath String
    | ModuleIsEmpty
    | BadDefinition String


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

        lineOfProblem =
            deadEnd.row

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

        codeBlock =
            extractFromString source startLoc endLoc

        problemDetail =
            problemToString source deadEnd.problem
    in
    [ ">> " ++ sourceRef
    , contextExplination
    , codeBlock
    , problemDetail
    ]
        |> List.filter (not << String.isEmpty)
        |> String.join "\n\n"


Modified src/TestCompiler.elm from [1362aa673b] to [e04edc62d9].

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
185
186
187
188
189
190
191


192


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
296
297
298
299
300
301
302








303
304
305
306
307
308
309

                Err errmsg ->
                    compileFailed errmsg


compileString : CompileStringOpts -> Result String Wasm.Module
compileString opts =
    case Parser.run "test" opts.sourceCode of
        Err parserErrors ->
            parserErrors
                |> List.map (Tuple.pair opts.sourceCode)
                |> formatErrors ParserProblem.toString

        Ok ast ->
            let
                qualifierResult =
                    Qualifier.run
                        { packageName = ""
                        , modulePath = ""
................................................................................
    let
        parserResult =
            opts.modules
                |> List.map parseModuleSource
                |> Result.combine

        parseModuleSource mod =


            case Parser.run (mod.package ++ mod.modulePath) mod.source of


                Err errs ->
                    Err ( mod.source, errs )

                Ok ast ->
                    Ok ( mod.package, mod.modulePath, ast )

        sourceDict =
            opts.modules
                |> List.map (\mod -> ( mod.package ++ mod.modulePath, mod.source ))
                |> Dict.fromList
    in
    case parserResult of
        Err ( sourceCode, errs ) ->
            errs
                |> List.map (Tuple.pair sourceCode)
                |> formatErrors ParserProblem.toString

        Ok withAst ->
            let
                initialConfig =
                    { packageName = ""
                    , modulePath = ""
                    , ast =
................................................................................
                    { updatedConfig
                        | inProgressAST = updatedInProgressAst
                        , externalModules = Dict.insert ("/" ++ modulePath) packageName updatedConfig.externalModules
                    }
            in
            ( problems, configWithQualifiedAst )










formatErrors : (String -> a -> String) -> List ( String, a ) -> Result String b
formatErrors fn problems =
    problems
        |> List.map (\( source, err ) -> fn source err)
        |> String.join "\n\n"
        |> Err







|


|
|







 







>
>
|
>
>

|










|

|
|







 







>
>
>
>
>
>
>
>







129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

                Err errmsg ->
                    compileFailed errmsg


compileString : CompileStringOpts -> Result String Wasm.Module
compileString opts =
    case Parser.run "<buffer>" opts.sourceCode of
        Err parserErrors ->
            parserErrors
                |> List.map (\e -> ( "<buffer>", opts.sourceCode, e ))
                |> formatParserErrors ParserProblem.toString

        Ok ast ->
            let
                qualifierResult =
                    Qualifier.run
                        { packageName = ""
                        , modulePath = ""
................................................................................
    let
        parserResult =
            opts.modules
                |> List.map parseModuleSource
                |> Result.combine

        parseModuleSource mod =
            let
                fullPath =
                    mod.package ++ mod.modulePath
            in
            case Parser.run fullPath mod.source of
                Err errs ->
                    Err ( fullPath, mod.source, errs )

                Ok ast ->
                    Ok ( mod.package, mod.modulePath, ast )

        sourceDict =
            opts.modules
                |> List.map (\mod -> ( mod.package ++ mod.modulePath, mod.source ))
                |> Dict.fromList
    in
    case parserResult of
        Err ( ref, sourceCode, errs ) ->
            errs
                |> List.map (\e -> ( ref, sourceCode, e ))
                |> formatParserErrors ParserProblem.toString

        Ok withAst ->
            let
                initialConfig =
                    { packageName = ""
                    , modulePath = ""
                    , ast =
................................................................................
                    { updatedConfig
                        | inProgressAST = updatedInProgressAst
                        , externalModules = Dict.insert ("/" ++ modulePath) packageName updatedConfig.externalModules
                    }
            in
            ( problems, configWithQualifiedAst )


formatParserErrors : (String -> String -> a -> String) -> List ( String, String, a ) -> Result String b
formatParserErrors fn problems =
    problems
        |> List.map (\( ref, source, err ) -> fn ref source err)
        |> String.join "\n\n"
        |> Err


formatErrors : (String -> a -> String) -> List ( String, a ) -> Result String b
formatErrors fn problems =
    problems
        |> List.map (\( source, err ) -> fn source err)
        |> String.join "\n\n"
        |> Err