Safe Haskell | None |
---|

Functions for working with the ATerms that ROSE produces.

- app :: (ATermTable -> a) -> ATermTable -> Int -> a
- foldr :: (ATermTable -> a -> a) -> a -> ATermTable -> a
- foldl :: (a -> ATermTable -> a) -> a -> ATermTable -> a
- foldl' :: (a -> ATermTable -> a) -> a -> ATermTable -> a
- foldM :: Monad m => (a -> ATermTable -> m a) -> a -> ATermTable -> m a
- mapM :: Monad m => (ATermTable -> m b) -> ATermTable -> m [b]
- mapM_ :: Monad m => (ATermTable -> m b) -> ATermTable -> m ()
- map :: (ATermTable -> a) -> ATermTable -> [a]
- concatMap :: (ATermTable -> [a]) -> ATermTable -> [a]
- type CheckM log state m a = RWST ATermTable log state m a
- appM :: (Monoid log, Monad m) => (ATermTable -> a) -> Int -> CheckM log state m a
- currentTerm :: (Monoid log, Monad m) => CheckM log state m ATermTable
- withCurrentTerm :: (Monoid log, Monad m) => ATermTable -> CheckM log state m a -> CheckM log state m a
- childrenM :: (Monad m, Monoid log) => CheckM log state m [Int]
- satisfy :: (Monad m, Monoid log) => (ATermTable -> Bool) -> CheckM log st m a -> CheckM log st m (Maybe a)
- inSubtree :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m [[a]]
- inSubtree_ :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m ()
- everywhere :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m [a]
- everywhere_ :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m ()
- extractString :: ATermTable -> Maybe String
- extractInteger :: ATermTable -> Maybe Integer
- extractFileInfo :: ATermTable -> Maybe (String, Integer, Integer)
- isNamed :: String -> ATermTable -> Bool
- showATerm :: ATermTable -> String
- children :: ATermTable -> [Int]
- readATerm :: String -> ATermTable
- writeSharedATerm :: ATermTable -> String
- getATermFromTable :: ATermTable -> Int -> ATermTable

# Utility functions

app :: (ATermTable -> a) -> ATermTable -> Int -> aSource

Turns a normal function of ATermTable into a function that works on the hash value instead.

foldr :: (ATermTable -> a -> a) -> a -> ATermTable -> aSource

Standard foldr, but for ATermTables

foldl :: (a -> ATermTable -> a) -> a -> ATermTable -> aSource

Standard foldl, but for ATermTables

foldl' :: (a -> ATermTable -> a) -> a -> ATermTable -> aSource

Standard foldl', but for ATermTables

foldM :: Monad m => (a -> ATermTable -> m a) -> a -> ATermTable -> m aSource

Standard foldM, but for ATermTables

mapM :: Monad m => (ATermTable -> m b) -> ATermTable -> m [b]Source

Standard mapM, but for ATermTables

mapM_ :: Monad m => (ATermTable -> m b) -> ATermTable -> m ()Source

Standard mapM_, but for ATermTables

map :: (ATermTable -> a) -> ATermTable -> [a]Source

Standard map, but for ATermTables

concatMap :: (ATermTable -> [a]) -> ATermTable -> [a]Source

Standard concatMap, but for ATermTables

# Check Monad

type CheckM log state m a = RWST ATermTable log state m aSource

The checker monad. For now the environment is the current ATerm, in the
future we may also store the path from the root to the current ATerm, so use
`currentTerm`

instead of ask to get the current ATerm

appM :: (Monoid log, Monad m) => (ATermTable -> a) -> Int -> CheckM log state m aSource

Like `app`

but lifts the result into the CheckM monad

currentTerm :: (Monoid log, Monad m) => CheckM log state m ATermTableSource

Use this instead of `ask`

so that we can refactor
the environment later without impacting existing code.

withCurrentTerm :: (Monoid log, Monad m) => ATermTable -> CheckM log state m a -> CheckM log state m aSource

Use this instead of `local`

so that we can refactor
the environment later without impacting existing code.

childrenM :: (Monad m, Monoid log) => CheckM log state m [Int]Source

Return the hashes of the current term's children into the monad

satisfy :: (Monad m, Monoid log) => (ATermTable -> Bool) -> CheckM log st m a -> CheckM log st m (Maybe a)Source

Use this when the current node must satisfy a specific property. Note: Using Maybe here is a bit of a hack. Refactor to support MonadPlus style guards?

inSubtree :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m [[a]]Source

Applies a traversal in a subtree of the current ATerm. Differs from `everywhere`

in that it does not apply the traversal to the current term (only its children and
their children).

everywhere :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m [a]Source

Applies a traversal over the tree defined by the current node (including root node).

everywhere_ :: (Monad m, Monoid log) => CheckM log state m a -> CheckM log state m ()Source

Like `everywhere`

but throws away the result.

# Extractions

extractString :: ATermTable -> Maybe StringSource

Extracts the label of Application nodes

extractInteger :: ATermTable -> Maybe IntegerSource

Extract the integer of Int nodes

extractFileInfo :: ATermTable -> Maybe (String, Integer, Integer)Source

Extracts the filename, line number, and colunm number from file_info nodes.

isNamed :: String -> ATermTable -> BoolSource

Equality test on the label of an Application node

showATerm :: ATermTable -> StringSource

It's not acually pretty, but that's not our fault.

children :: ATermTable -> [Int]Source

This pattern comes up in most traversals. Simply return the stable names so we don't break sharing.

# Read and write

readATerm :: String -> ATermTable

create an ATerm table from an input string. Shared or unshared ATerms can be read. A string for shared ATerms usually starts with an exclamation mark and contains many hash marks indicating references. Unshared ATerms are plain constructor terms.

writeSharedATerm :: ATermTable -> String

# Misc

getATermFromTable :: ATermTable -> Int -> ATermTableSource