Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firs try of ADT parser #99

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import System.IO

main :: IO ()
main = do
src <- readFile "System/FilePath/Internal.hs"
let tests = map renderTest $ concatMap parseTest $ lines src
src1 <- fmap lines $ readFile "System/FilePath/Internal.hs"
src2 <- fmap lines $ readFile "System/FilePath/Internal/Parser.hs"
let tests = map renderTest $ concatMap parseTest $ (src1++src2)
writeFileBinaryChanged "tests/TestGen.hs" $ unlines $
["-- GENERATED CODE: See ../Generate.hs"
,"module TestGen(tests) where"
,"import TestUtil"
,"import Data.List.NonEmpty (fromList)"
,"import System.FilePath.Internal.Parser"
,"import qualified System.FilePath.Windows as W"
,"import qualified System.FilePath.Posix as P"
,"{-# ANN module \"HLint: ignore\" #-}"
Expand Down Expand Up @@ -82,11 +85,26 @@ renderTest Test{..} = (body, code)

qualify :: PW -> String -> String
qualify pw str
| str `elem` fpops || (all isAlpha str && length str > 1 && str `notElem` prelude) = show pw ++ "." ++ str
| str `elem` fpops || (all isAlphaNum str && length str > 1 && str `notElem` prelude) = show pw ++ "." ++ str
| otherwise = str
where
prelude = ["elem","uncurry","snd","fst","not","null","if","then","else"
,"True","False","Just","Nothing","fromJust","concat","isPrefixOf","isSuffixOf","any","foldr"]
,"True","False","Just","Nothing","fromJust","concat","isPrefixOf","isSuffixOf","any","foldr","fromList"
,"parseDatastream"
,"getParse"
,"FileName"
,"parseFileName"
,"parseRelFilePath"
,"parseUNCShare"
,"endOfInput"
,"DS1"
,"DS2"
,"Rel1"
,"Rel2"
,"UnixSep"
,"WindowsSep"
,"UNCShare"
]
fpops = ["</>","<.>","-<.>"]


Expand Down
2 changes: 0 additions & 2 deletions System/FilePath/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ infixr 5 </>





---------------------------------------------------------------------
-- Platform Abstraction Methods (private)

Expand Down
Loading