pire-0.2.5

Copyright(c) Andreas Reuleaux 2015 - 2018
LicenseBSD2
MaintainerAndreas Reuleaux <rx@a-rx.info>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

OldDecorate

Description

decorate the (old) syntax tree with exact position information, used subsequently to calculate ranges, and allow for line column navigation in the white space aware syntax tree

Synopsis

Documentation

class Deco t where Source #

Minimal complete definition

deco

Methods

deco :: MonadState Delta m => t -> m (t, Delta) Source #

Instances
Deco String Source # 
Instance details

Defined in OldDecorate

Methods

deco :: MonadState Delta m => String -> m (String, Delta) Source #

Deco Text Source # 
Instance details

Defined in OldDecorate

Methods

deco :: MonadState Delta m => Text -> m (Text, Delta) Source #

decorate :: (Deco b, Deco a, Bitraversable t) => t a b -> Delta -> t (a, Delta) (b, Delta) Source #

decorate token trees with exact position information (relying on bitraversal, and on the fact the every token is recorded now with its textual repr),

decorate e delta is just a shortcut for evalState (bitraverse deco deco e) delta, creates a tree of pairs

(more fine grained than (Position ...), wrapped around only some of the exprs by the parser), and works after parsing as well

>>> evalState (bitraverse deco deco $ nopos $ parse expr_ "f arg") $ beginning
Ws_ (V ("f",Lines 0 0 0 0)) (Ws (" ",Lines 0 1 0 0)) :@ Ws_ (V ("arg",Lines 0 2 0 0)) (Ws ("",Lines 0 5 0 0))

and works with String exprs as well

>>> evalState (bitraverse deco deco $ t2s $ nopos $ parse expr_ "f arg") $ beginning
Ws_ (V ("f",Lines 0 0 0 0)) (Ws (" ",Lines 0 1 0 0)) :@ Ws_ (V ("arg",Lines 0 2 0 0)) (Ws ("",Lines 0 5 0 0))
>>> decorate (nopos $ parse expr_ "\\  x . f  a") $ beginning
LamPAs_ (LamTok ("\\",Lines 0 0 0 0) (Ws ("  ",Lines 0 1 0 0))) [(RuntimeP,Binder_ ("x",Lines 0 3 0 0) (Ws (" ",Lines 0 4 0 0)),Annot Nothing)] (Dot (".",Lines 0 5 0 0) (Ws (" ",Lines 0 6 0 0))) (Scope (Ws_ (V (F (V ("f",Lines 0 7 0 0)))) (Ws ("  ",Lines 0 8 0 0)) :@ Ws_ (V (F (V ("a",Lines 0 10 0 0)))) (Ws ("",Lines 0 11 0 0))))

watch out however for bound vars (they have no textual repr in the scope, and thus shift the result)

>>> decorate (nopos $ parse expr_ "\\  x . x  a") $ beginning
LamPAs_ (LamTok ("\\",Lines 0 0 0 0) (Ws ("  ",Lines 0 1 0 0))) [(RuntimeP,Binder_ ("x",Lines 0 3 0 0) (Ws (" ",Lines 0 4 0 0)),Annot Nothing)] (Dot (".",Lines 0 5 0 0) (Ws (" ",Lines 0 6 0 0))) (Scope (Ws_ (V (B 0)) (Ws ("  ",Lines 0 7 0 0)) :@ Ws_ (V (F (V ("a",Lines 0 9 0 0)))) (Ws ("",Lines 0 10 0 0))))

but get exact positions, even in the case of bound vars, w/ the help of wrap:

>>> decorate (nopos $ wrap $ parse expr_ "\\  x . x  a") $ beginning
LamPAs_ (LamTok ("\\",Lines 0 0 0 0) (Ws ("  ",Lines 0 1 0 0))) [(RuntimeP,Binder_ ("x",Lines 0 3 0 0) (Ws (" ",Lines 0 4 0 0)),Annot Nothing)] (Dot (".",Lines 0 5 0 0) (Ws (" ",Lines 0 6 0 0))) (Scope (Ws_ (BndV ("x",Lines 0 7 0 0) (V (B 0))) (Ws ("  ",Lines 0 8 0 0)) :@ Ws_ (V (F (V ("a",Lines 0 10 0 0)))) (Ws ("",Lines 0 11 0 0))))

decoWithDummy :: (Deco t, MonadState Delta m) => t -> m (t, Delta) Source #

decoWithDummy' :: Monad m => t -> m (t, Delta) Source #

decorateM :: (Deco t1, Deco t2, Ord t1) => Module t1 t2 -> Module (t1, Delta) (t2, Delta) Source #

dummyDecorateM :: Ord t1 => Module t1 t2 -> Module (t1, Delta) (t2, Delta) Source #

undecorateM :: Ord b1 => Module (b1, b2) (a, b3) -> Identity (Module b1 a) Source #