Changeset 8315 for src/Pugs.hs

Show
Ignore:
Timestamp:
12/20/05 07:11:45 (3 years ago)
Author:
autrijus
Message:

* fix the "newline causes use to belong in different namespaces"

bug mentioned by clkao; in -C and -B modes pugs inlines all use
statements in the beginning of lines _except_ when it occurs on
the first line, and it forgets to close over the scope in {...}
brackets. Fix both.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs.hs

    r8153 r8315  
    7979 
    8080-- -CPIL1.Perl5 outputs PIL formatted as Perl 5. 
    81 run ("-C":backend:args) | map toUpper backend == "JS" = do 
     81run ("-C":backend:args) | map toLower backend == "js" = do 
    8282    exec <- getArg0 
    8383    doHelperRun "JS" ("--compile-only":("--pugs="++exec):args) 
    84 run ("-C":backend:"-e":prog:_)           = doCompileDump backend "-e" prog 
    85 run ("-C":backend:file:_)                = slurpFile file >>= doCompileDump backend file 
     84run ("-C":backend:"-e":prog:_)           = withInlinedIncludes prog >>= doCompileDump backend "-e" 
     85run ("-C":backend:file:_)                = readFile file >>= withInlinedIncludes >>= doCompileDump backend file 
    8686 
    8787run ("-B":backend:_) | (== map toLower backend) `any` ["js","perl5"] = do 
     
    8989    args <- getArgs 
    9090    doHelperRun backend (("--pugs="++exec):args) 
    91 run ("-B":backend:"-e":prog:_)           = doCompileRun backend "-e" prog 
    92 run ("-B":backend:file:_)                = slurpFile file >>= doCompileRun backend file 
     91run ("-B":backend:"-e":prog:_)           = withInlinedIncludes prog >>= doCompileRun backend "-e" 
     92run ("-B":backend:file:_)                = readFile file >>= withInlinedIncludes >>= doCompileRun backend file 
    9393 
    9494run ("--external":mod:"-e":prog:_)    = doExternal mod "-e" prog 
     
    417417    evalParrotFile "a.pir" 
    418418 
    419 slurpFile :: FilePath -> IO String 
    420 slurpFile file = do 
    421     prog <- readFile file 
     419withInlinedIncludes :: String -> IO String 
     420withInlinedIncludes prog = do 
    422421    libs <- getLibs 
    423422    expandInc libs prog 
    424423    where 
    425424    expandInc :: [FilePath] -> String -> IO String 
    426     expandInc incs str = case breakOnGlue "\nuse " str of 
    427         Nothing -> case breakOnGlue "\nrequire " str of 
     425    expandInc incs str = case breakOnGlue "\nuse " ('\n':str) of 
     426        Nothing -> case breakOnGlue "\nrequire " ('\n':str) of 
    428427            Nothing -> return str 
    429428            Just (pre, post) -> do 
     
    436435            mod'    <- includeInc incs mod 
    437436            rest'   <- expandInc incs rest 
    438             return $ pre ++ mod' ++ rest' 
     437            return $ pre ++ "\n{" ++ mod' ++ "\n}\n" ++ rest' 
    439438    includeInc :: [FilePath] -> String -> IO String 
    440439    includeInc _ ('v':_) = return []