Messages d'erreurs beaucoup plus parlant

pull/1/head
Jean-Christophe Jameux 3 years ago
parent 1e272eb7f7
commit 156327621b
  1. 213
      src/GenerateurH5P.elm

@ -1548,6 +1548,15 @@ contentField =
-} -}
test =
"""* BranchingScenario Titre
** BranchingQuestion Question
*** trueFalse
**** CoursePresentation
***** TrueFalse
* CoursePresentation"""
type Context type Context
= PreambleContext = PreambleContext
| RootContext | RootContext
@ -1584,9 +1593,10 @@ contentsParser context depth =
contentParser context depth = contentParser context depth =
succeed identity succeed Tuple.pair
|. stars depth |. stars depth
|. espaces |= star
|. mySpaces
|= getChompedString |= getChompedString
(chompWhile (chompWhile
(\c -> (\c ->
@ -1601,7 +1611,11 @@ contentParser context depth =
) )
) )
|> andThen |> andThen
(\maybeContentType -> (\( maybeStar, maybeContentType ) ->
if maybeStar then
problem InconsistantStructure
else
case ( maybeContentType, context ) of case ( maybeContentType, context ) of
( "BranchingScenario", RootContext ) -> ( "BranchingScenario", RootContext ) ->
contentParserHelp BranchingScenarioContext depth "" contentParserHelp BranchingScenarioContext depth ""
@ -1630,6 +1644,9 @@ contentParser context depth =
( "TrueFalse", _ ) -> ( "TrueFalse", _ ) ->
problem (Problem "Un TrueFalse doit se trouver à la racine ou dans un CoursePresentation") problem (Problem "Un TrueFalse doit se trouver à la racine ou dans un CoursePresentation")
( "", _ ) ->
problem NoContent
-- Dans les trois cas ci-dessous, le maybeContentType ne désigne -- Dans les trois cas ci-dessous, le maybeContentType ne désigne
-- pas un contentType, c'est une astuce pour récupérer le texte avaler. -- pas un contentType, c'est une astuce pour récupérer le texte avaler.
-- (cf. bit dans la définition de contentParserHelp) -- (cf. bit dans la définition de contentParserHelp)
@ -1647,17 +1664,7 @@ contentParser context depth =
) )
test =
"""* BranchingScenario Titre
** BranchingQuestion Question
*** trueFalse
**** CoursePresentation
***** TrueFalse
* CoursePresentation"""
contentParserHelp context depth bit = contentParserHelp context depth bit =
--TODO
let let
f endOfLine contentList = f endOfLine contentList =
H5pTree context (bit ++ endOfLine) contentList H5pTree context (bit ++ endOfLine) contentList
@ -1667,24 +1674,6 @@ contentParserHelp context depth bit =
|= tillEndOfLine |= tillEndOfLine
|. whileNoStarOnFirstColumnOrEndOfFile |. whileNoStarOnFirstColumnOrEndOfFile
|= contentsParser context (depth + 1) |= contentsParser context (depth + 1)
|. whileNoStarOnFirstColumnOrEndOfFile
whileNoStarOnFirstColumn =
succeed identity
|. chompWhile ((/=) '*')
|= getCol
|> andThen
(\col ->
if col > 1 then
succeed ()
|. symbol (Token "*" EndOfFile)
|. whileNoStarOnFirstColumn
else
succeed
()
)
whileNoStarOnFirstColumnOrEndOfFile = whileNoStarOnFirstColumnOrEndOfFile =
@ -1706,67 +1695,28 @@ whileNoStarOnFirstColumnOrEndOfFile =
) )
countStars = stars depth =
succeed S.length symbol (Token (S.repeat depth "*") GenericProblem)
|= getChompedString (chompWhile ((==) '*'))
stars profondeur =
succeed ()
|. symbol (Token (S.repeat profondeur "*") GenericProblem)
|. espaces
tillEndOfLine =
getChompedString <|
succeed ()
|. chompWhile ((/=) '\n')
{-| Avale tout l'espace blanc et impose de s'arrêter star =
soit en début de ligne soit en fin de fichier. succeed
-}
blankLines =
succeed ()
|. chompWhile
(\x -> (\x ->
x if S.length x == 0 then
== ' ' False
|| x
== '\t'
|| x
== '\n'
|| x
== '\u{000D}'
)
|. oneOf
[ end GenericProblem
, getPosition
|> andThen
(\( row, col ) ->
if col == 1 then
succeed ()
else else
problemBis True
("N'y aurait-il pas des espaces en trop au début de la ligne "
++ String.fromInt row
++ " ?"
) )
) |= getChompedString (chompWhile ((==) '*'))
]
espaces =
chompWhile <| \x -> x == ' ' || x == '\t'
keywordBis x = tillEndOfLine =
keyword <| Token x GenericProblem getChompedString <| chompWhile ((/=) '\n')
problemBis x = mySpaces =
problem <| Problem x chompWhile <| \x -> x == ' ' || x == '\t'
@ -1785,7 +1735,7 @@ problemBis x =
-} -}
{- {-
branchingScenarioParser profondeur = branchingScenarioParser depth =
let let
f title contentList = f title contentList =
BranchingScenarioH5P BranchingScenarioH5P
@ -1799,10 +1749,10 @@ problemBis x =
succeed f succeed f
|= titleParser |= titleParser
|. blankLines |. blankLines
|= loop [] (contentsParser (profondeur + 1) BranchingScenarioContext) |= loop [] (contentsParser (depth + 1) BranchingScenarioContext)
-} -}
--|= loop ( [], 0 ) (branchingScenarioParserHelp (profondeur + 1)) --|= loop ( [], 0 ) (branchingScenarioParserHelp (depth + 1))
--|. blankLines --|. blankLines
{- Dans une configuration de la forme : {- Dans une configuration de la forme :
@ -1815,27 +1765,27 @@ problemBis x =
Récupère tout ce qui se trouve au niveau ** sous la forme d'une liste Récupère tout ce qui se trouve au niveau ** sous la forme d'une liste
-} -}
{- {-
branchingScenarioParserHelp profondeur ( contentList, contentId ) = branchingScenarioParserHelp depth ( contentList, contentId ) =
oneOf oneOf
[ let [ let
f ( contents, id ) = f ( contents, id ) =
Loop ( contentList ++ contents, id + 1 ) Loop ( contentList ++ contents, id + 1 )
in in
succeed f succeed f
|= contentParser profondeur contentId |= contentParser depth contentId
|. blankLines |. blankLines
, succeed (Done contentList) , succeed (Done contentList)
] ]
-} -}
{- {-
contentParserBis profondeur contentId = contentParserBis depth contentId =
oneOf oneOf
[ backtrackable <| branchingQuestionParser profondeur contentId [ backtrackable <| branchingQuestionParser depth contentId
, succeed (\x -> ( [ x ], contentId + 1 )) , succeed (\x -> ( [ x ], contentId + 1 ))
|= oneOf |= oneOf
[ backtrackable <| coursePresentationParser profondeur [ backtrackable <| coursePresentationParser depth
, trueFalseParser profondeur , trueFalseParser depth
] ]
--, problemBis "Oups" --, problemBis "Oups"
@ -1870,7 +1820,7 @@ uuid n =
{- {-
{-| Ici branchList est un enregistrement forçant la liste à avoir au moins deux éléments {-| Ici branchList est un enregistrement forçant la liste à avoir au moins deux éléments
-} -}
branchingQuestionParser profondeur contentId = branchingQuestionParser depth contentId =
let let
f question ( branchList, id ) = f question ( branchList, id ) =
( branchList.first :: branchList.second :: branchList.others ( branchList.first :: branchList.second :: branchList.others
@ -1878,18 +1828,18 @@ uuid n =
) )
in in
succeed f succeed f
|. stars profondeur |. stars depth
|. keywordBis "BranchingQuestion" |. keywordBis "BranchingQuestion"
|. espaces |. mySpaces
|= questionParser |= questionParser
|. blankLines |. blankLines
-- Je dirais qu'il faut un contentId + 1 ici -- Je dirais qu'il faut un contentId + 1 ici
|= loop ( [], contentId ) (branchingQuestionAlternativeParser (profondeur + 1)) |= loop ( [], contentId ) (branchingQuestionAlternativeParser (depth + 1))
{-| Ici branchList est une liste {-| Ici branchList est une liste
-} -}
branchingQuestionAlternativeParser profondeur ( branchList, contentId ) = branchingQuestionAlternativeParser depth ( branchList, contentId ) =
oneOf oneOf
[ let [ let
f alternative ( alternativeList, id ) = f alternative ( alternativeList, id ) =
@ -1903,9 +1853,9 @@ uuid n =
Loop ( alternativeList, id ) Loop ( alternativeList, id )
in in
succeed f succeed f
|. stars profondeur |. stars depth
|= alternativeAnswerParser |= alternativeAnswerParser
|= loop ( [], contentId ) (branchingQuestionAlternativeParserHelp (profondeur + 1)) |= loop ( [], contentId ) (branchingQuestionAlternativeParserHelp (depth + 1))
, (succeed () , (succeed ()
|> P.map (\_ -> List.concat branchList) |> P.map (\_ -> List.concat branchList)
) )
@ -1927,7 +1877,7 @@ uuid n =
{-| Tout le travail reste à faire ! {-| Tout le travail reste à faire !
-} -}
branchingQuestionAlternativeParserHelp profondeur ( branchList, contentId ) = branchingQuestionAlternativeParserHelp depth ( branchList, contentId ) =
oneOf oneOf
[ succeed [ succeed
(Done (Done
@ -1975,14 +1925,14 @@ deadEndsToStringBis errs =
voirErreur err = voirErreur err =
"Problème : " "Ligne "
++ showProblem err.problem
++ "Ligne : "
++ String.fromInt err.row ++ String.fromInt err.row
++ " | Colonne : " ++ ", Colonne "
++ String.fromInt err.col ++ String.fromInt err.col
++ " : "
++ showProblem err.problem
++ showContext (L.map .context err.contextStack) ++ showContext (L.map .context err.contextStack)
++ "\n\n-----------------------------------------\n" ++ "\n\n---------------------------------------------------------\n"
showProblem prob = showProblem prob =
@ -1991,10 +1941,7 @@ showProblem prob =
p ++ "\n" p ++ "\n"
NoContent -> NoContent ->
"""Je n'ai aucun contenu à produire ! "Je ne peux pas produire de contenu à partir de rien !\n"
Y a-t-il autre chose qu'un préambule à analyser ?
Est-ce que vos * ne seraient pas trop indentées ?
"""
EndOfFile -> EndOfFile ->
"Fin de fichier\n" "Fin de fichier\n"
@ -2010,43 +1957,55 @@ Est-ce que vos * ne seraient pas trop indentées ?
"Contenu H5P inconnu : " ++ x ++ "\n" "Contenu H5P inconnu : " ++ x ++ "\n"
InconsistantStructure -> InconsistantStructure ->
"La structure du document n'est pas consistante !" "La structure du document n'est pas consistante !\n"
_ -> _ ->
"Problème inconnu\n" "Problème inconnu\n"
showContext ccc = showContext contextStack =
case ccc of case contextStack of
[] -> [] ->
"" ""
_ -> _ ->
"\nContexte :\n" ++ showContextHelp (L.reverse ccc) "\nDans le contexte suivant :\n" ++ showContextHelp 0 (L.reverse contextStack)
showContextHelp ccc = showContextHelp depth ccc =
case ccc of case ccc of
[] -> [] ->
"\n" ""
PreambleContext :: cc -> c :: cc ->
let
f x =
S.repeat depth "*"
++ x
++ showContextHelp (depth + 1) cc
in
case c of
PreambleContext ->
"Préambule" "Préambule"
RootContext :: cc -> RootContext ->
showContextHelp cc if cc == [] then
"Root"
else
showContextHelp 1 cc
BranchingScenarioContext :: cc -> BranchingScenarioContext ->
"BranchingScenario > " ++ showContextHelp cc f "BranchingScenario\n"
BranchingQuestionContext :: cc -> BranchingQuestionContext ->
"BranchingQuestion > " ++ showContextHelp cc f "BranchingQuestion\n"
BranchingQuestionAlternativeContext :: cc -> BranchingQuestionAlternativeContext ->
"Alternative > " ++ showContextHelp cc f "Alternative\n"
CoursePresentationContext :: cc -> CoursePresentationContext ->
"CoursePresentation > " ++ showContextHelp cc f "CoursePresentation\n"
TrueFalseContext :: cc -> TrueFalseContext ->
"TrueFalse" f "TrueFalse\n"

Loading…
Cancel
Save