Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A LexTree
is a map designed to reconstruct the lexical structure (tree of scopes) of a source file, given an unordered list of scopes.
Values are inserted with a pair source locations as its key.
For a given key, we can then ask what the smallest enclosing scope is.
For example, in the snippet below the smallest scope containing x
is b
.
x
| a |
| b |
| c |
Scopes are not allowed to overlap.
The purpose of this data structure is to find out what surrounding definition a certain use site belongs to.
Synopsis
- data LexTree p a
- data TreeError p a
- = InvalidBounds p a p
- | OverlappingBounds a a p p
- | MidSplit
- | LexicalError p a p (LexTree p a)
- lookup :: Ord p => p -> LexTree p a -> Maybe a
- lookupOuter :: Ord p => p -> LexTree p a -> Maybe a
- insert :: Ord p => p -> a -> p -> LexTree p a -> Either (TreeError p a) (LexTree p a)
- emptyLexTree :: LexTree p a
- foldLexTree :: r -> (r -> p -> a -> r -> p -> r -> r) -> LexTree p a -> r
- toForest :: LexTree p a -> Forest (p, a, p)
- insertWith :: Ord p => (a -> a -> Maybe a) -> p -> a -> p -> LexTree p a -> Either (TreeError p a) (LexTree p a)
- height :: LexTree p a -> Int
- toList :: LexTree p a -> [(p, a, p)]
- bin :: LexTree p a -> p -> a -> LexTree p a -> p -> LexTree p a -> LexTree p a
- shift :: Num p => p -> LexTree p a -> LexTree p a
Documentation
Instances
Functor (LexTree p) Source # | |
Foldable (LexTree p) Source # | |
Defined in Calligraphy.Util.LexTree fold :: Monoid m => LexTree p m -> m # foldMap :: Monoid m => (a -> m) -> LexTree p a -> m # foldMap' :: Monoid m => (a -> m) -> LexTree p a -> m # foldr :: (a -> b -> b) -> b -> LexTree p a -> b # foldr' :: (a -> b -> b) -> b -> LexTree p a -> b # foldl :: (b -> a -> b) -> b -> LexTree p a -> b # foldl' :: (b -> a -> b) -> b -> LexTree p a -> b # foldr1 :: (a -> a -> a) -> LexTree p a -> a # foldl1 :: (a -> a -> a) -> LexTree p a -> a # toList :: LexTree p a -> [a] # length :: LexTree p a -> Int # elem :: Eq a => a -> LexTree p a -> Bool # maximum :: Ord a => LexTree p a -> a # minimum :: Ord a => LexTree p a -> a # | |
Traversable (LexTree p) Source # | |
Defined in Calligraphy.Util.LexTree | |
(Eq p, Eq a) => Eq (LexTree p a) Source # | |
(Show p, Show a) => Show (LexTree p a) Source # | |
InvalidBounds p a p | Nonsensical bounds, i.e. a left-hand bound larger than the right-hand obund |
OverlappingBounds a a p p | Two identical scopes |
MidSplit | An attempt to split halfway through a scope, usually the result of two partially overlapping scopes |
LexicalError p a p (LexTree p a) | Attempting to insert a scope that would not form a tree structure |
Instances
Functor (TreeError p) Source # | |
Foldable (TreeError p) Source # | |
Defined in Calligraphy.Util.LexTree fold :: Monoid m => TreeError p m -> m # foldMap :: Monoid m => (a -> m) -> TreeError p a -> m # foldMap' :: Monoid m => (a -> m) -> TreeError p a -> m # foldr :: (a -> b -> b) -> b -> TreeError p a -> b # foldr' :: (a -> b -> b) -> b -> TreeError p a -> b # foldl :: (b -> a -> b) -> b -> TreeError p a -> b # foldl' :: (b -> a -> b) -> b -> TreeError p a -> b # foldr1 :: (a -> a -> a) -> TreeError p a -> a # foldl1 :: (a -> a -> a) -> TreeError p a -> a # toList :: TreeError p a -> [a] # null :: TreeError p a -> Bool # length :: TreeError p a -> Int # elem :: Eq a => a -> TreeError p a -> Bool # maximum :: Ord a => TreeError p a -> a # minimum :: Ord a => TreeError p a -> a # | |
Traversable (TreeError p) Source # | |
Defined in Calligraphy.Util.LexTree | |
(Eq p, Eq a) => Eq (TreeError p a) Source # | |
(Show p, Show a) => Show (TreeError p a) Source # | |
emptyLexTree :: LexTree p a Source #
foldLexTree :: r -> (r -> p -> a -> r -> p -> r -> r) -> LexTree p a -> r Source #
insertWith :: Ord p => (a -> a -> Maybe a) -> p -> a -> p -> LexTree p a -> Either (TreeError p a) (LexTree p a) Source #