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 (..)
-- 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
voirArbresParses arbresParsesPotentiels =
case arbresParsesPotentiels of
Err erreurs -> deadEndsToStringBis erreurs
Ok arbresParses -> voirArbres arbresParses
{--
parser =
succeed identity
|. mangeDesEspaces 2
|= (
chompUntil "\n"
|> getChompedString
)
deadEndsToStringBis errs =
errs
|> List.map voirErreur
|> String.concat
|> (++) "Il y a des problèmes aux endroits suivants :\n"
mangeDesEspaces ind =
token <| String.repeat ind " "
mangeDesEspacesBis =
let
ind =
case getIndent of
Ok indent -> indent
Err _ -> 0
in
token <| String.repeat ind " "
--}
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
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 ()
|> map (\_ -> Done (List.reverse arbrs))
|> fin
]
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
--}
in
loop [] sousArbres
Loading…
Cancel
Save