Copyright | (c) 2016-2019 Rudy Matela |
---|---|
License | 3-Clause BSD (see the file LICENSE) |
Maintainer | Rudy Matela <rudy@matela.com.br> |
Safe Haskell | Safe |
Language | Haskell2010 |
Utilities for manipulating strings.
At some point, this file was part of the Speculate tool.
Synopsis
- module Data.String
- module Data.Char
- unquote :: String -> String
- atomic :: String -> Bool
- outernmostPrec :: String -> Maybe Int
- isNegativeLiteral :: String -> Bool
- isInfix :: String -> Bool
- isPrefix :: String -> Bool
- isInfixedPrefix :: String -> Bool
- toPrefix :: String -> String
- prec :: String -> Int
- variableNamesFromTemplate :: String -> [String]
- primeCycle :: [String] -> [String]
Documentation
module Data.String
module Data.Char
unquote :: String -> String Source #
Unquotes a string if possible, otherwise, this is just an identity.
> unquote "\"string\"" "string" > unquote "something else" "something else"
atomic :: String -> Bool Source #
Checks if a string-encoded Haskell expression is atomic.
> atomic "123" True > atomic "42 + 1337" False > atomic "'a'" True > atomic "[1,2,3,4,5]" True > atomic "(1,2,3,4,5)" True
FIXME: The current implementation may produce false positives:
> atomic "'a' < 'b'" True > atomic "\"asdf\" ++ \"qwer\"" True > atomic "[1,2,3] ++ [4,5,6]" True
but this does not cause problems for (all?) most cases.
isNegativeLiteral :: String -> Bool Source #
isInfix :: String -> Bool Source #
Check if a function / operator is infix
isInfix "foo" == False isInfix "(+)" == False isInfix "`foo`" == True isInfix "+" == True
isInfixedPrefix :: String -> Bool Source #
Is the string of the form `string`
toPrefix :: String -> String Source #
Transform an infix operator into an infix function:
toPrefix "`foo`" == "foo" toPrefix "+" == "(+)"
variableNamesFromTemplate :: String -> [String] Source #
Returns an infinite list of variable names based on the given template.
> variableNamesFromTemplate "x" ["x", "y", "z", "x'", "y'", ...]
> variableNamesFromTemplate "p" ["p", "q", "r", "p'", "q'", ...]
> variableNamesFromTemplate "xy" ["xy", "zw", "xy'", "zw'", "xy''", ...]
primeCycle :: [String] -> [String] Source #