Skip to content

Instantly share code, notes, and snippets.

@arvidj
Created September 16, 2012 15:17
Show Gist options
  • Save arvidj/3732804 to your computer and use it in GitHub Desktop.
Save arvidj/3732804 to your computer and use it in GitHub Desktop.
lex-pass transformer: Kill trailing comma
module Transf.KillTrailingComma where
import Lang.Php
import TransfUtil
import qualified Data.Intercal as IC
transfs :: [Transf]
transfs = [
"kill-trailing-comma" -:- ftype -?-
"Kills trailing commas from Arrays."
-=- argless (lexPass $ killTrailingComma)]
-- optionally pretend we changed something to make this file count and force
-- rewrite.
killTrailingComma :: Ast -> Transformed Ast
killTrailingComma = modAll $ \ cStmt -> case cStmt of
StmtExpr (ExprArray a (Right (b, Just ws))) c d ->
let b' = init b ++ [(last b) { wsCapPost = ws}] in
(pure $ StmtExpr (ExprArray a (Right (b', Nothing))) c d)
_ -> transfNothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment