diff --git a/elm-stuff/0.19.1/ParserTest.elmi b/elm-stuff/0.19.1/ParserTest.elmi index 050a764..f7801ee 100644 Binary files a/elm-stuff/0.19.1/ParserTest.elmi and b/elm-stuff/0.19.1/ParserTest.elmi differ diff --git a/elm-stuff/0.19.1/ParserTest.elmo b/elm-stuff/0.19.1/ParserTest.elmo index 8e28bed..5fedd6a 100644 Binary files a/elm-stuff/0.19.1/ParserTest.elmo and b/elm-stuff/0.19.1/ParserTest.elmo differ diff --git a/elm-stuff/0.19.1/d.dat b/elm-stuff/0.19.1/d.dat index 8e7c52c..14f4675 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/ParserTest.elm b/src/ParserTest.elm index fe47b8b..394741d 100644 --- a/src/ParserTest.elm +++ b/src/ParserTest.elm @@ -1,11 +1,5 @@ module ParserTest exposing (..) --- Press buttons to increment and decrement a counter. --- --- Read how it works: --- https://guide.elm-lang.org/architecture/buttons.html --- - import Parser exposing (..) import Browser import Html exposing (Html, button, div, text) @@ -62,8 +56,7 @@ view model = div [] [ text texte ] -texte = voirArbreParse <| run arbre "*\n *" -{-- +texte = voirArbresParses <| run (withIndent -1 arbres) -- permet d'avoir... """ * * @@ -76,12 +69,11 @@ texte = voirArbreParse <| run arbre "*\n *" * * * - * +* <- cet arbre * * * - """ ---} +""" unArbre = Arbre @@ -91,33 +83,20 @@ unArbre = ] ] -voirArbreParse arbreParsePotentiel = - case arbreParsePotentiel of - Err erreurs -> deadEndsToString erreurs - Ok arbreParse -> voirArbre arbreParse - -{-- -parser = - succeed identity - |. mangeDesEspaces 2 - |= ( - chompUntil "\n" - |> getChompedString - ) - -mangeDesEspaces ind = - token <| String.repeat ind " " - - -mangeDesEspacesBis = - let - ind = - case getIndent of - Ok indent -> indent - Err _ -> 0 - in - token <| String.repeat ind " " ---} +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) @@ -126,62 +105,8 @@ voirArbre arbr = Arbre [] -> "[]" Arbre arbrs -> "[" ++ String.concat (List.map voirArbre arbrs) ++ "]" -{-- -parserArbre = parserArbreInd 0 - -parserArbreInd ind = - succeed Arbre - |. token <| String.repeat ind " " - | - |. symbol "*" - |= oneOF [fin, sousArbre] - |. token "\n" - |. spaces - |= - -type Ligne = - LigneVide - | Ligne Indentation - -type alias Indentation = - { indentation : Int - , ligne : String - } - -parserArborescence chaine = - chaine - |> String.lines - |> List.map profondeur - |> construireArbre - -construireArbre : List Ligne -> Result Arbre -construireArbre lgns = - case lgns of - [] -> Ok <| Arbre [] - LigneVide :: lgnss -> Ok <| construireArbre lgnss - Ligne ind :: lgnss -> - construireArbreBis ind.indentation ( Arbre [] ) lgnss - -construireArbreBis prfdr arbrs lgns = - case - -profondeur : String -> Ligne -profondeur ligne = - Indentation 0 ligne - |> profondeurBis - -profondeurBis ind = - if String.isEmpty ind.ligne then - LigneVide - else if String.startsWith " " then - { ind - | indentation = ind.indentation + 1 - , ligne = String.dropLeft 1 ind.ligne - } - else - ind ---} - +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 @@ -193,115 +118,38 @@ arbre = flip withIndent <| succeed Arbre |. symbol "*" - |= loop [] arbres -- (Etat ind []) remplacé par [] + |= arbres in getCol |> andThen suite flip f a b = f b a - -type alias Etat = - { indentation : Int - , arborescence : List Arbre - } - -arbres arbrs = +arbres = let - suite col_ind = - if Tuple.first col_ind > Tuple.second col_ind then -- if col > ind - succeed ( \arbr -> Loop (arbr :: arbrs) ) - |= lazy (\_ -> arbre) - else - succeed () - |> map (\_ -> Done (List.reverse arbrs)) + sousArbres arbrs = + let + boucle = + succeed ( \arbr -> Loop (arbr :: arbrs) ) + |= lazy (\_ -> arbre) + 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 - succeed Tuple.pair - |. spaces - |= getCol - |= getIndent - |> andThen suite - {-- - oneOf - [ succeed ( \arbr -> Loop { etat | arborescence = arbr :: etat.arborescence } ) - |= arbresBis - |. spaces - , succeed () - |> map (\_ -> Done (List.reverse etat.arborescence)) - ] - --} - -{-- -arbresBis typeInd = - case typeInd of - MemeIndentation -> - succeed ( \arbr -> Loop { etat | arborescence = arbr :: etat.arborescence } ) - |. symbol "*" - |. spaces - |= regarderIndentation - -type Indentation = - MemeIndentation - | MoinsIndentee - | PlusIndentee - -regarderIndentation : Parser Indentation -regarderIndentation = - succeed pair - |= getCol - |= getIndent - |> andThen regarderIndentationBis - -regarderIndentationBis col_ind = - let - col = first col_ind - ind = second col_ind - if col == ind then MemeIndentation - else if col < ind then MoinsIndentee - else PlusIndentee - -arbresBis : Parser Arbre -arbresBis = - memeIndentation - |> andThen arbresTer - -arbresTer : Bool -> Parser Arbre -arbresTer mmInd = - if mmInd then - succeed Arbre - else - problem "expecting more spaces" - -plusIndentee : Parser Bool -plusIndentee = - succeed (>=) - |= getCol - |= getIndent - -moinsIndentee : Parser Bool -moinsIndentee = - succeed (<=) - |= getCol - |= getIndent - -parser = - succeed (x -> Arbre ) - |= oneOf - [ getChompedString <| chompUntil "\n" - , succeed "" - ] - |. token "\n" - |. spaces - |= changerIndentation parser - -parserBis = - getChompedString <| chompUntil "\n" - |. token "\n" - |. spaces - |= changerIndentation parser - - -changerIndentation prsr - succeed (col -> withIndent col prsr) - |= getCol ---} + loop [] sousArbres \ No newline at end of file