Commit 1a8aa318 authored by Michael Hanus's avatar Michael Hanus
Browse files

curry preprocessor generalized to include more preprocessing targets

parent ceb3b8c9
# intermediate files
*~
.curry
*.state
Curry_Main_Goal.curry
# executables
......@@ -11,7 +10,7 @@ browser/SourceProgGUI
CASS/cass
CASS/cass_worker
curry2js/Curry2JS
currypp/Translator
currypp/Main
currydoc/CurryDoc
currytest/CurryTest
createmakefile/CreateMakefile
......
{-# OPTIONS_CYMAKE -F --pgmF=currypp #-}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=--foreigncode #-}
------------------------------------------------------------------------------
--- This program contains some examples for integrated code to format strings.
......
{-# OPTIONS_CYMAKE -F --pgmF=currypp #-}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=--foreigncode #-}
------------------------------------------------------------------------------
--- This program contains examples for integrated code to support
......@@ -21,7 +21,7 @@ must be of type HtmlExp and is inserted as an HTML element.
-}
test1 :: String -> IO ()
test1 name = putStrLn (showHtmlExps ``html
test1 name = putStrLn $ showHtmlExps ``html
<html>
<head>
......@@ -32,6 +32,7 @@ test1 name = putStrLn (showHtmlExps ``html
<p>
Sorry, i've got nothing to say...but:
<h2>{(reverse sey)++"we "++"can!"}
Have a wonderful time!'')
Have a wonderful time!''
sey :: String
sey = " seY"
{-# OPTIONS_CYMAKE -F --pgmF=currypp #-}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=--foreigncode #-}
------------------------------------------------------------------------------
--- This program contains some examples for using different kinds of
......
{-# OPTIONS_CYMAKE -F --pgmF=currypp #-}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=--foreigncode #-}
------------------------------------------------------------------------------
--- This program contains some examples for integrated code to support
......
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=-o #-}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=--foreigncode --optF=-o #-}
------------------------------------------------------------------------------
-- Example for CGI programming in Curry:
......
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=-o --optF=-v #-}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=--foreigncode --optF=-o #-}
------------------------------------------------------------------------------
--- This program contains examples for integrated code to support
......
------------------------------------------------------------------------------
--- The main module of currypp, the Curry Preprocessor
--- ===================================================
---
--- The Curry Preprocessor transforms the source code of Curry programs.
--- Currently, only the translation of foreign code integrated in Curry code
--- is supported (option --foreigncode, see module `Translator`).
---
--- @author Michael Hanus
--- @version February 2015
------------------------------------------------------------------------------
import System
import Translator(translateFile)
cppTitle :: String
cppTitle = "Curry Preprocessor (version of 09/02/2015)"
--- The main function should be called with three arguments and uses
--- translateFile to translate Curry with Integrated Code to standard Curry.
main :: IO ()
main = do
args <- getArgs
case args of
(orgSourceFile:inFile:outFile:options) ->
let (save,version,optError,ppts) = processOptions (False,False,False,[]) options
in if optError
then showUsage args
else do
when version (putStrLn cppTitle)
preprocess ppts inFile outFile
when save (saveFile orgSourceFile outFile)
_ -> showUsage args
where
processOptions (save,version,opterror,ppts) opts = case opts of
[] -> (save,version,opterror,ppts)
("-o":os) -> processOptions (True,version,opterror,ppts) os
("-v":os) -> processOptions (save,True,opterror,ppts) os
(('-':'-':ts):os) -> if ts `elem` ["foreigncode"]
then processOptions (save,version,opterror,ts:ppts) os
else (False,False,True,[])
_ -> (False,False,True,[])
saveFile orgSourceFile outFile = do
let sFile = orgSourceFile++".CURRYPP"
system ("cp "++outFile++" "++sFile)
putStrLn $ "Translated Curry file written to '"++sFile++"'"
showUsage args = do
putStrLn cppTitle
putStrLn $ "\nERROR: Illegal arguments: " ++ unwords args ++ "\n"
putStrLn usageText
exitWith 1
usageText :: String
usageText =
"Usage: currypp <OrgFileName> <InputFilePath> <OutputFilePath> <options>\n\n"++
"<OrgFileName> : name of original program source file\n" ++
"<InputFilePath> : name of the actual input file\n" ++
"<OutputFilePath>: name of the file where output should be written\n\n" ++
"where <options> can contain:\n" ++
"--foreigncode : translate foreign code pieces in the source file\n" ++
"-o : store output also in file <OrgFileName>.CURRYPP\n" ++
"-v : show preprocessor version on stdout\n"
-- Start the Curry preprocessor:
preprocess :: [String] -> String -> String -> IO ()
preprocess pptargets infile outfile
| null pptargets = do
putStrLn cppTitle
putStrLn "ERROR: no preprocessing target (e.g., --foreigncode) specified!\n"
putStrLn usageText
exitWith 1
| "foreigncode" `elem` pptargets = translateFile infile outfile
| otherwise = error "currypp: internal error"
......@@ -18,17 +18,16 @@ TOOL = $(BINDIR)/currypp
SRCDIR = $(CURDIR)
PARSEDIR = $(SRCDIR)/Parser
MLDIR = $(PARSEDIR)/ML
MAIN = $(SRCDIR)/Translator.curry
.PHONY: all compile install clean uninstall
all: install
compile: Translator
compile: Main
install: compile
rm -f $(TOOL)
ln -s $(CURDIR)/Translator $(TOOL)
ln -s $(CURDIR)/Main $(TOOL)
clean:
$(CLEANCURRY) -r
......@@ -38,7 +37,7 @@ uninstall: clean
rm -f $(TOOL)
# generate executable of currypp translator:
Translator: $(MAIN) $(SRCDIR)/*.curry $(PARSEDIR)/*.curry $(MLDIR)/*.curry
Main: $(SRCDIR)/*.curry $(PARSEDIR)/*.curry $(MLDIR)/*.curry
@echo Compiling Curry Integrated Code Translator ...
$(REPL) $(REPL_OPTS) :set path $(SRCDIR):$(PARSEDIR):$(MLDIR) \
:load $(MAIN) :save :quit
:load Main :save :quit
......@@ -25,7 +25,7 @@
--- xml - see the MLParser and XML library
---
--- @author Jasper Sikorra (with changes by Michael Hanus)
--- @version May 2014
--- @version February 2015
------------------------------------------------------------------------------
module Translator where
......@@ -42,9 +42,6 @@ import FormatParser as FormatParser
import RegexParser as RegexParser
import MLTranslate as MLTranslate
cppTitle :: String
cppTitle = "Curry Preprocessor (version of 07/11/2014)"
-- Parser for Curry with Integrated Code
ciparser :: Filename -> String -> IO (PM [StandardToken])
ciparser = CIParser.parse
......@@ -95,49 +92,6 @@ formatWarnings ws@((p,_):_) = "\nWARNINGS in " ++ getFilename p ++ ":"
++ " Col " ++ show (getCol (getWarnPos w))
++ " | " ++ getWarnMsg w
--- The main function should be called with three arguments and uses
--- translateFile to translate Curry with Integrated Code to standard Curry.
main :: IO ()
main = do
args <- getArgs
case args of
(orgSourceFile:inFile:outFile:options) ->
let (save,version,optError) = processOptions (False,False,False) options
in if optError
then showUsage args
else do
when version (putStrLn cppTitle)
translateFile inFile outFile
when save (saveFile orgSourceFile outFile)
_ -> showUsage args
where
processOptions (save,version,opterror) opts = case opts of
[] -> (save,version,opterror)
("-o":os) -> processOptions (True,version,opterror) os
("-v":os) -> processOptions (save,True,opterror) os
_ -> (False,False,True)
saveFile orgSourceFile outFile = do
let sFile = orgSourceFile++".CURRYPP"
system ("cp "++outFile++" "++sFile)
putStrLn $ "Translated Curry file written to '"++sFile++"'"
showUsage args = do
putStrLn cppTitle
putStrLn $ "\nERROR: Illegal arguments: " ++ unwords args ++ "\n"
putStrLn usageText
exitWith 1
usageText :: String
usageText =
"Usage: currypp <OrgFileName> <InputFilePath> <OutputFilePath> [-o] [-v]\n\n"++
"<OrgFileName> : name of original program source file\n" ++
"<InputFilePath> : name of the actual input file\n" ++
"<OutputFilePath>: name of the file where output should be written\n" ++
"-o : store output also in file <OrgFileName>.CURRYPP\n" ++
"-v : show preprocessor version on stdout\n"
--- Translates a file with Curry with Integrated Code to a file with Curry Code.
--- @param in_fp - The filepath to the input file
--- @param out_fp - The filepath to the output file
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment