diff --git a/Setup.lhs b/Setup.lhs
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -13,6 +13,7 @@
 import System.FilePath ((</>))
 import Control.Exception ( IOException, try )
 import System.Directory (removeFile)
+import Data.Char
 
 main :: IO ()
 main = defaultMainWithHooks simpleUserHooks{ postBuild = myPostBuild,
@@ -23,16 +24,19 @@
 -- hack to turn cpp-style '# 27 "GenericTemplate.hs"' into 
 -- '{-# LINE 27 "GenericTemplate.hs" #-}'.
 mungeLinePragma line = case symbols line of
- ["#", number, string] | length string >= 2
-                      && head string == '"'
-                      && last string == '"'
-   -> case reads number of
-        [(n, "")] -> "{-# LINE " ++ show (n :: Int) ++ " " ++ string ++ " #-}"
-        _         -> line
+ syms | Just prag <- getLinePrag syms  -> prag
  -- Also convert old-style CVS lines, no idea why we do this...
  ("--":"$":"Id":":":_) -> filter (/='$') line
  (     "$":"Id":":":_) -> filter (/='$') line
  _ -> line
+
+getLinePrag :: [String] -> Maybe String
+getLinePrag ("#" : n : string : rest)
+  | length rest <= 1   -- clang puts an extra field
+  , length string >= 2 && head string == '"' && last string == '"'
+  , all isDigit n
+  = Just $ "{-# LINE " ++ n ++ " " ++ string ++ " #-}"
+getLinePrag other = Nothing
 
 symbols :: String -> [String]
 symbols cs = case lex cs of
diff --git a/alex.cabal b/alex.cabal
--- a/alex.cabal
+++ b/alex.cabal
@@ -1,11 +1,11 @@
 name: alex
-version: 3.1.2
+version: 3.1.3
 license: BSD3
 license-file: LICENSE
 copyright: (c) Chis Dornan, Simon Marlow
 author: Chris Dornan and Simon Marlow
 maintainer: Simon Marlow <marlowsd@gmail.com>
-bug-reports: mailto:marlowsd@gmail.com
+bug-reports: https://github.com/simonmar/alex/issues
 stability: stable
 homepage: http://www.haskell.org/alex/
 synopsis: Alex is a tool for generating lexical analysers in Haskell
@@ -15,6 +15,10 @@
   expressions and generates a Haskell module containing code
   for scanning text efficiently. It is similar to the tool
   lex or flex for C/C++.
+  .
+  Changes in 3.1.3:
+  .
+  * Fix for clang (XCode 5)
   .
   Changes in 3.1.2:
   .
diff --git a/dist/build/alex/alex-tmp/Parser.hs b/dist/build/alex/alex-tmp/Parser.hs
--- a/dist/build/alex/alex-tmp/Parser.hs
+++ b/dist/build/alex/alex-tmp/Parser.hs
@@ -21,7 +21,7 @@
 import qualified Data.Array as Happy_Data_Array
 import qualified GHC.Exts as Happy_GHC_Exts
 
--- parser produced by Happy Version 1.19.1
+-- parser produced by Happy Version 1.19.0
 
 newtype HappyAbsSyn  = HappyAbsSyn HappyAny
 #if __GLASGOW_HASKELL__ >= 607
@@ -919,9 +919,9 @@
 -- parse (a %partial parser).  We must ignore the saved token on the top of
 -- the stack in this case.
 happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) =
-        happyReturn1 ans
+	happyReturn1 ans
 happyAccept j tk st sts (HappyStk ans _) = 
-        (happyTcHack j (happyTcHack st)) (happyReturn1 ans)
+	(happyTcHack j (happyTcHack st)) (happyReturn1 ans)
 
 -----------------------------------------------------------------------------
 -- Arrays only: do the next action
@@ -929,35 +929,35 @@
 
 
 happyDoAction i tk st
-        = {- nothing -}
+	= {- nothing -}
 
 
-          case action of
-                0#           -> {- nothing -}
-                                     happyFail i tk st
-                -1#          -> {- nothing -}
-                                     happyAccept i tk st
-                n | LT(n,(0# :: Happy_GHC_Exts.Int#)) -> {- nothing -}
+	  case action of
+		0#		  -> {- nothing -}
+				     happyFail i tk st
+		-1# 	  -> {- nothing -}
+				     happyAccept i tk st
+		n | LT(n,(0# :: Happy_GHC_Exts.Int#)) -> {- nothing -}
 
-                                                   (happyReduceArr Happy_Data_Array.! rule) i tk st
-                                                   where rule = (Happy_GHC_Exts.I# ((Happy_GHC_Exts.negateInt# ((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#))))))
-                n                 -> {- nothing -}
+				     (happyReduceArr Happy_Data_Array.! rule) i tk st
+				     where rule = (Happy_GHC_Exts.I# ((Happy_GHC_Exts.negateInt# ((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#))))))
+		n		  -> {- nothing -}
 
 
-                                     happyShift new_state i tk st
+				     happyShift new_state i tk st
                                      where new_state = (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#))
    where off    = indexShortOffAddr happyActOffsets st
          off_i  = (off Happy_GHC_Exts.+# i)
-         check  = if GTE(off_i,(0# :: Happy_GHC_Exts.Int#))
+	 check  = if GTE(off_i,(0# :: Happy_GHC_Exts.Int#))
                   then EQ(indexShortOffAddr happyCheck off_i, i)
-                  else False
+		  else False
          action
           | check     = indexShortOffAddr happyTable off_i
           | otherwise = indexShortOffAddr happyDefActions st
 
 
 indexShortOffAddr (HappyA# arr) off =
-        Happy_GHC_Exts.narrow16Int# i
+	Happy_GHC_Exts.narrow16Int# i
   where
         i = Happy_GHC_Exts.word2Int# (Happy_GHC_Exts.or# (Happy_GHC_Exts.uncheckedShiftL# high 8#) low)
         high = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr (off' Happy_GHC_Exts.+# 1#)))
@@ -1018,9 +1018,9 @@
      = happyFail 0# tk st sts stk
 happyReduce k nt fn j tk st sts stk
      = case happyDrop (k Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) sts of
-         sts1@((HappyCons (st1@(action)) (_))) ->
-                let r = fn stk in  -- it doesn't hurt to always seq here...
-                happyDoSeq r (happyGoto nt j tk st1 sts1 r)
+	 sts1@((HappyCons (st1@(action)) (_))) ->
+        	let r = fn stk in  -- it doesn't hurt to always seq here...
+       		happyDoSeq r (happyGoto nt j tk st1 sts1 r)
 
 happyMonadReduce k nt fn 0# tk st sts stk
      = happyFail 0# tk st sts stk
@@ -1072,7 +1072,7 @@
 -- parse error if we are in recovery and we fail again
 happyFail 0# tk old_st _ stk@(x `HappyStk` _) =
      let i = (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# (i)) -> i }) in
---      trace "failing" $ 
+--	trace "failing" $ 
         happyError_ i tk
 
 {-  We don't need state discarding for our restricted implementation of
@@ -1081,16 +1081,16 @@
 
 -- discard a state
 happyFail  0# tk old_st (HappyCons ((action)) (sts)) 
-                                                (saved_tok `HappyStk` _ `HappyStk` stk) =
---      trace ("discarding state, depth " ++ show (length stk))  $
-        happyDoAction 0# tk action sts ((saved_tok`HappyStk`stk))
+						(saved_tok `HappyStk` _ `HappyStk` stk) =
+--	trace ("discarding state, depth " ++ show (length stk))  $
+	happyDoAction 0# tk action sts ((saved_tok`HappyStk`stk))
 -}
 
 -- Enter error recovery: generate an error token,
 --                       save the old token and carry on.
 happyFail  i tk (action) sts stk =
 --      trace "entering error recovery" $
-        happyDoAction 0# tk action sts ( (Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# (i))) `HappyStk` stk)
+	happyDoAction 0# tk action sts ( (Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# (i))) `HappyStk` stk)
 
 -- Internal happy errors:
 
@@ -1108,9 +1108,9 @@
 
 -----------------------------------------------------------------------------
 -- Seq-ing.  If the --strict flag is given, then Happy emits 
---      happySeq = happyDoSeq
+--	happySeq = happyDoSeq
 -- otherwise it emits
---      happySeq = happyDontSeq
+-- 	happySeq = happyDontSeq
 
 happyDoSeq, happyDontSeq :: a -> b -> b
 happyDoSeq   a b = a `seq` b
diff --git a/dist/build/alex/alex-tmp/Scan.hs b/dist/build/alex/alex-tmp/Scan.hs
--- a/dist/build/alex/alex-tmp/Scan.hs
+++ b/dist/build/alex/alex-tmp/Scan.hs
@@ -231,6 +231,7 @@
 
 
 
+-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
 #if __GLASGOW_HASKELL__ > 706
 #define GTE(n,m) (tagToEnum# (n >=# m))
 #define EQ(n,m) (tagToEnum# (n ==# m))
@@ -238,11 +239,11 @@
 #define GTE(n,m) (n >=# m)
 #define EQ(n,m) (n ==# m)
 #endif
-{-# LINE 50 "templates/GenericTemplate.hs" #-}
+{-# LINE 51 "templates/GenericTemplate.hs" #-}
 
 
 data AlexAddr = AlexA# Addr#
-
+-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
 #if __GLASGOW_HASKELL__ < 503
 uncheckedShiftL# = shiftL#
 #endif
@@ -280,6 +281,7 @@
 #else
   indexInt32OffAddr# arr off
 #endif
+
 
 
 
diff --git a/templates/GenericTemplate.hs b/templates/GenericTemplate.hs
--- a/templates/GenericTemplate.hs
+++ b/templates/GenericTemplate.hs
@@ -23,6 +23,7 @@
 #define ILIT(n) n#
 #define IBOX(n) (I# (n))
 #define FAST_INT Int#
+-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
 ALEX_IF_GHC_GT_706
 ALEX_DEFINE GTE(n,m) (tagToEnum# (n >=# m))
 ALEX_DEFINE EQ(n,m) (tagToEnum# (n ==# m))
@@ -50,7 +51,7 @@
 
 #ifdef ALEX_GHC
 data AlexAddr = AlexA# Addr#
-
+-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
 ALEX_IF_GHC_LT_503
 uncheckedShiftL# = shiftL#
 ALEX_ENDIF
@@ -93,6 +94,7 @@
 #endif
 
 #ifdef ALEX_GHC
+
 ALEX_IF_GHC_LT_503
 quickIndex arr i = arr ! i
 ALEX_ELSE
