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-packages
currypp
Commits
fd6e3e79
Commit
fd6e3e79
authored
Dec 29, 2018
by
Michael Hanus
Browse files
Format parser produces code for library Data.Format
parent
fd88de19
Changes
7
Hide whitespace changes
Inline
Side-by-side
docs/manual.tex
View file @
fd6e3e79
...
...
@@ -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''
...
...
package.json
View file @
fd6e3e79
...
...
@@ -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"
...
...
src/ContractWrapper/Examples/BubbleSortFormat.curry
View file @
fd6e3e79
...
...
@@ -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''
...
...
src/IntegratedCode/Examples/FormatExample.curry
View file @
fd6e3e79
...
...
@@ -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 ()
...
...
src/IntegratedCode/Examples/MixedExamples.curry
View file @
fd6e3e79
...
...
@@ -6,7 +6,7 @@
------------------------------------------------------------------------------
import RegExp
import Format
import
Data.
Format
isEmail :: String -> Bool
isEmail s = s ``regex
...
...
src/IntegratedCode/Examples/testFormat.curry
View file @
fd6e3e79
...
...
@@ -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:
...
...
src/IntegratedCode/Parser/FormatParser.curry
View file @
fd6e3e79
...
...
@@ -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
Nov
ember 201
4
--- @version
Dec
ember 201
8
------------------------------------------------------------------------------
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 o
n
a function in the Format library
--- Map each type
t
o 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
...
...
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