dino-0.1: A convenient tagless EDSL

Safe HaskellNone
LanguageHaskell2010

Dino.AST

Contents

Description

Untyped representation of abstract syntax trees

Synopsis

Representation

newtype Field Source #

A wrapper for String with a Show instance that omits quotes

Useful in situations where show is (ab)used to provide conversion to String rather than for displaying values.

Constructors

Field 

Fields

Instances
Eq Field Source # 
Instance details

Defined in Dino.Pretty

Methods

(==) :: Field -> Field -> Bool #

(/=) :: Field -> Field -> Bool #

Ord Field Source # 
Instance details

Defined in Dino.Pretty

Methods

compare :: Field -> Field -> Ordering #

(<) :: Field -> Field -> Bool #

(<=) :: Field -> Field -> Bool #

(>) :: Field -> Field -> Bool #

(>=) :: Field -> Field -> Bool #

max :: Field -> Field -> Field #

min :: Field -> Field -> Field #

Show Field Source # 
Instance details

Defined in Dino.Pretty

Methods

showsPrec :: Int -> Field -> ShowS #

show :: Field -> String #

showList :: [Field] -> ShowS #

IsString Field Source # 
Instance details

Defined in Dino.Pretty

Methods

fromString :: String -> Field #

Pretty Field Source # 
Instance details

Defined in Dino.Pretty

Methods

pretty :: Field -> Doc #

prettyList :: [Field] -> Doc #

Hashable Field Source # 
Instance details

Defined in Dino.Pretty

Methods

hashWithSalt :: Int -> Field -> Int #

hash :: Field -> Int #

Inspectable a => Inspectable (Mapping Field a) Source # 
Instance details

Defined in Dino.AST

data Mapping k v Source #

Constructors

Mapping Importance !(HashMap k v) 
Instances
Functor (Mapping k) Source # 
Instance details

Defined in Dino.AST

Methods

fmap :: (a -> b) -> Mapping k a -> Mapping k b #

(<$) :: a -> Mapping k b -> Mapping k a #

Foldable (Mapping k) Source # 
Instance details

Defined in Dino.AST

Methods

fold :: Monoid m => Mapping k m -> m #

foldMap :: Monoid m => (a -> m) -> Mapping k a -> m #

foldr :: (a -> b -> b) -> b -> Mapping k a -> b #

foldr' :: (a -> b -> b) -> b -> Mapping k a -> b #

foldl :: (b -> a -> b) -> b -> Mapping k a -> b #

foldl' :: (b -> a -> b) -> b -> Mapping k a -> b #

foldr1 :: (a -> a -> a) -> Mapping k a -> a #

foldl1 :: (a -> a -> a) -> Mapping k a -> a #

toList :: Mapping k a -> [a] #

null :: Mapping k a -> Bool #

length :: Mapping k a -> Int #

elem :: Eq a => a -> Mapping k a -> Bool #

maximum :: Ord a => Mapping k a -> a #

minimum :: Ord a => Mapping k a -> a #

sum :: Num a => Mapping k a -> a #

product :: Num a => Mapping k a -> a #

Traversable (Mapping k) Source # 
Instance details

Defined in Dino.AST

Methods

traverse :: Applicative f => (a -> f b) -> Mapping k a -> f (Mapping k b) #

sequenceA :: Applicative f => Mapping k (f a) -> f (Mapping k a) #

mapM :: Monad m => (a -> m b) -> Mapping k a -> m (Mapping k b) #

sequence :: Monad m => Mapping k (m a) -> m (Mapping k a) #

(Eq k, Eq v) => Eq (Mapping k v) Source # 
Instance details

Defined in Dino.AST

Methods

(==) :: Mapping k v -> Mapping k v -> Bool #

(/=) :: Mapping k v -> Mapping k v -> Bool #

(Show k, Show v) => Show (Mapping k v) Source # 
Instance details

Defined in Dino.AST

Methods

showsPrec :: Int -> Mapping k v -> ShowS #

show :: Mapping k v -> String #

showList :: [Mapping k v] -> ShowS #

Generic (Mapping k v) Source # 
Instance details

Defined in Dino.AST

Associated Types

type Rep (Mapping k v) :: Type -> Type #

Methods

from :: Mapping k v -> Rep (Mapping k v) x #

to :: Rep (Mapping k v) x -> Mapping k v #

(Pretty a, Show k, Ord k) => Pretty (Mapping k a) Source #

If k is a String-like type, it will be shown with quotes. Use Field to prevent this.

Instance details

Defined in Dino.AST

Methods

pretty :: Mapping k a -> Doc #

prettyList :: [Mapping k a] -> Doc #

(Pretty a, Pretty (Diff a), Show k, Ord k) => Pretty (Mapping k (ElemOp a)) Source #

If k is a String-like type, it will be shown with quotes. Use Field to prevent this.

Instance details

Defined in Dino.AST.Diff

Methods

pretty :: Mapping k (ElemOp a) -> Doc #

prettyList :: [Mapping k (ElemOp a)] -> Doc #

(Hashable k, Hashable v) => Hashable (Mapping k v) Source # 
Instance details

Defined in Dino.AST

Methods

hashWithSalt :: Int -> Mapping k v -> Int #

hash :: Mapping k v -> Int #

Inspectable a => Inspectable (Mapping Field a) Source # 
Instance details

Defined in Dino.AST

(Eq k, Hashable k, Diffable a) => Diffable (Mapping k a) Source # 
Instance details

Defined in Dino.AST.Diff

Associated Types

type Diff (Mapping k a) :: Type Source #

Methods

diff :: Mapping k a -> Mapping k a -> Maybe (Diff (Mapping k a)) Source #

applyDiff :: Diff (Mapping k a) -> Mapping k a -> Maybe (Mapping k a) Source #

type Rep (Mapping k v) Source # 
Instance details

Defined in Dino.AST

type Diff (Mapping k a) Source # 
Instance details

Defined in Dino.AST.Diff

type Diff (Mapping k a) = Mapping k (ElemOp a)

data NameType Source #

Constructors

Constructor

Global constructor or variable

LocalVar

Local variable

Annotation

User annotation

Instances
Bounded NameType Source # 
Instance details

Defined in Dino.AST

Enum NameType Source # 
Instance details

Defined in Dino.AST

Eq NameType Source # 
Instance details

Defined in Dino.AST

Show NameType Source # 
Instance details

Defined in Dino.AST

Generic NameType Source # 
Instance details

Defined in Dino.AST

Associated Types

type Rep NameType :: Type -> Type #

Methods

from :: NameType -> Rep NameType x #

to :: Rep NameType x -> NameType #

Hashable NameType Source # 
Instance details

Defined in Dino.AST

Methods

hashWithSalt :: Int -> NameType -> Int #

hash :: NameType -> Int #

type Rep NameType Source # 
Instance details

Defined in Dino.AST

type Rep NameType = D1 (MetaData "NameType" "Dino.AST" "dino-0.1-6MkCTG92eXJDyeFPmd1P4Q" False) (C1 (MetaCons "Constructor" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "LocalVar" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Annotation" PrefixI False) (U1 :: Type -> Type)))

data Constr Source #

Description of a constructor or variable

Constructors

Tuple 
List 
Named NameType Text 
Instances
Eq Constr Source # 
Instance details

Defined in Dino.AST

Methods

(==) :: Constr -> Constr -> Bool #

(/=) :: Constr -> Constr -> Bool #

Show Constr Source # 
Instance details

Defined in Dino.AST

IsString Constr Source #

Creates a Named constructor/variable

Instance details

Defined in Dino.AST

Methods

fromString :: String -> Constr #

Generic Constr Source # 
Instance details

Defined in Dino.AST

Associated Types

type Rep Constr :: Type -> Type #

Methods

from :: Constr -> Rep Constr x #

to :: Rep Constr x -> Constr #

Hashable Constr Source # 
Instance details

Defined in Dino.AST

Methods

hashWithSalt :: Int -> Constr -> Int #

hash :: Constr -> Int #

type Rep Constr Source # 
Instance details

Defined in Dino.AST

data Importance Source #

Constructors

Unimportant 
Important 
Instances
Eq Importance Source # 
Instance details

Defined in Dino.Pretty

Show Importance Source # 
Instance details

Defined in Dino.Pretty

Generic Importance Source # 
Instance details

Defined in Dino.Pretty

Associated Types

type Rep Importance :: Type -> Type #

Semigroup Importance Source #

Returns Important iff. any argument is Important.

Instance details

Defined in Dino.Pretty

Hashable Importance Source # 
Instance details

Defined in Dino.Pretty

type Rep Importance Source # 
Instance details

Defined in Dino.Pretty

type Rep Importance = D1 (MetaData "Importance" "Dino.Pretty" "dino-0.1-6MkCTG92eXJDyeFPmd1P4Q" False) (C1 (MetaCons "Unimportant" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Important" PrefixI False) (U1 :: Type -> Type))

data AST n Source #

Representation of abstract syntax and values

AST is parameterized by the representation of numbers. This makes it possible to affect the exactness of comparisons. For example a newtype with approximate equality can be used instead of e.g. Double.

Constructors

Number n

Numeric literal

Text Text

Text literal

App Constr [AST n]

Application of constructor or variable

Let Text (AST n) (AST n)

Let v a body binds v to a in body

Record (Mapping Field (AST n)) 
Instances
Functor AST Source # 
Instance details

Defined in Dino.AST

Methods

fmap :: (a -> b) -> AST a -> AST b #

(<$) :: a -> AST b -> AST a #

Foldable AST Source # 
Instance details

Defined in Dino.AST

Methods

fold :: Monoid m => AST m -> m #

foldMap :: Monoid m => (a -> m) -> AST a -> m #

foldr :: (a -> b -> b) -> b -> AST a -> b #

foldr' :: (a -> b -> b) -> b -> AST a -> b #

foldl :: (b -> a -> b) -> b -> AST a -> b #

foldl' :: (b -> a -> b) -> b -> AST a -> b #

foldr1 :: (a -> a -> a) -> AST a -> a #

foldl1 :: (a -> a -> a) -> AST a -> a #

toList :: AST a -> [a] #

null :: AST a -> Bool #

length :: AST a -> Int #

elem :: Eq a => a -> AST a -> Bool #

maximum :: Ord a => AST a -> a #

minimum :: Ord a => AST a -> a #

sum :: Num a => AST a -> a #

product :: Num a => AST a -> a #

Traversable AST Source # 
Instance details

Defined in Dino.AST

Methods

traverse :: Applicative f => (a -> f b) -> AST a -> f (AST b) #

sequenceA :: Applicative f => AST (f a) -> f (AST a) #

mapM :: Monad m => (a -> m b) -> AST a -> m (AST b) #

sequence :: Monad m => AST (m a) -> m (AST a) #

Eq n => Eq (AST n) Source # 
Instance details

Defined in Dino.AST

Methods

(==) :: AST n -> AST n -> Bool #

(/=) :: AST n -> AST n -> Bool #

Show n => Show (AST n) Source # 
Instance details

Defined in Dino.AST

Methods

showsPrec :: Int -> AST n -> ShowS #

show :: AST n -> String #

showList :: [AST n] -> ShowS #

Generic (AST n) Source # 
Instance details

Defined in Dino.AST

Associated Types

type Rep (AST n) :: Type -> Type #

Methods

from :: AST n -> Rep (AST n) x #

to :: Rep (AST n) x -> AST n #

Show a => Pretty (AST a) Source # 
Instance details

Defined in Dino.AST

Methods

pretty :: AST a -> Doc #

prettyList :: [AST a] -> Doc #

Hashable n => Hashable (AST n) Source # 
Instance details

Defined in Dino.AST

Methods

hashWithSalt :: Int -> AST n -> Int #

hash :: AST n -> Int #

Real n => Inspectable (AST n) Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: AST n -> AST Rational Source #

Eq a => Diffable (AST a) Source # 
Instance details

Defined in Dino.AST.Diff

Associated Types

type Diff (AST a) :: Type Source #

Methods

diff :: AST a -> AST a -> Maybe (Diff (AST a)) Source #

applyDiff :: Diff (AST a) -> AST a -> Maybe (AST a) Source #

type Rep (AST n) Source # 
Instance details

Defined in Dino.AST

type Diff (AST a) Source # 
Instance details

Defined in Dino.AST.Diff

type Diff (AST a) = Edit a

Generic inspection

class GInspectableArgs rep where Source #

Methods

gInspectArgs :: rep x -> [AST Rational] Source #

Instances
GInspectableArgs (U1 :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspectArgs :: U1 x -> [AST Rational] Source #

(GInspectableArgs rep1, GInspectableArgs rep2) => GInspectableArgs (rep1 :*: rep2 :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspectArgs :: (rep1 :*: rep2) x -> [AST Rational] Source #

Inspectable a => GInspectableArgs (S1 (MetaSel (Nothing :: Maybe Symbol) x y z) (Rec0 a) :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspectArgs :: S1 (MetaSel Nothing x y z) (Rec0 a) x0 -> [AST Rational] Source #

class GInspectableFields rep where Source #

Methods

gInspectFields :: rep x -> [(Field, AST Rational)] Source #

Instances
GInspectableFields (U1 :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspectFields :: U1 x -> [(Field, AST Rational)] Source #

(GInspectableFields rep1, GInspectableFields rep2) => GInspectableFields (rep1 :*: rep2 :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspectFields :: (rep1 :*: rep2) x -> [(Field, AST Rational)] Source #

(Inspectable a, KnownSymbol fld) => GInspectableFields (S1 (MetaSel (Just fld) x y z) (Rec0 a) :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspectFields :: S1 (MetaSel (Just fld) x y z) (Rec0 a) x0 -> [(Field, AST Rational)] Source #

class GInspectable rep where Source #

Methods

gInspect :: rep x -> AST Rational Source #

Instances
(GInspectableFields rep, KnownSymbol con) => GInspectable (C1 (MetaCons con x True) rep :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspect :: C1 (MetaCons con x True) rep x0 -> AST Rational Source #

(GInspectableArgs rep, KnownSymbol con) => GInspectable (C1 (MetaCons con x False) rep :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspect :: C1 (MetaCons con x False) rep x0 -> AST Rational Source #

GInspectable rep => GInspectable (D1 meta rep :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspect :: D1 meta rep x -> AST Rational Source #

(GInspectable rep1, GInspectable rep2) => GInspectable (rep1 :+: rep2 :: k -> Type) Source # 
Instance details

Defined in Dino.AST

Methods

gInspect :: (rep1 :+: rep2) x -> AST Rational Source #

class Inspectable a where Source #

Minimal complete definition

Nothing

Instances
Inspectable Bool Source # 
Instance details

Defined in Dino.AST

Inspectable Double Source # 
Instance details

Defined in Dino.AST

Inspectable Float Source # 
Instance details

Defined in Dino.AST

Inspectable Int Source # 
Instance details

Defined in Dino.AST

Inspectable Integer Source # 
Instance details

Defined in Dino.AST

Inspectable Rational Source # 
Instance details

Defined in Dino.AST

Inspectable () Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: () -> AST Rational Source #

Inspectable String Source # 
Instance details

Defined in Dino.AST

Inspectable Text Source # 
Instance details

Defined in Dino.AST

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

Defined in Dino.AST

Methods

inspect :: [a] -> AST Rational Source #

Inspectable a => Inspectable (Maybe a) Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: Maybe a -> AST Rational Source #

Real n => Inspectable (AST n) Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: AST n -> AST Rational Source #

Inspectable (Reified a) Source # 
Instance details

Defined in Dino.Interpretation

(Inspectable a, Inspectable b) => Inspectable (a, b) Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: (a, b) -> AST Rational Source #

Inspectable a => Inspectable (Mapping Field a) Source # 
Instance details

Defined in Dino.AST

(Inspectable a, Inspectable b, Inspectable c) => Inspectable (a, b, c) Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: (a, b, c) -> AST Rational Source #

(Inspectable a, Inspectable b, Inspectable c, Inspectable d) => Inspectable (a, b, c, d) Source # 
Instance details

Defined in Dino.AST

Methods

inspect :: (a, b, c, d) -> AST Rational Source #

inspectListAsRec Source #

Arguments

:: Inspectable a 
=> Importance 
-> (a -> Field)

Extract the key

-> [a] 
-> AST Rational 

Represent a list as a record, if the elements contain a value that can be used as key

Conversion to Tree

toTree :: Show n => AST n -> Tree Text Source #

Conversion from AST to Tree

  • Built-in consturctors (tuples and lists) are shown prepended with #.
  • Record fields are shown as fieldName:.
  • Local variables are shown as *varName (both at binding and use site).
  • Annotations are shown as "ANN: annotation ".

showTree :: Show n => AST n -> String Source #

Show an AST using Unicode art

drawTree :: Show n => AST n -> IO () Source #

Draw an AST on the terminal using Unicode art

htmlTree :: Show n => FilePath -> AST n -> IO () Source #

Convert an AST to an HTML file with foldable nodes