Permalink
Browse files

lexer, xml extension support, massive simplification and separation

Summary: this will become lex-pass 2.1 prob after it's tested more

Reviewed By: eletuchy

Test Plan: lex-pass id on codebase

Revert Plan: ok
  • Loading branch information...
1 parent 4689f2a commit eaf4b2304865b6249280bf09fbfad3d5ad67ba21 Daniel Corson committed Oct 24, 2009
View
@@ -5,4 +5,3 @@ cd src
./do-codegen
cd ..
cabal install --enable-optimization=2 --global --root-cmd=sudo
-sudo cp src/php_lex_stdin /usr/local/bin
View
@@ -7,11 +7,28 @@ synopsis: perform lexically-aware transformational passes over a
codebase, limiting number of files changed per run to try to
minimize conflicts in a rapidly changing development
environment
-build-depends: FUtil, HSH >= 2, base, binary, derive, directory, filepath,
- mtl, parsec, process
build-type: Simple
-Cabal-Version: >= 1.2
+cabal-version: >= 1.6
+
+flag test-only
+ description: Build test executable instead of main program
+ default: False
+
+executable lex-pass
+ if flag(test-only)
+ buildable: False
+ hs-source-dirs: src
+ main-is: Main.hs
+ build-depends: FUtil, HSH >= 2, base >= 4, binary, bytestring, containers,
+ derive, directory, filepath, mtl, parsec >= 2 && < 3, process,
+ syb
+
+executable lex-pass-test
+ if !flag(test-only)
+ buildable: False
+ hs-source-dirs: src
+ main-is: Lang/Php/Ast/Test.hs
+ build-depends: FUtil, HSH >= 2, base >= 4, binary, bytestring, containers,
+ derive, directory, filepath, mtl, parsec >= 2 && < 3, process,
+ syb
-executable: lex-pass
-hs-source-dirs: src
-main-is: Main.hs
View
@@ -0,0 +1,44 @@
+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
+
+module Common (
+ module Text.ParserCombinators.Parsec,
+ Oper, Parse(..), Unparse(..)) where
+
+import Control.Applicative hiding (many, (<|>))
+import Control.Monad
+import Text.ParserCombinators.Parsec hiding (State, parse, choice)
+import Text.ParserCombinators.Parsec.Expr
+
+-- parsec 2 vs 3 stuff
+
+type Oper a = Operator Char () a
+
+instance Applicative (GenParser Char ()) where
+ pure = return
+ (<*>) = ap
+
+class Parse a where
+ parse :: Parser a
+
+class Unparse a where
+ unparse :: a -> String
+
+instance (Parse a) => Parse [a] where
+ parse = many parse
+
+instance (Parse a, Parse b) => Parse (Either a b) where
+ parse = Left <$> parse <|> Right <$> parse
+
+instance (Unparse a, Unparse b) => Unparse (Either a b) where
+ unparse (Left a) = unparse a
+ unparse (Right a) = unparse a
+
+instance (Unparse a, Unparse b) => Unparse (a, b) where
+ unparse (a, b) = unparse a ++ unparse b
+
+instance (Unparse a) => Unparse [a] where
+ unparse = concatMap unparse
+
+instance (Unparse a) => Unparse (Maybe a) where
+ unparse = maybe "" unparse
+
View
@@ -0,0 +1,10 @@
+module Config where
+
+import Data.List
+import HSH
+
+-- put any custom default excluded directories or aliased filetypes here etc
+sourceFiles :: [String] -> String -> IO [String]
+sourceFiles ftypes dir = run ("find", dir:args) where
+ args = intercalate ["-or"] [["-iname", "*." ++ ftype] | ftype <- ftypes]
+
View
@@ -2,20 +2,20 @@
module Data.Intercal where
+import Common
import Control.Arrow
import Control.Applicative
-import Control.Monad hiding (mapM)
+import Control.Monad
import Data.Binary
-import Data.Generics
-import Prelude hiding (concatMap, map, mapM)
+import Data.Data
+import Prelude hiding (concatMap, map)
import qualified Prelude
-import Text.Parsec
data Intercal a b = Intercal a b (Intercal a b) | Interend a
deriving (Eq, Show, Typeable, Data)
-- we're using method that should be faster-but-bigger instead of storing
--- length. is this the same as the derive one, should we just use that?
+-- length. this is probably the same as the derive one, just use that?
instance (Binary a, Binary b) => Binary (Intercal a b) where
put (Intercal x y r) = put (0 :: Word8) >> put x >> put y >> put r
put (Interend x) = put (1 :: Word8) >> put x
@@ -25,15 +25,25 @@ instance (Binary a, Binary b) => Binary (Intercal a b) where
0 -> liftM3 Intercal get get get
1 -> liftM Interend get
-intercalParser :: Parsec [t] () a -> Parsec [t] () b ->
- Parsec [t] () (Intercal a b)
+intercalParser :: Parser a -> Parser b -> Parser (Intercal a b)
intercalParser a b = do
aRes <- a
bResMb <- optionMaybe b
case bResMb of
Nothing -> return $ Interend aRes
Just bRes -> liftM (Intercal aRes bRes) $ intercalParser a b
+instance (Parse a, Parse b) => Parse (Intercal a b) where
+ parse = intercalParser parse parse
+
+intercalUnparser :: (a -> String) -> (b -> String) -> Intercal a b -> String
+intercalUnparser f g i =
+ Prelude.concatMap (\ (a, b) -> f a ++ g b) xInit ++ f xEnd where
+ (xInit, xEnd) = breakEnd i
+
+instance (Unparse a, Unparse b) => Unparse (Intercal a b) where
+ unparse = intercalUnparser unparse unparse
+
concatMapM :: (Monad m) => (a -> b -> a -> m (Intercal a b)) ->
Intercal a b -> m (Intercal a b)
concatMapM _f i@(Interend _) = return i
@@ -91,3 +101,7 @@ mapA f g (Intercal x y rest) = liftA3 Intercal (f x) (g y) (mapA f g rest)
singleton :: a -> b -> a -> Intercal a b
singleton a1 b a2 = Intercal a1 b $ Interend a2
+append :: a -> b -> Intercal b a -> Intercal b a
+append a b (Interend b0) = Intercal b0 a $ Interend b
+append a b (Intercal b0 a0 rest) = Intercal b0 a0 $ append a b rest
+
View
@@ -1,9 +1,11 @@
module Lang.Php (
module Lang.Php.Ast,
- module Lang.Php.Tok,
- module Lang.Php.Transf
+ module Lang.Php.Transf,
+ ftype
) where
import Lang.Php.Ast
-import Lang.Php.Tok
import Lang.Php.Transf
+
+ftype = ["php"]
+
Oops, something went wrong. Retry.

0 comments on commit eaf4b23

Please sign in to comment.