express-1.0.10: Dynamically-typed expressions involving function application and variables.
Copyright(c) 2016-2021 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Express.Utils.String

Description

Utilities for manipulating strings.

At some point, this file was part of the Speculate tool.

Synopsis

Documentation

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.

outernmostPrec :: String -> Maybe Int Source #

Returns the operator precedence of an infix string.

> outernmostPrec "1 + 2"
Just 6

isNegativeLiteral :: String -> Bool Source #

Returns whether the given String represents a negative literal.

> isNegativeLiteral "1"
False
> isNegativeLiteral "-1"
True
> isNegativeLiteral "-x"
False
> isNegativeLiteral "1 - 3"
False

isInfix :: String -> Bool Source #

Check if a function / operator is infix

isInfix "foo"   == False
isInfix "(+)"   == False
isInfix "`foo`" == True
isInfix "+"     == True

isPrefix :: String -> Bool Source #

Is the given string a prefix function?

> isPrefix "abs"
True
> isPrefix "+"
False

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 "+"     == "(+)"

prec :: String -> Int Source #

Returns the precedence of default Haskell operators

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 #

Cycles through a list of variable names priming them at each iteration.

primeCycle ["x","y","z"]
"x","y","z","x'","y'","z'","x''","y''","z''","x'''",...