2017-01-07 20:29:26 +03:00
|
|
|
module Main exposing (main)
|
|
|
|
|
2017-01-07 22:58:41 +03:00
|
|
|
import Result
|
2017-01-07 20:29:26 +03:00
|
|
|
import Ast
|
2017-01-20 00:27:11 +03:00
|
|
|
import Ast as L
|
2017-01-07 20:29:26 +03:00
|
|
|
import Ast.Expression exposing (..)
|
|
|
|
import Ast.Statement exposing (..)
|
2017-01-07 22:58:41 +03:00
|
|
|
import Html exposing (Html, p, div, li, ul, pre, textarea, text)
|
2017-01-16 00:57:03 +03:00
|
|
|
import Html.Attributes exposing (id, class)
|
2017-01-07 20:29:26 +03:00
|
|
|
import Html.Events exposing (..)
|
|
|
|
import Json.Decode as JD
|
2017-01-16 01:24:37 +03:00
|
|
|
import Types
|
2017-01-08 13:44:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- Rules
|
|
|
|
|
|
|
|
import NoDebug
|
2017-01-20 00:27:11 +03:00
|
|
|
import NoDuplicateImports
|
2017-01-08 13:44:31 +03:00
|
|
|
import NoExposingEverything
|
2017-01-20 00:27:11 +03:00
|
|
|
import NoImportingEverything
|
|
|
|
import NoUnannotatedFunction
|
2017-01-17 01:32:06 +03:00
|
|
|
import NoUnusedVariables
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= Replace String
|
|
|
|
|
|
|
|
|
|
|
|
init : String
|
|
|
|
init =
|
2017-01-19 23:02:21 +03:00
|
|
|
"""module Main exposing (f)
|
|
|
|
|
|
|
|
import Html
|
2017-01-20 00:27:11 +03:00
|
|
|
import Html exposing (..)
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
f : Int -> Int
|
2017-01-07 23:17:01 +03:00
|
|
|
f x = x Debug.log 1
|
2017-01-07 20:29:26 +03:00
|
|
|
|
2017-01-19 23:02:21 +03:00
|
|
|
g n = n + 1
|
2017-01-07 20:29:26 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> String -> String
|
|
|
|
update action model =
|
|
|
|
case action of
|
|
|
|
Replace m ->
|
|
|
|
m
|
|
|
|
|
|
|
|
|
|
|
|
withChild : a -> List (Html Msg) -> Html Msg
|
|
|
|
withChild title children =
|
|
|
|
li []
|
|
|
|
[ pre [] [ text <| toString title ]
|
|
|
|
, ul [] children
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
expression : Expression -> Html Msg
|
|
|
|
expression e =
|
|
|
|
case e of
|
|
|
|
List es ->
|
|
|
|
withChild e (List.map expression es)
|
|
|
|
|
|
|
|
Application e1 e2 ->
|
|
|
|
withChild e
|
|
|
|
[ expression e1
|
|
|
|
, expression e2
|
|
|
|
]
|
|
|
|
|
|
|
|
e ->
|
|
|
|
li [] [ pre [] [ text <| toString e ] ]
|
|
|
|
|
|
|
|
|
|
|
|
statement : Statement -> Html Msg
|
|
|
|
statement s =
|
|
|
|
case s of
|
|
|
|
FunctionDeclaration _ _ e ->
|
|
|
|
withChild s [ expression e ]
|
|
|
|
|
|
|
|
s ->
|
|
|
|
li [] [ pre [] [ text <| toString s ] ]
|
|
|
|
|
|
|
|
|
2017-01-07 22:58:41 +03:00
|
|
|
tree : Result a ( b, c, List Statement ) -> Html Msg
|
|
|
|
tree ast =
|
|
|
|
case ast of
|
2017-01-07 20:29:26 +03:00
|
|
|
Ok ( _, _, statements ) ->
|
|
|
|
ul [] (List.map statement statements)
|
|
|
|
|
|
|
|
err ->
|
2017-01-20 00:38:46 +03:00
|
|
|
div [] [ text "Sorry, I could not parse your code. This may be my fault though :/" ]
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
|
2017-01-16 01:24:37 +03:00
|
|
|
rules : List (String -> List Types.Error)
|
|
|
|
rules =
|
2017-01-16 02:16:28 +03:00
|
|
|
[ NoDebug.rule
|
2017-01-20 00:27:11 +03:00
|
|
|
, NoDuplicateImports.rule
|
2017-01-16 01:24:37 +03:00
|
|
|
, NoExposingEverything.rule
|
2017-01-20 00:27:11 +03:00
|
|
|
, NoImportingEverything.rule
|
2017-01-16 02:16:28 +03:00
|
|
|
, NoUnannotatedFunction.rule
|
2017-01-17 01:32:06 +03:00
|
|
|
, NoUnusedVariables.rule
|
2017-01-16 01:24:37 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-01-10 00:12:37 +03:00
|
|
|
lint : String -> Html Msg
|
|
|
|
lint source =
|
2017-01-07 22:58:41 +03:00
|
|
|
let
|
|
|
|
errors =
|
2017-01-16 02:16:28 +03:00
|
|
|
List.concatMap (\rule -> rule source) rules
|
2017-01-17 01:38:05 +03:00
|
|
|
|
|
|
|
messages =
|
|
|
|
if List.isEmpty errors then
|
|
|
|
[ "No issues here." ]
|
|
|
|
else
|
|
|
|
List.map (\err -> err.rule ++ ": " ++ err.message) errors
|
2017-01-07 22:58:41 +03:00
|
|
|
in
|
2017-01-16 01:24:37 +03:00
|
|
|
div []
|
|
|
|
(List.map
|
2017-01-17 01:38:05 +03:00
|
|
|
(\message -> p [] [ text message ])
|
|
|
|
messages
|
2017-01-16 01:24:37 +03:00
|
|
|
)
|
2017-01-07 22:58:41 +03:00
|
|
|
|
|
|
|
|
2017-01-07 20:29:26 +03:00
|
|
|
view : String -> Html Msg
|
|
|
|
view model =
|
2017-01-10 00:12:37 +03:00
|
|
|
div [ id "wrapper" ]
|
2017-01-16 00:57:03 +03:00
|
|
|
[ div [ id "left" ]
|
|
|
|
[ p [ class "title" ] [ text "Source code" ]
|
|
|
|
, textarea
|
|
|
|
[ id "input"
|
|
|
|
, on "input" (JD.map Replace targetValue)
|
|
|
|
]
|
|
|
|
[ text model ]
|
|
|
|
, div []
|
|
|
|
[ p [ class "title" ] [ text "Linting errors" ]
|
|
|
|
, div [ id "lint" ]
|
|
|
|
[ lint model
|
|
|
|
]
|
|
|
|
]
|
2017-01-10 00:12:37 +03:00
|
|
|
]
|
|
|
|
, div [ id "right" ]
|
2017-01-16 00:57:03 +03:00
|
|
|
[ p [ class "title" ] [ text "AST" ]
|
|
|
|
, p [ id "ast" ] [ tree <| Ast.parse model ]
|
2017-01-07 22:58:41 +03:00
|
|
|
]
|
2017-01-10 00:12:37 +03:00
|
|
|
]
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
main : Program Never String Msg
|
|
|
|
main =
|
|
|
|
Html.beginnerProgram
|
|
|
|
{ model = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
}
|