express-0.1.1: Dynamically-typed expressions involving applications and variables.

Copyright(c) 2016-2019 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellSafe
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.

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

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''", ...]