evalCompArgs cmdFn al = evalCTokens al [] where
    evalCTokens []     !acc = return $ reverse acc
    evalCTokens (x:xs) !acc = case x of
            Lit s         -> next s
            CmdTok t      -> cmdFn t >>= next
            Block o       -> next o
            VarRef vn     -> varGetNS vn >>= next
            ArrRef ns n i -> do
                 ni <- evalArgs_ [i] >>= return . T.asBStr . head
                 varGetNS (NSQual ns (arrName n ni)) >>= next
            CatLst l      -> evalArgs_ l >>= next . T.fromBStr . B.concat . map T.asBStr
            ExpTok t      -> do
                 [rs] <- evalArgs_ [t]
                 l <- T.asList rs
                 evalCTokens xs ((reverse l) ++ acc)
     where next !r = evalCTokens xs (r:acc)
           {-# INLINE next #-}
           evalArgs_ args = evalCTokens args []
evalCompArgs cmdFn al = evalCTokens al [] where
    evalCTokens []     !acc = return $ reverse acc
    evalCTokens (x:xs) !acc = case x of
            Lit s         -> next s
            CmdTok t      -> cmdFn t >>= next
            Block o       -> next o
            VarRef vn     -> varGetNS vn >>= next
            ArrRef ns n i -> do
                 ni <- evalArgs_ [i] >>= return . T.asBStr . head
                 varGetNS (NSQual ns (arrName n ni)) >>= next
            CatLst l      -> evalArgs_ l >>= next . T.fromBStr . B.concat . map T.asBStr
            ExpTok t      -> do
                 [rs] <- evalArgs_ [t]
                 l <- T.asList rs
                 evalCTokens xs ((reverse l) ++ acc)
     where next !r = evalCTokens xs (r:acc)
           {-# INLINE next #-}
           evalArgs_ args = evalCTokens args []
evalCompArgs cmdFn al = evalCTokens al [] where
    evalCTokens []     !acc = return $ reverse acc
    evalCTokens (x:xs) !acc = case x of
            Lit s         -> next s
            CmdTok t      -> cmdFn t >>= next
            Block o       -> next o
            VarRef vn     -> varGetNS vn >>= next
            ArrRef ns n i -> do
                 ni <- evalArgs_ [i] >>= return . T.asBStr . head
                 varGetNS (NSQual ns (arrName n ni)) >>= next
            CatLst l      -> evalArgs_ l >>= next . T.fromBStr . B.concat . map T.asBStr
            ExpTok t      -> do
                 [rs] <- evalArgs_ [t]
                 l <- T.asList rs
                 evalCTokens xs ((reverse l) ++ acc)
     where next !r = evalCTokens xs (r:acc)
           {-# INLINE next #-}
           evalArgs_ args = evalCTokens args []