Permalink
Browse files

[wxhaskell-from-cvs @ 2003-10-23 09:08:09 by dleijen]

Initial support for #include files in the wxWindows API header files.

darcs-hash:20031023090818-deb31-d57af9fe022c2b2dde2acdd6f32b9c6d3e9d574b.gz
  • Loading branch information...
1 parent 590021f commit 98103060dd653dcfdf4321fdfefa2b01a461c003 dleijen committed Oct 23, 2003
Showing with 40 additions and 7 deletions.
  1. +3 −2 makefile
  2. +2 −2 wxdirect/src/Main.hs
  3. +35 −3 wxdirect/src/ParseC.hs
View
5 makefile
@@ -4,7 +4,7 @@
# See "license.txt" for more details.
#-----------------------------------------------------------------------
-# $Id: makefile,v 1.45 2003/10/21 15:04:09 dleijen Exp $
+# $Id: makefile,v 1.46 2003/10/23 09:08:09 dleijen Exp $
#--------------------------------------------------------------------------
# make [all] - build the libraries (in "lib").
@@ -153,7 +153,8 @@ WXC-SPECS-EIFFEL = \
wxc/eiffel/wxc_defs.e wxc/eiffel/ewxw/wx_defs.e
WXC-SPECS-HEADER = \
- wxc/include/wxc.h wxc/include/ewxw/wxc_glue.h
+ wxc/include/wxc.h
+ # wxc/include/ewxw/wxc_glue.h
# distributed in a source distribution
WXC-SRCS=$(wildcard wxc/src/*.cpp) $(wildcard wxc/src/ewxw/*.cpp) $(wildcard wxc/src/ewxw/*.h)\
View
4 wxdirect/src/Main.hs
@@ -88,8 +88,8 @@ getDefaultHeaderFiles :: IO [FilePath]
getDefaultHeaderFiles
= do wxcdir <- getWxcDir
return [wxcdir ++ "/include/wxc.h"
- -- wxcdir ++ "/ewxw/eiffel/ewxw_glue.h"
- ,wxcdir ++ "/ewxw/eiffel/wxc_glue.h"
+ -- , wxcdir ++ "/ewxw/eiffel/ewxw_glue.h"
+ -- , wxcdir ++ "/ewxw/eiffel/wxc_glue.h"
]
View
38 wxdirect/src/ParseC.hs
@@ -12,6 +12,7 @@
-----------------------------------------------------------------------------------------
module ParseC( parseC ) where
+import Char( isSpace )
import List( isPrefixOf )
import Text.ParserCombinators.Parsec
import qualified Text.ParserCombinators.Parsec.Token as P
@@ -24,12 +25,43 @@ import Types
-----------------------------------------------------------------------------------------}
parseC :: FilePath -> IO [Decl]
parseC fname
- = do putStrLn ("parsing: " ++ fname)
- input <- readFile fname
- declss <- mapM (parseDecl fname) (pairComments (lines input))
+ = do lines <- readHeaderFile fname
+ declss <- mapM (parseDecl fname) (pairComments lines)
-- putStrLn ("ok.")
return (concat declss)
+-- flaky but suitable.
+readHeaderFile :: FilePath -> IO [String]
+readHeaderFile fname
+ = do putStrLn ("parsing: " ++ fname)
+ input <- readFile fname
+ lls <- mapM readIncludeFile (flattenComments (lines input))
+ return (concat lls)
+ where
+ pathName
+ = reverse $ dropWhile (\c -> not (elem c "/\\")) $ reverse fname
+
+ readIncludeFile line
+ | isPrefixOf "#include \"" line
+ = readHeaderFile (pathName ++ includePath)
+ where
+ includePath = takeWhile (/='"') $ tail $ dropWhile (/='"') line
+
+ readIncludeFile line
+ = return [line]
+
+-- flaky, but suitable
+flattenComments :: [String] -> [String]
+flattenComments lines
+ = case lines of
+ (('/':'*':xs):xss) -> let (incomment,comment:rest) = span (not . endsComment) lines
+ in (concat (incomment ++ [comment]) : flattenComments rest)
+ xs : xss -> xs : flattenComments xss
+ [] -> []
+ where
+ endsComment line = isPrefixOf "/*" (dropWhile isSpace (reverse line))
+
+
pairComments :: [String] -> [(String,String)]
pairComments lines
= case lines of

0 comments on commit 9810306

Please sign in to comment.