sanityCheck :: [Pos Token] -> [Pos Token]
sanityCheck xs = (filterDoubleSpaces . filterEndspaces) xs
    where
    filterEndspaces [] = []
    filterEndspaces xs = case snd (head xs) of
        Space -> die
        Newline -> die
        Indent -> die
        Dedent -> die
        _ -> case snd (last xs) of
            Space -> die
            Newline -> die
            Indent -> die
    filterDoubleSpaces [] = xs
    filterDoubleSpaces ((_,Space):(_,Space):xs) = die
    filterDoubleSpaces (x:xs) = filterDoubleSpaces xs
    die = error $ "INTERNAL ERROR: sanity check fail\n" ++ show xs
sanityCheck :: [Pos Token] -> [Pos Token]
sanityCheck xs = (filterDoubleSpaces . filterEndspaces) xs
    where
    filterEndspaces [] = []
    filterEndspaces xs = case snd (head xs) of
        Space -> die
        Newline -> die
        Indent -> die
        Dedent -> die
        _ -> case snd (last xs) of
            Space -> die
            Newline -> die
            Indent -> die
    filterDoubleSpaces [] = xs
    filterDoubleSpaces ((_,Space):(_,Space):xs) = die
    filterDoubleSpaces (x:xs) = filterDoubleSpaces xs
    die = error $ "INTERNAL ERROR: sanity check fail\n" ++ show xs
sanityCheck xs = (filterDoubleSpaces . filterEndspaces) xs
    where
    filterEndspaces [] = []
    filterEndspaces xs = case snd (head xs) of
        Space -> die
        Newline -> die
        Indent -> die
        Dedent -> die
        _ -> case snd (last xs) of
            Space -> die
            Newline -> die
            Indent -> die
    filterDoubleSpaces [] = xs
    filterDoubleSpaces ((_,Space):(_,Space):xs) = die
    filterDoubleSpaces (x:xs) = filterDoubleSpaces xs
    die = error $ "INTERNAL ERROR: sanity check fail\n" ++ show xs