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

currypp Format parser extended to accept expressions as parameters

parent 7da6a7ca
......@@ -16,7 +16,7 @@ ex1 name alter = putStrLn ``format "hello %s. alter %i",name,alter''
-- Format two integers:
ex2 :: Int -> Int -> IO ()
ex2 n1 n2 = putStrLn ``format "%+.5d und % 20.4i",n1,n2''
ex2 n1 n2 = putStrLn ``format "%+.5d and % 20.4i",n1,n2''
-- Format a charater:
ex3 :: Char -> IO ()
......@@ -33,3 +33,7 @@ ex5 f = putStrLn ``format "This is a float: %+10.3f",f''
-- Format a float with an exponent:
ex6 :: Float -> IO ()
ex6 f = ``printf "This formats a float, too: % .4E\n",f''
-- Format the sum of two integers:
ex7 :: Int -> Int -> IO ()
ex7 n1 n2 = ``printf "The sum of %+.5d and %+5i is %+6i.\n",n1,n2,n1+n2''
......@@ -42,7 +42,7 @@ uninstall:
rm -f $(TOOL)
# generate executable of currypp translator:
Translator: $(MAIN)
Translator: $(MAIN) $(PARSEDIR)/*.curry $(MLDIR)/*.curry
@echo Compiling Curry Integrated Code Translator ...
$(REPL) $(REPL_OPTS) :set path $(SRCDIR):$(PARSEDIR):$(MLDIR) \
:load $(MAIN) :save :quit
......
------------------------------------------------------------------------------
--- A printf-like format expression parser
--- ======================================
--- A format expression is in the form
--- A format expression is of the form
---
--- "(Specifier|NonSpecifier)*"(,Var)*
---
--- where `Var` can be any string without a comma.
---
--- A specifier is in the form
---
--- %[flags] [width] [.precision] type
......@@ -21,8 +23,8 @@
--- __For further informations see the Format library.
--- Not all parsable expressions are usable.__
---
--- @author Jasper Sikorra
--- @version January 2014
--- @author Jasper Sikorra (with changes by Michael Hanus)
--- @version November 2014
------------------------------------------------------------------------------
module FormatParser(parse) where
......@@ -108,7 +110,7 @@ specToString (SpecV f w p t v) =
++ " " ++ show f
++ " " ++ show w
++ " " ++ show p
++ " " ++ v
++ " " ++ (if all isAlphaNum v then v else '(':v++")")
++ ")"
--- Assign variables to the specifiers
......
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