parent
24783e8d32
commit
943590c669
@ -1,53 +0,0 @@ |
|||||||
module Couleur exposing (Couleur) |
|
||||||
|
|
||||||
|
|
||||||
type alias Couleur = |
|
||||||
{ rouge : Float |
|
||||||
, vert : Float |
|
||||||
, bleu : Float |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
plusSombre : Float -> Couleur -> Couleur |
|
||||||
plusSombre taux { red, green, blue, alpha } = |
|
||||||
if red < green && red < blue then |
|
||||||
let |
|
||||||
nouveauRouge = |
|
||||||
red * taux |
|
||||||
|
|
||||||
nouveauPasRouge = |
|
||||||
nouveauRouge - red |
|
||||||
in |
|
||||||
{ red = nouveauRouge |
|
||||||
, green = green + nouveauPasRouge |
|
||||||
, blue = blue + nouveauPasRouge |
|
||||||
, alpha = alpha |
|
||||||
} |
|
||||||
|
|
||||||
else if green < blue then |
|
||||||
let |
|
||||||
nouveauVert = |
|
||||||
green * taux |
|
||||||
|
|
||||||
nouveauPasVert = |
|
||||||
nouveauVert - green |
|
||||||
in |
|
||||||
{ red = red + nouveauPasVert |
|
||||||
, green = nouveauVert |
|
||||||
, blue = blue + nouveauPasVert |
|
||||||
, alpha = alpha |
|
||||||
} |
|
||||||
|
|
||||||
else |
|
||||||
let |
|
||||||
nouveauBleu = |
|
||||||
blue * taux |
|
||||||
|
|
||||||
nouveauPasBleu = |
|
||||||
nouveauBleu - blue |
|
||||||
in |
|
||||||
{ red = red + nouveauPasBleu |
|
||||||
, green = green + nouveauPasBleu |
|
||||||
, blue = blue + nouveauBleu |
|
||||||
, alpha = alpha |
|
||||||
} |
|
||||||
@ -1,164 +0,0 @@ |
|||||||
module ParserArbre exposing (..) |
|
||||||
|
|
||||||
import Parser exposing (..) |
|
||||||
import Browser |
|
||||||
import Html exposing (Html, button, div, text) |
|
||||||
import Html.Events exposing (onClick) |
|
||||||
import Maybe exposing (Maybe) |
|
||||||
import Result exposing (Result) |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- MAIN |
|
||||||
|
|
||||||
|
|
||||||
main = |
|
||||||
Browser.sandbox { init = init, update = update, view = view } |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- MODEL |
|
||||||
|
|
||||||
|
|
||||||
type alias Model = Int |
|
||||||
|
|
||||||
|
|
||||||
init : Model |
|
||||||
init = |
|
||||||
0 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- UPDATE |
|
||||||
|
|
||||||
|
|
||||||
type Msg |
|
||||||
= Increment |
|
||||||
| Decrement |
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> Model |
|
||||||
update msg model = |
|
||||||
case msg of |
|
||||||
Increment -> |
|
||||||
model + 1 |
|
||||||
|
|
||||||
Decrement -> |
|
||||||
model - 1 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- VIEW |
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg |
|
||||||
view model = |
|
||||||
div [] [ text texte ] |
|
||||||
|
|
||||||
{- |
|
||||||
Sans le withIndent -1, les arbres sous-indentés sautes |
|
||||||
-} |
|
||||||
texte = voirArbresParses <| run (withIndent -1 arbres) |
|
||||||
""" |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
|
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
* |
|
||||||
""" |
|
||||||
|
|
||||||
unArbre = |
|
||||||
Arbre |
|
||||||
[ Arbre [] |
|
||||||
, Arbre |
|
||||||
[ Arbre [] |
|
||||||
] |
|
||||||
] |
|
||||||
|
|
||||||
voirArbresParses arbresParsesPotentiels = |
|
||||||
case arbresParsesPotentiels of |
|
||||||
Err erreurs -> deadEndsToStringBis erreurs |
|
||||||
Ok arbresParses -> voirArbres arbresParses |
|
||||||
|
|
||||||
deadEndsToStringBis errs = |
|
||||||
errs |
|
||||||
|> List.map voirErreur |
|
||||||
|> String.concat |
|
||||||
|> (++) "Il y a des problèmes aux endroits suivants :\n" |
|
||||||
|
|
||||||
voirErreur err = |
|
||||||
"Ligne : " ++ String.fromInt err.row |
|
||||||
++ " | Colonne : " ++ String.fromInt err.col |
|
||||||
|
|
||||||
type Arbre = Arbre (List Arbre) |
|
||||||
|
|
||||||
voirArbre arbr = |
|
||||||
case arbr of |
|
||||||
Arbre [] -> "[]" |
|
||||||
Arbre arbrs -> "[" ++ String.concat (List.map voirArbre arbrs) ++ "]" |
|
||||||
|
|
||||||
voirArbres = |
|
||||||
List.map voirArbre >> String.concat |
|
||||||
|
|
||||||
{-| Ce parser change l'indentation courante, cré un arbre puis |
|
||||||
y intègre ses branches grâce à une boucle |
|
||||||
-} |
|
||||||
arbre : Parser Arbre |
|
||||||
arbre = |
|
||||||
let |
|
||||||
suite = |
|
||||||
Debug.log "? :" <| |
|
||||||
flip withIndent |
|
||||||
<| succeed Arbre |
|
||||||
|. symbol "*" |
|
||||||
|= arbres |
|
||||||
in |
|
||||||
getCol |
|
||||||
|> andThen suite |
|
||||||
|> Debug.log "Arbre : " |
|
||||||
|
|
||||||
flip f a b = f b a |
|
||||||
|
|
||||||
arbres = |
|
||||||
let |
|
||||||
sousArbres arbrs = |
|
||||||
let |
|
||||||
boucle = |
|
||||||
succeed ( \arbr -> Loop (arbr :: arbrs) ) |
|
||||||
|= arbre -- lazy (\_ -> arbre) semble inutile malgrè l'appel récursif... |
|
||||||
fin = |
|
||||||
map (\_ -> Done (List.reverse arbrs)) |
|
||||||
suite col_ind = |
|
||||||
oneOf |
|
||||||
[ succeed () |
|
||||||
|. end |
|
||||||
|> fin |
|
||||||
, if Tuple.first col_ind > Tuple.second col_ind then -- if col > ind |
|
||||||
boucle |
|
||||||
else |
|
||||||
succeed () |
|
||||||
|> fin |
|
||||||
] |
|
||||||
in |
|
||||||
succeed Tuple.pair |
|
||||||
|. spaces |
|
||||||
|= getCol |
|
||||||
|= getIndent |
|
||||||
|> andThen suite |
|
||||||
in |
|
||||||
loop [] sousArbres |
|
||||||
|> Debug.log "Début de la boucle arbres : " |
|
||||||
@ -0,0 +1,196 @@ |
|||||||
|
module ParserMathsPratt exposing |
||||||
|
( Expr(..) |
||||||
|
, evaluer |
||||||
|
, evaluerBis |
||||||
|
, expr |
||||||
|
, montrerErreurs |
||||||
|
, parseMaths |
||||||
|
, resultatFractionnaire |
||||||
|
) |
||||||
|
|
||||||
|
import Fraction |
||||||
|
import Maybe as M |
||||||
|
import Parser exposing (..) |
||||||
|
import Pratt exposing (constant, infixLeft, infixRight, literal, postfix, prefix) |
||||||
|
import Set |
||||||
|
|
||||||
|
|
||||||
|
type Expr |
||||||
|
= Entier Int |
||||||
|
| Decimal Float |
||||||
|
| Oppose Expr |
||||||
|
| Somme Expr Expr |
||||||
|
| Difference Expr Expr |
||||||
|
| Produit Expr Expr |
||||||
|
| Quotient Expr Expr |
||||||
|
| Reste Expr Expr |
||||||
|
| Exp Expr Expr |
||||||
|
| Cos Expr |
||||||
|
| Sin Expr |
||||||
|
| Tan Expr |
||||||
|
| ArcCos Expr |
||||||
|
| ArcSin Expr |
||||||
|
| ArcTan Expr |
||||||
|
| Log Expr |
||||||
|
| Ln Expr |
||||||
|
| Factorielle Expr |
||||||
|
| Degre Expr |
||||||
|
| Poly (List Expr) String |
||||||
|
| E |
||||||
|
| Pi |
||||||
|
|
||||||
|
|
||||||
|
parseMaths : String -> Result (List DeadEnd) Expr |
||||||
|
parseMaths source = |
||||||
|
run expr source |
||||||
|
|
||||||
|
|
||||||
|
montrerErreurs : String -> List DeadEnd -> String |
||||||
|
montrerErreurs source errs = |
||||||
|
case List.head errs of |
||||||
|
Nothing -> |
||||||
|
"" |
||||||
|
|
||||||
|
Just firstErr -> |
||||||
|
source |
||||||
|
++ "\n" |
||||||
|
++ String.repeat (firstErr.col - 1) " " |
||||||
|
++ "^" |
||||||
|
++ "\nL'algorithme attendait :" |
||||||
|
++ String.join |
||||||
|
" ou " |
||||||
|
(List.map montrerAttendu errs) |
||||||
|
|
||||||
|
|
||||||
|
montrerAttendu : DeadEnd -> String |
||||||
|
montrerAttendu err = |
||||||
|
case err.problem of |
||||||
|
ExpectingNumber -> |
||||||
|
"un nombre entier" |
||||||
|
|
||||||
|
ExpectingSymbol s -> |
||||||
|
"un \"" ++ s ++ "\"" |
||||||
|
|
||||||
|
_ -> |
||||||
|
"une expression" |
||||||
|
|
||||||
|
|
||||||
|
evaluerBis : Expr -> Fraction.Fraction |
||||||
|
evaluerBis expression = |
||||||
|
case resultatFractionnaire expression of |
||||||
|
Err _ -> |
||||||
|
{ numerateur = 666, denominateur = 1 } |
||||||
|
|
||||||
|
Ok a -> |
||||||
|
a |
||||||
|
|
||||||
|
|
||||||
|
evaluer = |
||||||
|
resultatFractionnaire |
||||||
|
|
||||||
|
|
||||||
|
resultatFractionnaire : Expr -> Fraction.Resultat |
||||||
|
resultatFractionnaire expression = |
||||||
|
let |
||||||
|
f opperation a b = |
||||||
|
Fraction.map2 opperation (resultatFractionnaire a) (resultatFractionnaire b) |
||||||
|
in |
||||||
|
case expression of |
||||||
|
Somme a b -> |
||||||
|
f Fraction.somme a b |
||||||
|
|
||||||
|
Difference a b -> |
||||||
|
f Fraction.difference a b |
||||||
|
|
||||||
|
Produit a b -> |
||||||
|
f Fraction.produit a b |
||||||
|
|
||||||
|
Quotient a b -> |
||||||
|
f Fraction.quotient a b |
||||||
|
|
||||||
|
Exp a b -> |
||||||
|
f Fraction.exp a b |
||||||
|
|
||||||
|
Oppose a -> |
||||||
|
Result.map Fraction.oppose (resultatFractionnaire a) |
||||||
|
|
||||||
|
Entier n -> |
||||||
|
Fraction.fraction n 1 |
||||||
|
|
||||||
|
Poly a_i x -> |
||||||
|
Err "Les polynômes ne sont pas encore pris en charge." |
||||||
|
|
||||||
|
_ -> |
||||||
|
Err "BOOM" |
||||||
|
|
||||||
|
|
||||||
|
expr : Parser Expr |
||||||
|
expr = |
||||||
|
succeed identity |
||||||
|
|= mathExpression |
||||||
|
|
||||||
|
|
||||||
|
mathExpression : Parser Expr |
||||||
|
mathExpression = |
||||||
|
Pratt.expression |
||||||
|
{ oneOf = |
||||||
|
[ constant (keyword "E") E |
||||||
|
, constant (keyword "Pi") Pi |
||||||
|
, literal (map Entier int) |
||||||
|
, prefix 3 (symbol "-") Oppose |
||||||
|
, expressionEntreParentheses |
||||||
|
, prefix 3 (symbol "+") identity |
||||||
|
, prefix 5 (keyword "Cos") Cos |
||||||
|
, prefix 5 (keyword "Sin") Sin |
||||||
|
, prefix 5 (keyword "Tan") Tan |
||||||
|
, prefix 5 (keyword "ArcCos") ArcCos |
||||||
|
, prefix 5 (keyword "ArcSin") ArcSin |
||||||
|
, prefix 5 (keyword "ArcTan") ArcTan |
||||||
|
, prefix 5 (keyword "Log") Log |
||||||
|
, prefix 5 (keyword "Ln") Ln |
||||||
|
] |
||||||
|
, andThenOneOf = |
||||||
|
[ infixLeft 1 (symbol "+") Somme |
||||||
|
, infixLeft 1 (symbol "-") Difference |
||||||
|
, infixLeft 2 (symbol "*") Produit |
||||||
|
, infixLeft 2 (symbol "%") Reste |
||||||
|
, infixLeft 2 (symbol "/") Quotient |
||||||
|
, infixRight 4 (symbol "^") Exp |
||||||
|
, postfix 6 (symbol "!") Factorielle |
||||||
|
, postfix 6 (symbol "°") Degre |
||||||
|
] |
||||||
|
, spaces = espaces |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
espaces = |
||||||
|
Parser.chompWhile <| (==) ' ' |
||||||
|
|
||||||
|
|
||||||
|
expressionEntreParentheses : Pratt.Config Expr -> Parser Expr |
||||||
|
expressionEntreParentheses config = |
||||||
|
succeed identity |
||||||
|
|. symbol "(" |
||||||
|
|= Pratt.subExpression 0 config |
||||||
|
|. symbol ")" |
||||||
|
|
||||||
|
|
||||||
|
poly : Parser Expr |
||||||
|
poly = |
||||||
|
succeed Poly |
||||||
|
|. keyword "Poly" |
||||||
|
|. spaces |
||||||
|
|= sequence |
||||||
|
{ start = "[" |
||||||
|
, separator = "," |
||||||
|
, end = "]" |
||||||
|
, spaces = spaces |
||||||
|
, item = lazy (\_ -> mathExpression) |
||||||
|
, trailing = Forbidden |
||||||
|
} |
||||||
|
|. spaces |
||||||
|
|= variable |
||||||
|
{ start = \_ -> True |
||||||
|
, inner = \_ -> False |
||||||
|
, reserved = Set.fromList [] |
||||||
|
} |
||||||
@ -0,0 +1,61 @@ |
|||||||
|
module Sujet exposing (..) |
||||||
|
|
||||||
|
|
||||||
|
type Bloc typeDeBloc etat exportabilite |
||||||
|
= Bloc |
||||||
|
{ entete : Macro |
||||||
|
, contenu : List Bloc |
||||||
|
, commentaire : Macro |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Les différents types de blocs |
||||||
|
|
||||||
|
|
||||||
|
type Simple |
||||||
|
= Simple |
||||||
|
|
||||||
|
|
||||||
|
type Qcm |
||||||
|
= Qcm |
||||||
|
|
||||||
|
|
||||||
|
type VraiFaux |
||||||
|
= VraixFaux |
||||||
|
|
||||||
|
|
||||||
|
type Aremplacer |
||||||
|
= Aremplacer |
||||||
|
|
||||||
|
|
||||||
|
type Tag |
||||||
|
= Tag |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Les blocs peuvent être complets ou incomplets |
||||||
|
|
||||||
|
|
||||||
|
type Complet |
||||||
|
= Complet |
||||||
|
|
||||||
|
|
||||||
|
type Incomplet |
||||||
|
= Incomplet |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Les blocs peuvent être exportable (en QuizScan ou EvalBox) ou non |
||||||
|
|
||||||
|
|
||||||
|
type NonExportable |
||||||
|
= NonExportable |
||||||
|
|
||||||
|
|
||||||
|
type ExportableEnQuizscanSeulement |
||||||
|
= ExportableEnQuizscanSeulement |
||||||
|
|
||||||
|
|
||||||
|
type Exportable |
||||||
|
= Exportable |
||||||
Loading…
Reference in new issue