----------------------------------------------------------------------
-- A few 'show' functions for Failure, Rule, and Shunt
----------------------------------------------------------------------

-- | Give a textual representation of a 'Failure'.
showFailure :: Token a => Failure a -> String
showFailure f = case f of
  MissingBefore ps p ->
    "Parse error: missing operator parts " ++
    concatMap (unwords . map toString) ps ++
    " before " ++ toString p
  MissingAfter p ps ->
    "Parse error: missing operator part " ++
    concat (intersperse ", " $ map toString p) ++ " after " ++
    unwords (map toString ps)
  CantMix a b ->
     "Parse error: cannot mix operators " ++ showPart a ++
     " and " ++ showPart b
  MissingSubBetween a b ->
    "Parse error: no sub-expression between " ++ toString a ++
    " and " ++ toString b
  MissingSubBefore a ->
    "Parse error: no sub-expression before " ++ toString a
  MissingSubAfter a ->
    "Parse error: no sub-expression after " ++ toString a
  Ambiguity _ ->
    "Parse error: the symbol is an ambiguous part"
  Unexpected ->
    "Parsing raised a bug"
showFailure :: Token a => Failure a -> String
showFailure f = case f of
  MissingBefore ps p ->
    "Parse error: missing operator parts " ++
    concatMap (unwords . map toString) ps ++
    " before " ++ toString p
  MissingAfter p ps ->
    "Parse error: missing operator part " ++
    concat (intersperse ", " $ map toString p) ++ " after " ++
    unwords (map toString ps)
  CantMix a b ->
     "Parse error: cannot mix operators " ++ showPart a ++
     " and " ++ showPart b
  MissingSubBetween a b ->
    "Parse error: no sub-expression between " ++ toString a ++
    " and " ++ toString b
  MissingSubBefore a ->
    "Parse error: no sub-expression before " ++ toString a
  MissingSubAfter a ->
    "Parse error: no sub-expression after " ++ toString a
  Ambiguity _ ->
    "Parse error: the symbol is an ambiguous part"
  Unexpected ->
    "Parsing raised a bug"
showFailure f = case f of
  MissingBefore ps p ->
    "Parse error: missing operator parts " ++
    concatMap (unwords . map toString) ps ++
    " before " ++ toString p
  MissingAfter p ps ->
    "Parse error: missing operator part " ++
    concat (intersperse ", " $ map toString p) ++ " after " ++
    unwords (map toString ps)
  CantMix a b ->
     "Parse error: cannot mix operators " ++ showPart a ++
     " and " ++ showPart b
  MissingSubBetween a b ->
    "Parse error: no sub-expression between " ++ toString a ++
    " and " ++ toString b
  MissingSubBefore a ->
    "Parse error: no sub-expression before " ++ toString a
  MissingSubAfter a ->
    "Parse error: no sub-expression after " ++ toString a
  Ambiguity _ ->
    "Parse error: the symbol is an ambiguous part"
  Unexpected ->
    "Parsing raised a bug"