Skip to content

Commit

Permalink
Update Elm for API search to version 0.19.1 (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd authored Dec 6, 2020
1 parent 45bbcf5 commit e54ccb0
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 62 deletions.
2 changes: 1 addition & 1 deletion api_search/frontend/ExploreCompile.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

elm-make src/Explore.elm --output build/js/fplus_api_explore.js
elm make src/FPlusApiExplore.elm --output=build/js/fplus_api_explore.js

if [ $? -eq 0 ]
then
Expand Down
2 changes: 1 addition & 1 deletion api_search/frontend/TypeSignatureTestCompile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

elm-make src/TypeSignatureTestMain.elm --output build/typesignaturetest.html
elm make src/TypeSignatureTestMain.elm --output=build/typesignaturetest.html
3 changes: 2 additions & 1 deletion api_search/frontend/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ rm -r -f build
mkdir -p build
mkdir -p build/js

elm-make src/Main.elm --output build/js/fplus_api_search.js
# todo: Use --optimize
elm make src/FPlusApiSearch.elm --output=build/js/fplus_api_search.js

if [ $? -eq 0 ]
then
Expand Down
18 changes: 0 additions & 18 deletions api_search/frontend/elm-package.json

This file was deleted.

29 changes: 29 additions & 0 deletions api_search/frontend/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"andre-dietrich/parser-combinators": "4.0.0",
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/regex": "1.0.0",
"elm-community/list-extra": "8.2.4",
"elm-explorations/markdown": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"pilatch/flip": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
9 changes: 5 additions & 4 deletions api_search/frontend/src/FPlusApiCommon.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module FPlusApiCommon exposing (..)

import Database
import Debug
import TypeSignature
import Html exposing (..)
import Html.Attributes exposing (..)
Expand Down Expand Up @@ -44,7 +45,7 @@ parseSignatureCrashOnError function =
++ function.name
++ ": "
++ function.signature
|> Debug.crash
|> Debug.todo


hasFwdSignature : String -> Bool
Expand Down Expand Up @@ -122,7 +123,7 @@ showMaybeSig maybeSig =

replaceInString : String -> String -> String -> String
replaceInString pattern replacement =
Regex.replace Regex.All (Regex.regex pattern) (always replacement)
Regex.replace (Maybe.withDefault Regex.never (Regex.fromString pattern)) (always replacement)


replaceSubMatchInString : String -> (String -> String) -> String -> String
Expand All @@ -136,7 +137,7 @@ replaceSubMatchInString pattern replacementFunc =
_ ->
match
in
Regex.replace Regex.All (Regex.regex pattern) f
Regex.replace (Maybe.withDefault Regex.never (Regex.fromString pattern)) f


replaceTwoSubMatchInString :
Expand All @@ -154,7 +155,7 @@ replaceTwoSubMatchInString pattern replacementFunc =
_ ->
match
in
Regex.replace Regex.All (Regex.regex pattern) f
Regex.replace (Maybe.withDefault Regex.never (Regex.fromString pattern)) f


applyUntilIdempotent : (String -> String) -> String -> String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module FPlusApiExplore exposing (..)

import FPlusApiCommon exposing (..)
import Browser
import Database
import TypeSignature
import Html exposing (..)
Expand All @@ -12,16 +13,21 @@ import String


main =
program
{ init = initModelAndCommands
Browser.element
{ init = init
, update = update
, subscriptions = always Sub.none
, subscriptions = subscriptions
, view = view
}


initModelAndCommands : ( Model, Cmd Msg )
initModelAndCommands =
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none


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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module FPlusApiSearch exposing (..)

import FPlusApiCommon exposing (..)
import TypeSignature
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
Expand All @@ -11,21 +12,26 @@ import String


main =
program
{ init = initModelAndCommands
Browser.element
{ init = init
, update = update
, subscriptions = always Sub.none
, subscriptions = subscriptions
, view = view
}


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none


maxVisibleFunctions : Int
maxVisibleFunctions =
20


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


Expand Down Expand Up @@ -125,7 +131,7 @@ view model =
[ placeholder "search query"
, autofocus True
, autocomplete True
, style [ ( "width", "500px" ) ]
, style "width" "500px"
, onInput UpdateQuery
]
[]
Expand Down Expand Up @@ -315,17 +321,17 @@ showFunctions ratedFunctions =

ratingToHtml : Float -> Html Msg
ratingToHtml rating =
"search rating: " ++ toString (round rating) |> docFromString
"search rating: " ++ String.fromInt (round rating) |> docFromString


showRatedFunction : ( Function, Float ) -> Html Msg
showRatedFunction ( function, rating ) =
let
functionRating =
ratingOfFunction =
div [ class "functionrating" ]
[ rating
|> ratingToHtml
]
in
div [ class "function" ]
( showFunctionDivs function ++ [functionRating] )
( showFunctionDivs function ++ [ratingOfFunction] )
29 changes: 15 additions & 14 deletions api_search/frontend/src/TypeSignature.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module TypeSignature exposing (Signature, parseSignature, showSignature, normali
{-| This module provides the possibility to parse Haskell and Elm type signatures.
-}

import Combine as C exposing ((<$))
import Combine as C
import Combine.Char as CC
import Combine.Num as CN
import Char
import Debug
import Dict
import Tuple exposing (first)
import List exposing ((::))
Expand Down Expand Up @@ -39,7 +40,7 @@ splitLast xs =

_ ->
"Error splitLast"
|> Debug.crash
|> Debug.todo


curry1 : Signature -> Signature
Expand All @@ -48,7 +49,7 @@ curry1 sig =
Arrow (Tuple []) ret ->
"Error curry1 (empty tuple): "
++ showSignature True sig
|> Debug.crash
|> Debug.todo

Arrow (Tuple params) ret ->
let
Expand All @@ -59,13 +60,13 @@ curry1 sig =
[p] -> Arrow p (Arrow x ret)
_ -> Arrow (Tuple ps) (Arrow x ret)

Arrow sig ret ->
Arrow (Tuple []) (Arrow sig ret)
Arrow sig2 ret ->
Arrow (Tuple []) (Arrow sig2 ret)

_ ->
"Error curry1: "
++ showSignature True sig
|> Debug.crash
|> Debug.todo

curry1Flip : Signature -> Signature
curry1Flip sig =
Expand All @@ -75,19 +76,19 @@ curry1Flip sig =
_ ->
"Error curry1Flip: "
++ showSignature True sig
|> Debug.crash
|> Debug.todo

mapS : (s -> String -> ( s, String )) -> s -> List Signature -> ( List Signature, s )
mapS f s =
let
go sig ( sigs, s ) =
go sig ( sigs, s2 ) =
let
( sig_, s_ ) =
mapLRS f s sig
mapLRS f s2 sig
in
( sig_ :: sigs, s_ )
in
List.foldl go ( [], s ) >> \( xs, s ) -> ( List.reverse xs, s )
List.foldl go ( [], s ) >> \( xs, s2 ) -> ( List.reverse xs, s2 )



Expand Down Expand Up @@ -146,7 +147,7 @@ nthVarName : Int -> String
nthVarName i =
let
charPart =
97 + (rem i 26) |> Char.fromCode |> String.fromChar
97 + (remainderBy 26 i) |> Char.fromCode |> String.fromChar

addNumber =
i // 26
Expand All @@ -155,7 +156,7 @@ nthVarName i =
if addNumber == 0 then
""
else
toString addNumber
String.fromInt addNumber
in
charPart ++ numStr

Expand Down Expand Up @@ -286,7 +287,7 @@ arrowParser : C.Parser s Signature
arrowParser =
let
arrowOp =
Arrow <$ trimSpaces (C.string "->")
C.onsuccess Arrow (trimSpaces (C.string "->"))
in
C.chainr arrowOp (C.lazy <| \() -> nonAppSignatureParser)

Expand All @@ -308,7 +309,7 @@ typeApplicationParser : C.Parser s Signature
typeApplicationParser =
let
typeApplyOp =
TypeApplication <$ C.many1 CC.space
C.onsuccess TypeApplication (C.many1 CC.space)

validate ta =
if isValidTypeApplication ta then
Expand Down
20 changes: 13 additions & 7 deletions api_search/frontend/src/TypeSignatureTestMain.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module TypeSignatureTestMain exposing (..)

import Browser
import TypeSignature
import Html exposing (..)
import Html.Attributes exposing (..)
Expand All @@ -10,8 +11,8 @@ import String


main =
beginnerProgram
{ model = ""
Browser.sandbox
{ init = init
, update = update
, view = view
}
Expand All @@ -21,6 +22,11 @@ type alias Model =
String


init : Model
init =
""


type Msg
= UpdateStr String

Expand Down Expand Up @@ -68,15 +74,15 @@ view str =
[ input
[ placeholder "please enter type signature"
, autofocus True
, style [ ( "width", "500px" ) ]
, style "width" "500px"
, onInput UpdateStr
]
[]
, div [ style [ ( "margin", "10px" ) ] ]
[ "parse result: " ++ (maybeSignature |> toString) |> text ]
, div [ style [ ( "margin", "10px" ) ] ]
, div [ style "margin" "10px" ]
[ "parse result: " ++ (maybeSignature |> Debug.toString) |> text ]
, div [ style "margin" "10px" ]
[ "parse result: "
++ (maybeSignatureNormalized |> toString)
++ (maybeSignatureNormalized |> Debug.toString)
|> text
]
, div [] [ "as string: " ++ signatureString |> text ]
Expand Down
2 changes: 1 addition & 1 deletion api_search/frontend/src/htmlmain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function init() {
var mainDiv = document.getElementById('main');
elmContent = Elm.FPlusApiSearch.embed(mainDiv);
elmContent = Elm.FPlusApiSearch.init({ node: mainDiv });
}
2 changes: 1 addition & 1 deletion api_search/frontend/src/htmlmain_explore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function init() {
var mainDiv = document.getElementById('main');
elmContent = Elm.FPlusApiExplore.embed(mainDiv);
elmContent = Elm.FPlusApiExplore.init({ node: mainDiv });
}

0 comments on commit e54ccb0

Please sign in to comment.