Ticket #205: 0001-Haskell-support-take-two.patch
| File 0001-Haskell-support-take-two.patch, 13.4 kB (added by tux_rocker, 2 years ago) |
|---|
-
a/ext/ohcount_native/generator.rb
old new 34 34 java = CMonoglot.new("java", '//', [e('/*'), e('*/')], true, false) 35 35 javascript = CMonoglot.new("javascript", '//', [e('/*'), e('*/')], true, true) 36 36 emacslisp = LineCommentMonoglot.new("emacslisp", ";") 37 haskell = CMonoglot.new("haskell", '--', [e('{-'), e('-}')], true, false) 37 38 lisp = LineCommentMonoglot.new("lisp", ";") 38 39 lua = CMonoglot.new("lua", '--', nil, true, true) 39 40 matlab = CMonoglot.new("matlab", '#|%', ['{%', '%}'], false,true) … … 75 76 java , 76 77 javascript , 77 78 emacslisp , 79 haskell, 78 80 lisp , 79 81 lua , 80 82 matlab, -
a/lib/ohcount/detector.rb
old new 120 120 '.h' => :disambiguate_h_header, 121 121 '.hpp' => "cncpp", 122 122 '.h++' => "cncpp", 123 '.hs' => "haskell", 123 124 '.hxx' => "cncpp", 124 125 '.hh' => "cncpp", 125 126 '.hrl' => "erlang", -
/dev/null
old new -
/dev/null
old new 1 module Gnutella.Misc where 2 import Data.ByteString(ByteString) 3 import qualified Data.ByteString as BS 4 import Data.Bits 5 import Data.Word 6 import Text.Read 7 import Data.Char(isNumber) 8 import Data.List(intersperse) 9 import Network 10 import Network.BSD(getHostByName, HostEntry(..)) 11 import Network.Socket(HostAddress(..)) 12 import Debug.Trace 13 composeWord32 :: ByteString -> Word32 14 composeWord32 s = shiftL byte4 24 + shiftL byte3 16 + shiftL byte2 8 + byte1 15 where byte1, byte2, byte3, byte4 :: Word32 16 [byte1, byte2, byte3, byte4] = map fromIntegral $ BS.unpack (BS.take 4 s) 17 word32ToWord8s :: Word32 -> (Word8, Word8, Word8, Word8) 18 word32ToWord8s w = (fromIntegral (w .&. 0x000000ff) 19 ,fromIntegral (shiftR w 8 .&. 0x000000ff) 20 ,fromIntegral (shiftR w 16 .&. 0x000000ff) 21 ,fromIntegral (shiftR w 24 .&. 0x000000ff) 22 ) 23 parseHostnameWithPort :: String -> IO (Maybe ((Word8, Word8, Word8, Word8) 24 ,PortNumber)) 25 parseHostnameWithPort str = do maybeHostName <- stringToIP hostNameStr 26 return $ (do portNum <- maybePortNum 27 hostName <- maybeHostName 28 return (hostName, portNum) 29 ) 30 where hostNameStr = takeWhile (/=':') str 31 maybePortNum = case tail (dropWhile (/=':') str) of 32 [] -> Just $ 6346 33 s -> case reads s of 34 [] -> Nothing 35 (x:xs) -> Just $ fromIntegral $ fst x 36 ipStringToBytes :: String -> Maybe (Word8, Word8, Word8, Word8) 37 ipStringToBytes s = 38 let ipBytesStrings = splitAtDots s 39 in if all (all isNumber) ipBytesStrings 40 then let bytesList = map (fst . head . reads) ipBytesStrings 41 in Just (bytesList!!0 42 ,bytesList!!1 43 ,bytesList!!2 44 ,bytesList!!3 45 ) 46 else Nothing 47 where splitAtDots s = foldr (\c (n:nums) -> if c == '.' 48 then [] : n : nums 49 else (c:n) : nums 50 ) [[]] s 51 ipBytesToString :: (Word8, Word8, Word8, Word8) -> String 52 ipBytesToString (b1, b2, b3, b4) = 53 concat $ intersperse "." $ map show [b1, b2, b3, b4] 54 stringToIP :: String -> IO (Maybe (Word8, Word8, Word8, Word8)) 55 stringToIP hostName = case ipStringToBytes hostName of 56 Just a -> return (Just a) 57 Nothing -> do hostent <- getHostByName hostName 58 let ipWord32 = head (hostAddresses hostent) 59 ipWord8s = word32ToWord8s ipWord32 60 return (Just ipWord8s) 61 instance Read PortNumber where 62 readsPrec i = map (\(a, b) -> (fromIntegral a, b)) . (readsPrec i :: ReadS Word16) -
/dev/null
old new 1 {-| 2 This module contains some functions that are useful in several places in the 3 program and don't belong to one specific other module. 4 -} 5 {-| 6 Maakt van vier bytes een Word32. Gaat ervan uit dat die vier bytes little-endian achter elkaar 7 staan. Als de gegeven string korter is dan 4 bytes, termineert de functie. Als de string langer 8 is, worden alle bytes voorbij de vierde genegeerd. 9 -} 10 {-| 11 Turns a Word32 into a tuple of Word8s. The tuple is little-endian: the least 12 significant octet comes first. 13 -} 14 {-| 15 Parses a host specification in the "name:12345"-style notation into a hostname 16 and a port number. 17 As a rather special feature, it returns 6346 as the port number when there is 18 no port specified. When there is a port specified, but it is unparseable, it 19 returns Nothing. 20 -} 21 {-| 22 Translates a string, representing an IP address, to a list of bytes. 23 Returns Nothing when the string does not represent an IP address in xxx.xxx.xxx.xxx format 24 -} 25 -- Again, hugs won't let us use regexes where they would be damn convenient 26 {-| 27 Translates a list of bytes representing an IP address (big endian) to a string 28 in the xxx.xxx.xxx.xxx format. 29 -} 30 {-| 31 Takes a String that's either an IP address or a hostname, and returns you the 32 IP address as a list of 4 bytes (in big-endian byte order). It returns Nothing 33 if there is no parse for the string as IP address and the hostname can't be 34 found. 35 -} 36 -- used in reading the hostcache -
/dev/null
old new -
/dev/null
old new 1 {-| 2 -} -
/dev/null
old new 1 {-| 2 This module contains some functions that are useful in several places in the 3 program and don't belong to one specific other module. 4 -} 5 module Gnutella.Misc where 6 7 import Data.ByteString(ByteString) 8 import qualified Data.ByteString as BS 9 import Data.Bits 10 import Data.Word 11 import Text.Read 12 import Data.Char(isNumber) 13 import Data.List(intersperse) 14 import Network 15 import Network.BSD(getHostByName, HostEntry(..)) 16 import Network.Socket(HostAddress(..)) 17 import Debug.Trace 18 19 {-| 20 Maakt van vier bytes een Word32. Gaat ervan uit dat die vier bytes little-endian achter elkaar 21 staan. Als de gegeven string korter is dan 4 bytes, termineert de functie. Als de string langer 22 is, worden alle bytes voorbij de vierde genegeerd. 23 -} 24 composeWord32 :: ByteString -> Word32 25 composeWord32 s = shiftL byte4 24 + shiftL byte3 16 + shiftL byte2 8 + byte1 26 where byte1, byte2, byte3, byte4 :: Word32 27 [byte1, byte2, byte3, byte4] = map fromIntegral $ BS.unpack (BS.take 4 s) 28 29 {-| 30 Turns a Word32 into a tuple of Word8s. The tuple is little-endian: the least 31 significant octet comes first. 32 -} 33 word32ToWord8s :: Word32 -> (Word8, Word8, Word8, Word8) 34 word32ToWord8s w = (fromIntegral (w .&. 0x000000ff) 35 ,fromIntegral (shiftR w 8 .&. 0x000000ff) 36 ,fromIntegral (shiftR w 16 .&. 0x000000ff) 37 ,fromIntegral (shiftR w 24 .&. 0x000000ff) 38 ) 39 40 {-| 41 Parses a host specification in the "name:12345"-style notation into a hostname 42 and a port number. 43 44 As a rather special feature, it returns 6346 as the port number when there is 45 no port specified. When there is a port specified, but it is unparseable, it 46 returns Nothing. 47 -} 48 parseHostnameWithPort :: String -> IO (Maybe ((Word8, Word8, Word8, Word8) 49 ,PortNumber)) 50 parseHostnameWithPort str = do maybeHostName <- stringToIP hostNameStr 51 return $ (do portNum <- maybePortNum 52 hostName <- maybeHostName 53 return (hostName, portNum) 54 ) 55 where hostNameStr = takeWhile (/=':') str 56 maybePortNum = case tail (dropWhile (/=':') str) of 57 [] -> Just $ 6346 58 s -> case reads s of 59 [] -> Nothing 60 (x:xs) -> Just $ fromIntegral $ fst x 61 62 {-| 63 Translates a string, representing an IP address, to a list of bytes. 64 Returns Nothing when the string does not represent an IP address in xxx.xxx.xxx.xxx format 65 -} 66 ipStringToBytes :: String -> Maybe (Word8, Word8, Word8, Word8) 67 -- Again, hugs won't let us use regexes where they would be damn convenient 68 ipStringToBytes s = 69 let ipBytesStrings = splitAtDots s 70 in if all (all isNumber) ipBytesStrings 71 then let bytesList = map (fst . head . reads) ipBytesStrings 72 in Just (bytesList!!0 73 ,bytesList!!1 74 ,bytesList!!2 75 ,bytesList!!3 76 ) 77 else Nothing 78 where splitAtDots s = foldr (\c (n:nums) -> if c == '.' 79 then [] : n : nums 80 else (c:n) : nums 81 ) [[]] s 82 83 {-| 84 Translates a list of bytes representing an IP address (big endian) to a string 85 in the xxx.xxx.xxx.xxx format. 86 -} 87 ipBytesToString :: (Word8, Word8, Word8, Word8) -> String 88 ipBytesToString (b1, b2, b3, b4) = 89 concat $ intersperse "." $ map show [b1, b2, b3, b4] 90 91 {-| 92 Takes a String that's either an IP address or a hostname, and returns you the 93 IP address as a list of 4 bytes (in big-endian byte order). It returns Nothing 94 if there is no parse for the string as IP address and the hostname can't be 95 found. 96 -} 97 stringToIP :: String -> IO (Maybe (Word8, Word8, Word8, Word8)) 98 stringToIP hostName = case ipStringToBytes hostName of 99 Just a -> return (Just a) 100 Nothing -> do hostent <- getHostByName hostName 101 let ipWord32 = head (hostAddresses hostent) 102 ipWord8s = word32ToWord8s ipWord32 103 return (Just ipWord8s) 104 105 -- used in reading the hostcache 106 instance Read PortNumber where 107 readsPrec i = map (\(a, b) -> (fromIntegral a, b)) . (readsPrec i :: ReadS Word16) 108 -
/dev/null
old new 1 {-| 2 3 -} 4 -
/dev/null
old new 1 # This has been shamelessly copied from java_test.rb because my Ruby is not so 2 # good and I don't really know what people expect from a Ohcount language test 3 # -- Reinier Lamers 2008-01-19 4 require File.dirname(__FILE__) + '/../test_helper' 5 6 class Ohcount::HaskellTest < Ohcount::Test 7 def test_comments 8 lb = [Ohcount::LanguageBreakdown.new("haskell", "", "--comment", 0)] 9 assert_equal lb, Ohcount::parse(" --comment", "haskell") 10 end 11 12 def test_comprehensive 13 verify_parse("haskell1.hs") 14 end 15 16 def test_comprehensive_with_carriage_returns 17 verify_parse("haskell2.hs") 18 end 19 end 20 21 22