Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
curry
curry-tools
Commits
1c071695
Commit
1c071695
authored
Nov 07, 2014
by
Michael Hanus
Browse files
currypp Format parser extended to accept expressions as parameters
parent
7da6a7ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
currypp/Examples/FormatExample.curry
View file @
1c071695
...
...
@@ -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
u
nd % 20.4i",n1,n2''
ex2 n1 n2 = putStrLn ``format "%+.5d
a
nd % 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''
currypp/Makefile
View file @
1c071695
...
...
@@ -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
...
...
currypp/Parser/FormatParser.curry
View file @
1c071695
------------------------------------------------------------------------------
--- 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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment