Skip to content

Commit

Permalink
Firs try of parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Dec 8, 2021
1 parent 3dbdea8 commit 16e5374
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 10 deletions.
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

0 comments on commit 16e5374

Please sign in to comment.