Parser jouet totalement opérationnel !!!!!!!!!!!!!

pull/1/head
Jean-Christophe Jameux 4 years ago
parent 1b2add7357
commit fff20406d7
  1. BIN
      elm-stuff/0.19.1/ParserTest.elmi
  2. BIN
      elm-stuff/0.19.1/ParserTest.elmo
  3. BIN
      elm-stuff/0.19.1/d.dat
  4. 222
      src/ParserTest.elm

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,11 +1,5 @@
module ParserTest exposing (..) 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 Parser exposing (..)
import Browser import Browser
import Html exposing (Html, button, div, text) import Html exposing (Html, button, div, text)
@ -62,8 +56,7 @@ view model =
div [] [ text texte ] 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 = unArbre =
Arbre Arbre
@ -91,33 +83,20 @@ unArbre =
] ]
] ]
voirArbreParse arbreParsePotentiel = voirArbresParses arbresParsesPotentiels =
case arbreParsePotentiel of case arbresParsesPotentiels of
Err erreurs -> deadEndsToString erreurs Err erreurs -> deadEndsToStringBis erreurs
Ok arbreParse -> voirArbre arbreParse Ok arbresParses -> voirArbres arbresParses
{-- deadEndsToStringBis errs =
parser = errs
succeed identity |> List.map voirErreur
|. mangeDesEspaces 2 |> String.concat
|= ( |> (++) "Il y a des problèmes aux endroits suivants :\n"
chompUntil "\n"
|> getChompedString
)
mangeDesEspaces ind = voirErreur err =
token <| String.repeat ind " " "Ligne : " ++ String.fromInt err.row
++ " | Colonne : " ++ String.fromInt err.col
mangeDesEspacesBis =
let
ind =
case getIndent of
Ok indent -> indent
Err _ -> 0
in
token <| String.repeat ind " "
--}
type Arbre = Arbre (List Arbre) type Arbre = Arbre (List Arbre)
@ -126,62 +105,8 @@ voirArbre arbr =
Arbre [] -> "[]" Arbre [] -> "[]"
Arbre arbrs -> "[" ++ String.concat (List.map voirArbre arbrs) ++ "]" Arbre arbrs -> "[" ++ String.concat (List.map voirArbre arbrs) ++ "]"
{-- voirArbres =
parserArbre = parserArbreInd 0 List.map voirArbre >> String.concat
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
--}
{-| Ce parser change l'indentation courante, cré un arbre puis {-| Ce parser change l'indentation courante, cré un arbre puis
y intègre ses branches grâce à une boucle y intègre ses branches grâce à une boucle
@ -193,115 +118,38 @@ arbre =
flip withIndent flip withIndent
<| succeed Arbre <| succeed Arbre
|. symbol "*" |. symbol "*"
|= loop [] arbres -- (Etat ind []) remplacé par [] |= arbres
in in
getCol getCol
|> andThen suite |> andThen suite
flip f a b = f b a flip f a b = f b a
arbres =
type alias Etat =
{ indentation : Int
, arborescence : List Arbre
}
arbres arbrs =
let let
suite col_ind = sousArbres arbrs =
if Tuple.first col_ind > Tuple.second col_ind then -- if col > ind let
boucle =
succeed ( \arbr -> Loop (arbr :: arbrs) ) succeed ( \arbr -> Loop (arbr :: arbrs) )
|= lazy (\_ -> arbre) |= 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 else
succeed () succeed ()
|> map (\_ -> Done (List.reverse arbrs)) |> fin
]
in in
succeed Tuple.pair succeed Tuple.pair
|. spaces |. spaces
|= getCol |= getCol
|= getIndent |= getIndent
|> andThen suite |> andThen suite
{-- in
oneOf loop [] sousArbres
[ 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
--}
Loading…
Cancel
Save