Commit fd6e3e79 authored by Michael Hanus 's avatar Michael Hanus

Format parser produces code for library Data.Format

parent fd88de19
......@@ -150,14 +150,15 @@ one can specify the desired format with foreign code marked by
similarly to the \code{printf} statement of C,
followed by a comma-separated list of arguments.
This format specification is transformed into operations
of the \CYS library \code{Format} so that it must be imported.
of the library \code{Data.Format} (of package \code{printf})
so that it must be imported.
For instance, the following program defines an operation
that formats a string, an integer (with leading sign and zeros),
and a float with leading sign and precision 3:
\begin{currynomath}
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=foreigncode #-}
import Format
import Data.Format
showSIF :: String -> Int -> Float -> String
showSIF s i f = ``format "Name: %s | %+.5i | %+6.3f",s,i,f''
......
......@@ -14,6 +14,7 @@
"currypath" : ">= 0.0.1",
"fl-parser" : ">= 1.0.0",
"html" : ">= 2.0.0",
"printf" : ">= 0.0.1",
"regexp" : ">= 1.1.0",
"wl-pprint" : ">= 0.0.1",
"xml" : ">= 2.0.0"
......
......@@ -4,7 +4,7 @@
-- Example for using integrated code, default rules, and contracts in one
-- module
import Format
import Data.Format
import Test.Prop
showInt i = ``format "%+.3d",i''
......
......@@ -8,7 +8,7 @@
--- <http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html>
------------------------------------------------------------------------------
import Format -- required in the pre-processed program
import Data.Format -- required in the pre-processed program
-- Format a string and an integer:
ex1 :: String -> Int -> IO ()
......
......@@ -6,7 +6,7 @@
------------------------------------------------------------------------------
import RegExp
import Format
import Data.Format
isEmail :: String -> Bool
isEmail s = s ``regex
......
......@@ -9,7 +9,7 @@
--- <http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html>
------------------------------------------------------------------------------
import Format -- required in the pre-processed program
import qualified Data.Format -- required in the pre-processed program
import Test.EasyCheck
-- Format a string and an integer:
......
......@@ -20,13 +20,13 @@
--- For explanation on semantics see
--- <http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html>
---
--- __For further informations see the Format library.
--- Not all parsable expressions are usable.__
--- __For further informations see the library `Data.Format` of package
--- `printf`. Not all parsable expressions are usable.__
---
--- @author Jasper Sikorra (with changes by Michael Hanus)
--- @version November 2014
--- @version December 2018
------------------------------------------------------------------------------
module FormatParser(parse) where
module FormatParser ( parse ) where
import Parser
import Char
......@@ -68,9 +68,9 @@ isVarStartLetter c = c /= ','
isVarInnerLetter :: Char -> Bool
isVarInnerLetter c = c /= ','
--- Map each type on a function in the Format library
--- Map each type to a function in the `Data.Format` library
mapTypes :: Char -> String
mapTypes c = "Format." ++ case c of
mapTypes c = "Data.Format." ++ case c of
'c' -> "showChar"
'd' -> "showInt"
'i' -> "showInt"
......@@ -86,12 +86,12 @@ mapTypes c = "Format." ++ case c of
_ -> error "mapTypes: unknown character"
--- The function parses and converts a String that is in the format of a C-like
--- printf expression into a Curry Expression that makes use of the Format
--- library.
--- printf expression into a Curry Expression that makes use of the
--- `Data.Format` library.
--- @param showfun - The operation to be applied to the formatted string result
--- @param pos - The position of the expression in the original file
--- @param exp - The expression which should be converted
--- @return A String in Curry Syntax matching exp using the Format
--- @return A String in Curry Syntax matching exp using the `Data.Format`
--- library
parse :: String -> LangParser
parse showfun p s = do
......
Markdown is supported
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