root/src/gen_prelude.hs

Revision 17129, 1.5 kB (checked in by diakopter, 15 months ago)

Fixed a typo. Look! I modified a .hs file! \nI'm now a Haskell programmer! Oh wait, it's just a comment block...

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1{-# OPTIONS_GHC -fglasgow-exts -O0 #-}
2
3{-|
4    Prelude generator.
5-}
6
7{-
8I'd do this in Perl, but presumably show escapes nasty things I didn't
9think about.
10
11Unfortunately, this doesn't put literal newlines in the output. There's a
12bug in any(The Haskell Report, sec. 2.6; GHC; my understanding) regarding
13strings with gaps, when between the gaps there is an empty line. Fixes
14welcome :-)
15
16-}
17
18module Main where
19import System (getArgs)
20
21main :: IO ()
22main = 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
35preludeIntro :: String -> String
36preludeIntro 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"
Note: See TracBrowser for help on using the browser.