eo-phi-normalizer-3.2.0: Command line normalizer of 𝜑-calculus expressions.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.EO.Phi.Syntax

Synopsis

Documentation

printTree :: (Pretty a, SugarableFinally a) => a -> String Source #

The top-level printing method.

Conversion to Bytes

intToBytes :: Int -> Bytes Source #

Convert an Int into Bytes representation.

>>> intToBytes 7
Bytes "00-00-00-00-00-00-00-07"
>>> intToBytes (3^33)
Bytes "00-13-BF-EF-A6-5A-BB-83"
>>> intToBytes (-1)
Bytes "FF-FF-FF-FF-FF-FF-FF-FF"

int64ToBytes :: Int64 -> Bytes Source #

Convert an Int64 into Bytes representation.

>>> int64ToBytes 7
Bytes "00-00-00-00-00-00-00-07"
>>> int64ToBytes (3^33)
Bytes "00-13-BF-EF-A6-5A-BB-83"
>>> int64ToBytes (-1)
Bytes "FF-FF-FF-FF-FF-FF-FF-FF"

int32ToBytes :: Int32 -> Bytes Source #

Convert an Int32 into Bytes representation.

>>> int32ToBytes 7
Bytes "00-00-00-07"
>>> int32ToBytes (3^33)
Bytes "A6-5A-BB-83"
>>> int32ToBytes (-1)
Bytes "FF-FF-FF-FF"

int16ToBytes :: Int16 -> Bytes Source #

Convert an Int16 into Bytes representation.

>>> int16ToBytes 7
Bytes "00-07"
>>> int16ToBytes (3^33)
Bytes "BB-83"
>>> int16ToBytes (-1)
Bytes "FF-FF"

floatToBytes :: Double -> Bytes Source #

Encode Double as Bytes following IEEE754.

Note: it is called "float" in EO, but it actually occupies 8 bytes so it corresponds to Double.

>>> floatToBytes 0
Bytes "00-00-00-00-00-00-00-00"
>>> floatToBytes (-0.1)
Bytes "BF-B9-99-99-99-99-99-9A"
>>> floatToBytes (1/0)       -- Infinity
Bytes "7F-F0-00-00-00-00-00-00"
>>> floatToBytes (asin 2) `elem` ["FF-F8-00-00-00-00-00-00", "7F-F8-00-00-00-00-00-00"]  -- sNaN or qNaN
True

boolToBytes :: Bool -> Bytes Source #

Convert Bool to Bytes.

>>> boolToBytes False
Bytes "00-"
>>> boolToBytes True
Bytes "01-"

stringToBytes :: String -> Bytes Source #

Encode String as Bytes.

>>> stringToBytes "Hello, world!"
Bytes "48-65-6C-6C-6F-2C-20-77-6F-72-6C-64-21"
>>> stringToBytes "Привет, мир!"
Bytes "D0-9F-D1-80-D0-B8-D0-B2-D0-B5-D1-82-2C-20-D0-BC-D0-B8-D1-80-21"
>>> stringToBytes  "hello, 大家!"
Bytes "68-65-6C-6C-6F-2C-20-E5-A4-A7-E5-AE-B6-21"

Conversion from Bytes

bytesToInt :: Bytes -> Int Source #

Parse Bytes as Int.

>>> bytesToInt "00-13-BF-EF-A6-5A-BB-83"
5559060566555523
>>> bytesToInt "AB-"
171

May error on invalid Bytes:

>>> bytesToInt "s"
*** Exception: Prelude.head: empty list
...
...
...
...
...
...

bytesToInt64 :: Bytes -> Int64 Source #

Parse Bytes as Int64.

>>> bytesToInt64 "00-13-BF-EF-A6-5A-BB-83"
5559060566555523
>>> bytesToInt64 "AB-"
171

May error on invalid Bytes:

>>> bytesToInt64 "s"
*** Exception: Prelude.head: empty list
...
...
...
...
...
...

bytesToInt32 :: Bytes -> Int32 Source #

Parse Bytes as Int32.

>>> bytesToInt32 "A6-5A-BB-83"
-1504003197
>>> bytesToInt32 "AB-"
171

May error on invalid Bytes:

>>> bytesToInt32 "s"
*** Exception: Prelude.head: empty list
...
...
...
...
...
...

bytesToInt16 :: Bytes -> Int16 Source #

Parse Bytes as Int16.

>>> bytesToInt16 "BB-83"
-17533
>>> bytesToInt16 "AB-"
171

May error on invalid Bytes:

>>> bytesToInt16 "s"
*** Exception: Prelude.head: empty list
...
...
...
...
...
...

bytesToFloat :: Bytes -> Double Source #

Decode Double from Bytes following IEEE754.

>>> bytesToFloat "00-00-00-00-00-00-00-00"
0.0
>>> bytesToFloat "BF-B9-99-99-99-99-99-9A"
-0.1
>>> bytesToFloat "7F-F0-00-00-00-00-00-00"
Infinity
>>> bytesToFloat "FF-F8-00-00-00-00-00-00"
NaN

bytesToString :: Bytes -> String Source #

Decode String from Bytes.

>>> bytesToString "48-65-6C-6C-6F-2C-20-77-6F-72-6C-64-21"
"Hello, world!"

bytesToBool :: Bytes -> Bool Source #

Interpret Bytes as Bool.

Zero is interpreted as False.

>>> bytesToBool "00-"
False
>>> bytesToBool "00-00"
False

Everything else is interpreted as True.

>>> bytesToBool "01-"
True
>>> bytesToBool "00-01"
True
>>> bytesToBool "AB-CD"
True

Wrapping Bytes into Object

Functions over Bytes

sliceBytes :: Bytes -> Int -> Int -> Bytes Source #

Select a slice (section) of Bytes.

>>> sliceBytes "12-34-56" 1 1
Bytes "34-"
>>> sliceBytes "12-34-56" 1 0
Bytes "00-"
>>> sliceBytes "12-34-56" 0 2
Bytes "12-34"

concatBytes :: Bytes -> Bytes -> Bytes Source #

Concatenate Bytes. FIXME: we should really use ByteString instead of the underlying String representation.

>>> concatBytes "00-" "01-02"
Bytes "00-01-02"
>>> concatBytes "03-04" "01-02"
Bytes "03-04-01-02"
>>> concatBytes "03-04" "01-"
Bytes "03-04-01"

Helpers

chunksOf :: Int -> [a] -> [[a]] Source #

Split a list into chunks of given size. All lists in the result are guaranteed to have length less than or equal to the given size.

>>> chunksOf 2 "012345678"
["01","23","45","67","8"]

See paddedLeftChunksOf for a version with padding to guarantee exact chunk size.

paddedLeftChunksOf :: a -> Int -> [a] -> [[a]] Source #

Split a list into chunks of given size, padding on the left if necessary. All lists in the result are guaranteed to have given size.

>>> paddedLeftChunksOf '0' 2 "1234567"
["01","23","45","67"]
>>> paddedLeftChunksOf '0' 2 "123456"
["12","34","56"]
n > 0  ==>  all (\chunk -> length chunk == n) (paddedLeftChunksOf c n s)

normalizeBytes :: String -> String Source #

Normalize the bytestring representation to fit valid Bytes token.

>>> normalizeBytes "238714ABCDEF"
"23-87-14-AB-CD-EF"
>>> normalizeBytes "0238714ABCDEF"
"00-23-87-14-AB-CD-EF"
>>> normalizeBytes "4"
"04-"

parseWith :: (DesugarableInitially a, CheckableSyntaxInitially a) => ([Token] -> Either String a) -> String -> Either String a Source #

Classes

class SugarableFinally a where Source #

Minimal complete definition

Nothing

Methods

sugarFinally :: a -> a Source #

Instances

Instances details
SugarableFinally Attribute Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally Binding Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally BindingsMetaId Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally Bytes Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally BytesMetaId Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally LabelMetaId Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally MetaId Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally Object Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally ObjectMetaId Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally Program Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally TailMetaId Source # 
Instance details

Defined in Language.EO.Phi.Syntax

SugarableFinally a => SugarableFinally [a] Source # 
Instance details

Defined in Language.EO.Phi.Syntax

Methods

sugarFinally :: [a] -> [a] Source #

Pattern synonyms

Orphan instances

IsString Attribute Source # 
Instance details

IsString AttributeSugar Source # 
Instance details

IsString Binding Source # 
Instance details

Methods

fromString :: String -> Binding #

IsString MetaId Source # 
Instance details

Methods

fromString :: String -> MetaId #

IsString Object Source # 
Instance details

Methods

fromString :: String -> Object #

IsString ObjectHead Source # 
Instance details

IsString PeeledObject Source # 
Instance details

IsString Program Source # 
Instance details

Methods

fromString :: String -> Program #

IsString RuleAttribute Source # 
Instance details