rightRecursive :: [Token] -> ([Token] -> ParserResult) -> Token
                  -> (Ast -> Ast -> Ast) -> ParserResult
rightRecursive tokens parsingFunc separator astType = do
    (aa, ta) <- manySep tokens parsingFunc separator
    return (buildTree aa, ta)
    where
        buildTree subList =
            if length subList == 1 then head subList
            else astType (head subList) (buildTree $ tail subList)


-- Generate error handler when a matcher fails
rightRecursive :: [Token] -> ([Token] -> ParserResult) -> Token
                  -> (Ast -> Ast -> Ast) -> ParserResult
rightRecursive tokens parsingFunc separator astType = do
    (aa, ta) <- manySep tokens parsingFunc separator
    return (buildTree aa, ta)
    where
        buildTree subList =
            if length subList == 1 then head subList
            else astType (head subList) (buildTree $ tail subList)


-- Generate error handler when a matcher fails
rightRecursive tokens parsingFunc separator astType = do
    (aa, ta) <- manySep tokens parsingFunc separator
    return (buildTree aa, ta)
    where
        buildTree subList =
            if length subList == 1 then head subList
            else astType (head subList) (buildTree $ tail subList)


-- Generate error handler when a matcher fails