Changeset 8729 for src/Pugs/Run/Args.hs
- Timestamp:
- 01/17/06 14:55:25 (3 years ago)
- Files:
-
- 1 modified
-
src/Pugs/Run/Args.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Run/Args.hs
r8726 r8729 33 33 > (-h -v -V) (-I) (-d) (-w) (-c) (-C) (--external) (-M) (-n -p) (-l -0 -e other) 34 34 35 Args -M, -n and -p are converted to -e scripts by joinDashE.35 Args -M, -n and -p are converted to -e scripts by desugarDashE. 36 36 -} 37 37 canonicalArgs :: [String] -> [String] 38 38 canonicalArgs x = concatMap procArg 39 . joinDashE 39 . concatDashE 40 . desugarDashE 40 41 . sortBy compareArgs 41 42 . gatherArgs … … 43 44 $ x 44 45 45 data Arg = File String | Switch Char | Opt String String 46 deriving Show 46 concatDashE :: [Arg] -> [Arg] 47 concatDashE (Opt "-e" e:xs) = (Opt "-e" $ concat (intersperse "\n" (e:map optArg es))) : rest 48 where 49 (es, rest) = partition isOptE xs 50 isOptE (Opt "-e" _) = True 51 isOptE _ = False 52 concatDashE (x:xs) = (x:concatDashE xs) 53 concatDashE xs = xs 54 55 data Arg 56 = File !String 57 | Switch !Char 58 | Opt { optFlag :: !String, optArg :: !String } 59 deriving Show 47 60 48 61 procArg :: Arg -> [String] … … 70 83 unpackOption opt 71 84 | Just short <- lookup ('-':opt) longOptions = [short] 72 | head opt `elem` composable = ('-':head opt:[]): unpackOption (tail opt)85 | head opt `elem` composable = ['-', head opt] : unpackOption (tail opt) 73 86 | Just (prefix, param) <- prefixOpt opt = ['-':prefix, param] 74 87 | otherwise = ['-':opt] … … 151 164 and "-p" into "-e" fragments 152 165 -} 153 joinDashE :: [Arg] -> [Arg]154 joinDashE [] = []155 joinDashE ((Switch 'p'):args) = joinDashE ((Opt "-e" "while ($_ = =<>) { $_ .= chomp;"):script++[(Opt "-e" "; say $_; }")]++rest)166 desugarDashE :: [Arg] -> [Arg] 167 desugarDashE [] = [] 168 desugarDashE ((Switch 'p'):args) = desugarDashE ((Opt "-e" "while ($_ = =<>) { $_ .= chomp;"):script++[(Opt "-e" "; say $_; }")]++rest) 156 169 where 157 170 (script,rest) = partition isDashE args 158 171 isDashE (Opt "-e" _) = True 159 172 isDashE (_) = False 160 joinDashE ((Switch 'n'):args) = joinDashE ((Opt "-e" "while ($_ = =<>) { $_ .= chomp;"):script++[(Opt "-e" "}")]++rest)173 desugarDashE ((Switch 'n'):args) = desugarDashE ((Opt "-e" "while ($_ = =<>) { $_ .= chomp;"):script++[(Opt "-e" "}")]++rest) 161 174 where 162 175 (script,rest) = partition isDashE args … … 168 181 -- "-e foo bar.p6" executes "foo" with @*ARGS[0] eq "bar.p6", 169 182 -- "-E foo bar.p6" executes "foo" and then bar.p6. 170 joinDashE ((Opt "-M" mod):args) = joinDashE ((Opt "-E" (";use " ++ mod ++ ";\n")):args)183 desugarDashE ((Opt "-M" mod):args) = desugarDashE ((Opt "-E" (";use " ++ mod ++ ";\n")):args) 171 184 172 185 -- Preserve the curious Perl5 behaviour: 173 186 -- perl -e 'print CGI->VERSION' -MCGI # works 174 187 -- perl print_cgi.pl -MCGI # fails 175 joinDashE (x@(Opt "-e" _):y@(Opt "-E" _):args) = joinDashE (y:x:args) 176 joinDashE ((Opt "-E" a):y@(Opt "-e" _):args) = joinDashE ((Opt "-e" a):y:args) 177 178 joinDashE ((Opt "-e" a):(Opt "-e" b):args) = 179 joinDashE (Opt "-e" combined:args) 180 where 181 combined = a++"\n"++b 182 joinDashE (x:xs) = [ x ] ++ joinDashE xs 188 desugarDashE (x@(Opt "-e" _):y@(Opt "-E" _):args) = desugarDashE (y:x:args) 189 desugarDashE ((Opt "-E" a):y@(Opt "-e" _):args) = desugarDashE ((Opt "-e" a):y:args) 190 desugarDashE (x:xs) = (x:desugarDashE xs)
