Module TransICode

Translator from Curry with Integrated Code to Curry

Integrated Code can be used in Curry in the form

AccentGraves Langtag Whitespaces Code SingleQuotes

where AccentGraves is a number of greater than 2 SingleQuotes is the same number of ' Langtag is an arbitrary sequence of characters without whitespaces, tabs and newlines, Whitespaces is a combination of spaces, tabs and newlines, and Code is code in the language Langtag. Is is allowed to use and ' in the code, as long as they amount of sequential ` or ' is smaller than their number in AccentGraves.

If there is a corresponding parser to the langtag, the expression can be translated into type-safe Curry code.

Currently available Langtags: format - see the FormatParser and Format library regex - see the RegexParser and Regex library html - see the MLParser and HTML library xml - see the MLParser and XML library sql - see the SQLConverter and CDBI-library

Author: Jasper Sikorra (with changes by Michael Hanus)

Version: June 2016

Summary of exported operations:

ciparser :: String -> String -> IO (WM (PR [StandardToken]))   
parsers :: Maybe String -> Either String ParserInfo -> Pos -> String -> IO (WM (PR String))   
addRealFname :: String -> (Pos,String) -> (Pos,String)   
formatErrors :: [PError] -> IO a   
formatWarnings :: [(Pos,String)] -> String   
translateIntCode :: Int -> String -> String -> String -> IO String   
Translates a string containing a Curry program with Integrated Code into a string with pure Curry code.
tryReadParserInfoFile :: Int -> String -> String -> IO (Either String ParserInfo)   
Try to read parser info file for the SQL preprocessor.
concatAllIOPM :: IO (WM (PR [StandardToken])) -> IO (WM (PR String))   
Handles the IO and PM monads around the StandardTokens for the concatenation, so they will not disturb in the real concat function concatAll
concatAll :: [StandardToken] -> String   
Concatenates the result of the translation process, inserting newlines and offsets if necessary
genLines :: Int -> String   
The function genLines generates lines
splitByLine :: String -> (String,String)   
The function splitByLine splits a string at the first newline
applyLangParsers :: Either String ParserInfo -> IO (WM (PR [StandardToken])) -> IO (WM (PR [StandardToken]))   
Applies the corresponding translators of the DSL to Curry on the StandardTokens
applyLangParser :: Either String ParserInfo -> StandardToken -> IO (WM (PR StandardToken))   
Select the right translator and apply it to a single StandardToken

Exported operations:

ciparser :: String -> String -> IO (WM (PR [StandardToken]))   

parsers :: Maybe String -> Either String ParserInfo -> Pos -> String -> IO (WM (PR String))   

addRealFname :: String -> (Pos,String) -> (Pos,String)   

formatErrors :: [PError] -> IO a   

formatWarnings :: [(Pos,String)] -> String   

translateIntCode :: Int -> String -> String -> String -> IO String   

Translates a string containing a Curry program with Integrated Code into a string with pure Curry code. The second argument is, if non-empty, the name of an info file containing information about the data model in case of integrated SQL code.

Example call:
(translateIntCode verb model fname s)
Parameters:
  • verb : verbosity level
  • model : name of file containing information about the datamodel in case of SQL, an empty string otherwise
  • fname : The name of the original Curry file
  • s : The string that should be translated
Returns:
The translated string

tryReadParserInfoFile :: Int -> String -> String -> IO (Either String ParserInfo)   

Try to read parser info file for the SQL preprocessor.

concatAllIOPM :: IO (WM (PR [StandardToken])) -> IO (WM (PR String))   

Handles the IO and PM monads around the StandardTokens for the concatenation, so they will not disturb in the real concat function concatAll

Example call:
(concatAllIOPM ioprpt)
Parameters:
  • ioprpt : A list of StandardTokens wrapped in IO and a ParserMonad

concatAll :: [StandardToken] -> String   

Concatenates the result of the translation process, inserting newlines and offsets if necessary

Example call:
(concatAll tks)
Parameters:
  • tks : A list of StandardTokens containing the results

genLines :: Int -> String   

The function genLines generates lines

Example call:
(genLines n)
Parameters:
  • n : The number of line to be generated

splitByLine :: String -> (String,String)   

The function splitByLine splits a string at the first newline

Example call:
(splitByLine s)
Parameters:
  • s : The string

applyLangParsers :: Either String ParserInfo -> IO (WM (PR [StandardToken])) -> IO (WM (PR [StandardToken]))   

Applies the corresponding translators of the DSL to Curry on the StandardTokens

Example call:
(applyLangParsers model iotks)
Parameters:
  • model : data model information (required in case of SQL code), otherwise an error message
  • iotks : The input StandardTokens wrapped in IO and ParserMonad

applyLangParser :: Either String ParserInfo -> StandardToken -> IO (WM (PR StandardToken))   

Select the right translator and apply it to a single StandardToken

Example call:
(applyLangParser model t)
Parameters:
  • model : data model information in case of SQL code, error message otherwise
  • t : The input StandardToken result - The translated StandardToken wrapped in IO and ParserMonad