Play

Check-in [5ff3a4c6ce]
Login
Overview
Comment:Added new Elm module containing CLI related functionality. This will be compiled toa bin/compiler.js bundle.
Timelines: family | ancestors | descendants | both | cli
Files: files | file ages | folders
SHA3-256: 5ff3a4c6cef2a2e4a7d01c8025e0634e287d86bf89924cf7078ae756dc4736a1
User & Date: robin.hansen on 2021-03-30 09:29:35
Other Links: branch diff | manifest | tags
Context
2021-03-30
10:04
Load and initialize Elm code in bin/cli.js check-in: cab10c643e user: robin.hansen tags: cli
09:29
Added new Elm module containing CLI related functionality. This will be compiled toa bin/compiler.js... check-in: 5ff3a4c6ce user: robin.hansen tags: cli
09:15
Added initial workings of a cli program. check-in: 66257248df user: robin.hansen tags: cli
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified package.json from [fe6c78cc73] to [895cd12b4c].

13
14
15
16
17
18
19
20

21
22
23
24
25
    "strip-indent": "^3.0.0",
    "wabt": "^1.0.20"
  },
  "scripts": {
    "test": "npm run test:elm && npm run test:wasm",
    "test:elm": "elm-test",
    "test:elm:watch": "elm-test --watch",
    "test:wasm": "elm make src/Main.elm --output wasm_tests/compiler.js && sed -i '' \"s/console.warn\\(.*\\);/\\/*&*\\//g\" wasm_tests/compiler.js && jest"

  },
  "bin": {
    "play": "bin/cli.js"
  }
}







|
>





13
14
15
16
17
18
19
20
21
22
23
24
25
26
    "strip-indent": "^3.0.0",
    "wabt": "^1.0.20"
  },
  "scripts": {
    "test": "npm run test:elm && npm run test:wasm",
    "test:elm": "elm-test",
    "test:elm:watch": "elm-test --watch",
    "test:wasm": "elm make src/Main.elm --output wasm_tests/compiler.js && sed -i '' \"s/console.warn\\(.*\\);/\\/*&*\\//g\" wasm_tests/compiler.js && jest",
    "build": "elm make src/CLI.elm --output bin/compiler.js && sed -i '' \"s/console.warn\\(.*\\);/\\/*&*\\//g\" bin/compiler.js"
  },
  "bin": {
    "play": "bin/cli.js"
  }
}

Added src/CLI.elm version [1457701d5b].

































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
port module CLI exposing (main)

import Platform exposing (Program)
import Play.Codegen as Codegen
import Play.Parser as Parser
import Play.Parser.Problem as ParserProblem
import Play.Qualifier as Qualifier
import Play.Qualifier.Problem as QualifierProblem
import Play.TypeChecker as TypeChecker
import Play.TypeChecker.Problem as TypeCheckerProblem
import Wasm


type alias Model =
    ()


type Msg
    = CompileString String


main : Program () Model Msg
main =
    Platform.worker
        { init = init
        , update = update
        , subscriptions = subscriptions
        }


init : () -> ( Model, Cmd Msg )
init _ =
    ( ()
    , Cmd.none
    )


update : Msg -> Model -> ( Model, Cmd Msg )
update msg _ =
    case msg of
        CompileString sourceCode ->
            case compile sourceCode of
                Ok wasm ->
                    ( ()
                    , compileFinished ( True, wasm )
                    )

                Err errmsg ->
                    ( ()
                    , compileFinished ( False, "Compilation failed:\n\n" ++ errmsg )
                    )


compile : String -> Result String String
compile sourceCode =
    case Parser.run sourceCode of
        Err parserErrors ->
            formatErrors (ParserProblem.toString sourceCode) parserErrors

        Ok ast ->
            Ok "It worked!"


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


subscriptions : Model -> Sub Msg
subscriptions _ =
    compileString CompileString


port compileString : (String -> msg) -> Sub msg


port compileFinished : ( Bool, String ) -> Cmd msg