diff --git a/elm-stuff/0.19.1/ParserMaths.elmi b/elm-stuff/0.19.1/ParserMaths.elmi index af18370..64af869 100644 Binary files a/elm-stuff/0.19.1/ParserMaths.elmi and b/elm-stuff/0.19.1/ParserMaths.elmi differ diff --git a/elm-stuff/0.19.1/ParserMaths.elmo b/elm-stuff/0.19.1/ParserMaths.elmo index dffa50e..f456104 100644 Binary files a/elm-stuff/0.19.1/ParserMaths.elmo and b/elm-stuff/0.19.1/ParserMaths.elmo differ diff --git a/elm-stuff/0.19.1/QCM.elmi b/elm-stuff/0.19.1/QCM.elmi index 86818cd..c72c4e8 100644 Binary files a/elm-stuff/0.19.1/QCM.elmi and b/elm-stuff/0.19.1/QCM.elmi differ diff --git a/elm-stuff/0.19.1/QCM.elmo b/elm-stuff/0.19.1/QCM.elmo index 3143c24..4eb0016 100644 Binary files a/elm-stuff/0.19.1/QCM.elmo and b/elm-stuff/0.19.1/QCM.elmo differ diff --git a/elm-stuff/0.19.1/d.dat b/elm-stuff/0.19.1/d.dat index d6fa1f6..e6b81fe 100644 Binary files a/elm-stuff/0.19.1/d.dat and b/elm-stuff/0.19.1/d.dat differ diff --git a/src/ParserMaths.elm b/src/ParserMaths.elm index 823d155..048363c 100644 --- a/src/ParserMaths.elm +++ b/src/ParserMaths.elm @@ -1,10 +1,11 @@ -module ParserMaths exposing (parseMaths, evaluer, montrerErreurs) +module ParserMaths exposing (parseMaths, evaluer, evaluerBis, montrerErreurs, expr) -import Fractions as F +import Fractions as F exposing (Frac) import Maybe as M import Set import Parser exposing (..) + montrerErreurs : String -> List DeadEnd -> String montrerErreurs source errs = case List.head errs of @@ -32,6 +33,11 @@ displayExpected err = _ -> "une expression" +evaluerBis : Expr -> F.Frac +evaluerBis expression = + case evaluer expression of + Nothing -> Frac 666 1 + Just a -> a evaluer : Expr -> Maybe F.Frac evaluer expression = @@ -65,6 +71,22 @@ evaluer expression = Poly a_i x -> Just <| F.Frac 50 1 +{-- +type Expr + = Const Fraction + | Var String + | Poly (List Fraction) String + | Exp Expr + | Ln Expr + | Sin Expr + | Cos Expr + | Prod Expr Expr + | Div Expr Expr + | Sum Expr Expr + | Dif Expr Expr + | Exp Expr Frac + | Opp Expr +--} type Expr = Add Expr Expr diff --git a/src/QCM.elm b/src/QCM.elm index 2b28487..7996dcf 100644 --- a/src/QCM.elm +++ b/src/QCM.elm @@ -7,7 +7,7 @@ import Set import ParserMaths as PM import String as S import Fractions as F exposing (Frac) -import Html exposing (Html, Attribute, button, div, textarea, input, text, p, iframe) +import Html exposing (Html, Attribute, button, div, textarea, input, p, iframe) import Html.Attributes exposing (..) import Html.Events exposing (onInput, onClick) @@ -84,6 +84,7 @@ view model = <| textarea [ placeholder "Liste des variables", value model.variables, onInput Variables ] [] :: textarea [ placeholder "Format de la question", value model.question, onInput Question ] [] :: button [ onClick GenererQuestion ] [ text "Générer les questions" ] + :: (text "Le résultat apparaitra\nici") :: [ ( p [] <| L.map (\q -> p [] [text q]) model.questions ) ] {-- :: text @@ -143,6 +144,12 @@ mix lls = (a :: ls) :: llss -> ( List.map ( (::) a ) ( mix llss ) ) ++ mix ( ls :: llss ) -} +text chaine = + S.lines chaine + |> L.map (p [] << L.singleton << Html.text) + |> p [] + + {- ██████ █████ ██████ ███████ ███████ ██████ ██████ ██████ ███ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ @@ -229,7 +236,7 @@ parserAremplacer variables = aRemplacer : Parser Aremplacer aRemplacer = - succeed Aremplacer + succeed ( \x y -> Aremplacer x (L.map (F.teX << PM.evaluerBis) y) ) |. P.spaces |= P.variable { start = \_ -> True @@ -243,11 +250,14 @@ aRemplacer = , separator = "," , end = "" , spaces = spaces + , item = PM.expr + {-- , item = P.variable { start = (/=) ',' , inner = (/=) ',' , reserved = Set.fromList [] } + --} , trailing = P.Optional } @@ -312,23 +322,6 @@ remplacerLaVariableParLaValeurDansLeTexteVariable var val tv = -} -type Nombre - = - -type Expr num - = Const num - | Var String - | Poly ( List num ) - | Exp ( Expr num ) - | Ln ( Expr num ) - | Sin ( Expr num ) - | Cos ( Expr num ) - | Prod ( Expr num ) ( Expr num ) - | Quot ( Expr num ) ( Expr num ) - | Sum ( Expr num ) ( Expr num ) - | Diff ( Expr num ) ( Expr num ) - | Power ( Expr num ) num - monome a n = if a == 0 then "" else if n == 0 then ( String.fromInt a ) @@ -385,15 +378,12 @@ dlGen a_ks n = {- - ██████ ██████ ███ ███ ██ ██ ██ ████ ████ ██ ██ ██ ██ ████ ██ ██ ▄▄ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ▀▀ - - -}