Created
November 6, 2017 04:37
-
-
Save remysucre/0eae2ee40e4abb4c48a2c8b429eb5569 to your computer and use it in GitHub Desktop.
srcloc for bangs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module Main where | |
import Language.Haskell.Exts | |
import Language.Haskell.Exts.Syntax | |
import Data.Generics.Uniplate.DataOnly | |
main :: IO () | |
main = do | |
ParseOk s <- parseFile "/Users/rem/exp/app/Main.hs" | |
let !locs = [ l | PBangPat l p <- universeBi s] :: [SrcSpanInfo] | |
print locs |
Nvm you don't need to -1, the first column is exactly where the bang is.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This programs prints out a list of the location of the bang patterns in a file. When ran on itself, it prints out
[SrcSpanInfo {srcInfoSpan = SrcSpan "/Users/rem/exp/app/Main.hs" 12 7 12 12, srcInfoPoints = [SrcSpan "/Users/rem/exp/app/Main.hs" 12 7 12 8]}]
, which means there's a bang around the pattern on line 12 from column 7 to column 12 (loc). Then to find out the exact location of the bang itself in the source just take the first column number and -1.