| 1 | {-# OPTIONS_GHC -fglasgow-exts -O0 #-} |
|---|
| 2 | |
|---|
| 3 | {-| |
|---|
| 4 | Prelude generator. |
|---|
| 5 | -} |
|---|
| 6 | |
|---|
| 7 | {- |
|---|
| 8 | I'd do this in Perl, but presumably show escapes nasty things I didn't |
|---|
| 9 | think about. |
|---|
| 10 | |
|---|
| 11 | Unfortunately, this doesn't put literal newlines in the output. There's a |
|---|
| 12 | bug in any(The Haskell Report, sec. 2.6; GHC; my understanding) regarding |
|---|
| 13 | strings with gaps, when between the gaps there is an empty line. Fixes |
|---|
| 14 | welcome :-) |
|---|
| 15 | |
|---|
| 16 | -} |
|---|
| 17 | |
|---|
| 18 | module Main where |
|---|
| 19 | import System (getArgs) |
|---|
| 20 | |
|---|
| 21 | main :: IO () |
|---|
| 22 | main = do |
|---|
| 23 | [moduleName] <- getArgs |
|---|
| 24 | putStr $ preludeIntro moduleName |
|---|
| 25 | str <- getContents |
|---|
| 26 | let lns = filter notComment . lines $ str |
|---|
| 27 | putStrLn . unlines . map (\ln -> " , " ++ show ln) $ lns |
|---|
| 28 | putStrLn " ]\n" |
|---|
| 29 | where |
|---|
| 30 | notComment ('#':_) = False |
|---|
| 31 | notComment (' ':cs) = notComment cs |
|---|
| 32 | notComment ('\t':cs) = notComment cs |
|---|
| 33 | notComment _ = True |
|---|
| 34 | |
|---|
| 35 | preludeIntro :: String -> String |
|---|
| 36 | preludeIntro moduleName = "\ |
|---|
| 37 | \{-# OPTIONS -fglasgow-exts #-}\n\ |
|---|
| 38 | \ \n\ |
|---|
| 39 | \{-\n\ |
|---|
| 40 | \ *** NOTE ***\n\ |
|---|
| 41 | \ DO NOT EDIT THIS FILE.\n\ |
|---|
| 42 | \ This module is automatically generated by src/gen_prelude.hs.\n\ |
|---|
| 43 | \-}\n\ |
|---|
| 44 | \ \n\ |
|---|
| 45 | \{-|\n\ |
|---|
| 46 | \ Perl 6 Prelude.\n\ |
|---|
| 47 | \ \n\ |
|---|
| 48 | \> The world was fair, the mountains tall,\n\ |
|---|
| 49 | \> In Eldar Days before the fall\n\ |
|---|
| 50 | \> Of mighty kings in Nargothrond\n\ |
|---|
| 51 | \> And Gondolin, who now beyond\n\ |
|---|
| 52 | \> The Western Seas have passed away:\n\ |
|---|
| 53 | \> The world was fair in Durin's day.\n\ |
|---|
| 54 | \ \n\ |
|---|
| 55 | \-}\n\ |
|---|
| 56 | \ \n\ |
|---|
| 57 | \ \n\ |
|---|
| 58 | \module " ++ moduleName ++ " (\n\ |
|---|
| 59 | \ preludeStr\n\ |
|---|
| 60 | \) where\n\ |
|---|
| 61 | \ \n\ |
|---|
| 62 | \preludeStr :: String\n\ |
|---|
| 63 | \preludeStr = unlines\n\ |
|---|
| 64 | \ [ \"\"\n" |
|---|