pire-0.2.5

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

OldLineColumnNavigation

Description

line/column navigation in the white space aware syntax tree (zipper), based on the old syntax.

Synopsis

Documentation

undeco'' :: Ord a => Term (a, b) (a, b) -> Term a a Source #

undecorate a zipper

this can be useful in two situations:

  1. the zipper has been decorated explicitly: pp $ fromRight' $ (ezipper $ M $ decorateM $ mm) >>= undeco >>= repr
  2. the zipper has been decorated implicitly (as by lineColumn): pp $ fromRight' $ (ezipper $ M $ mm) >>= lineColumn 19 4 >>= undeco >>= repr

for using repr this is not necessary any more though, as repr handles all kinds of situations now

some examples, originally in Navigation.hs, but using lineColumn, they belong here, but yet to see where exactly.

>>> tst <- (runExceptT $ getModules_ ["samples"] "Test") >>= return . last . fromRight'
Parsing File "samples/Nat.pi"
Parsing File "samples/Nat.pi"
Parsing File "samples/Sample.pi"
Parsing File "samples/Test.pi"
  • - -- -- -- >>> fromRight' $ refactor $ (rzipper $ M $ tst) >>= lineColumn2 19 12 >>= upToBinding >>= focus
  • - -- -- -- ...
  • - needs reworking
  • - -- >>> (refactor $ rzipper $ M $ tst) >>= lineColumn2 21 9 >>= focus
  • - -- Right (Exp {_expression = V "a"})
  • - -- -- -- need the state for upToBinding:
  • - -- -- -- >>> refactor $ (rzipper $ M $ tst) >>= lineColumn2 21 9 >>= upToBinding >>= focus
  • - -- -- -- ...
  • - -- -- -- >>> pp $ fromRight' $ refactor $ (rzipper $ M $ tst) >>= lineColumn 21 9 >>= upToBinding >>= focus
  • - -- -- -- BLANKLINE
  • - -- -- -- -- leading ws, module copied from M.pi, do not touch though: used in the doctests
  • - -- -- -- BLANKLINE
  • - -- -- -- module Main where
  • - -- -- -- BLANKLINE
  • - -- -- -- import Nat
  • - -- -- -- import Sample
  • - -- -- -- BLANKLINE
  • - -- -- -- a = x . 2
  • - -- -- -- BLANKLINE
  • - -- -- -- b = x [ y ] z . x 2
  • - -- -- -- BLANKLINE
  • - -- -- -- k = x . frec x
  • - -- -- -- BLANKLINE
  • - -- -- -- BLANKLINE
  • - -- -- -- f = x . a x
  • - -- -- -- g = x . c x
  • - -- -- -- BLANKLINE
  • - -- -- -- hh = yy . a (a . x a)
  • - -- -- -- BLANKLINE
  • - -- -- -- j = y . a (a . x (a . a))
  • - -- -- -- frec = y . frec (a . x (a . a))
  • - -- -- -- BLANKLINE

this is wrong (no state for upToBinding), note how really only the parentheses are used differently":

  • - needs reworking / wrong so far:
  • - -- >>> (refactor $ rzipper $ M $ tst) >>= lineColumn 21 9 >>= upToBinding >>= focus
  • - -- ...
  • - -- -- -- >>> :t (refactor $ rzipper $ M $ tst)
  • - -- -- -- (refactor $ rzipper $ M $ tst)
  • - -- -- -- :: Either RefactorError (Zipper T.Text)

deco'' :: Ord a => Term a a -> Term (a, Delta) (a, Delta) Source #

undeco' :: Ord a => (Term (a, Delta) (a, Delta) -> Term (a, Delta) (a, Delta)) -> Term a a -> Term a a Source #

undeco :: Ord a => Refactoring m => Zipper (a, Delta) -> m (Zipper a) Source #

deco' :: Ord a => (Term a a -> Term a a) -> Term (a, Delta) (a, Delta) -> Term (a, Delta) (a, Delta) Source #

this is new stuff

decorateZ :: (Ord a, Deco a, Monad m) => Zipper a -> m (Zipper (a, Delta)) Source #

unwrapTerm :: Eq a => Term a a -> Term a a Source #

unwrapZ :: (Refactoring m, Eq a) => Zipper a -> m (Zipper a) Source #

checkLeadingWs :: (HasDetailedRange (a, b), HasRange (a, b), Refactoring m) => Pos -> Ws (a, b) -> m () Source #

line column navigation

lineColumn line column

go to line column in the zipper (this temporarily decorates the zipper w/ Delta's, but the result is undecorated again):

(ezipper $ M $ nopos $ tst) >>= lineColumn 19 4 >>= focus pp $ fromRight' $ (ezipper $ M $ nopos $ tst) >>= lineColumn 19 4 >>= repr

likewise for further processing: fromRight' $ (ezipper $ M $ t2s $ nopos $ mm) >>= lineColumn 9 0 >>= upToBinding' "a" >>= focus fromRight' $ refactor $ (rzipper $ M $ t2s $ nopos $ mm) >>= lineColumn 9 0 >>= upToBinding >>= focus

  • -------------------
>>> tst <- (silence $ runExceptT $ getModules_ ["samples"] "Test") >>= return . last . fromRight'
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 1 0 >>= focus
Left (RFail "leading white space")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 2 7 >>= focus
Left (RFail "leading white space")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 3 0 >>= focus
Left (RFail "leading white space")

handled by checkModuleKeyword:

>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 3 17 >>= focus
Left (RFail "checkModuleKeyword: position does not exist")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 0 >>= focus
Left (RFail "module keyword")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 5 >>= focus
Left (RFail "module keyword")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 6 >>= focus
Left (RFail "white space after module keyword")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 7 >>= focus
Left (RFail "module name")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 10 >>= focus
Left (RFail "module name")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 11 >>= focus
Left (RFail "white space after module name")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 12 >>= focus
Left (RFail "where keyword")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 16 >>= focus
Left (RFail "where keyword")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 17 >>= focus
Left (RFail "white space after where keyword")
>>> (ezipper $ M $ nopos $ tst) >>= lineColumn 4 19 >>= focus
Left (RFail "checkWsAfterWhereKeyword: position does not exist")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 5 0 >>= focus
  • - -- -- -- Left (RFail "white space after where keyword")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 5 5 >>= focus
  • - -- -- -- Left (RFail "checkImports: position does not exist")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 0 >>= focus
  • - -- -- -- Left (RFail "import keyword")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 5 >>= focus
  • - -- -- -- Left (RFail "import keyword")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 6 >>= focus
  • - -- -- -- Left (RFail "white space after import keyword")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 9 >>= focus
  • - -- -- -- Left (RFail "import name")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 11 >>= focus
  • - -- -- -- Left (RFail "import name")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 12 >>= focus
  • - -- -- -- Left (RFail "white space after import name")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 6 13 >>= focus
  • - -- -- -- Left (RFail "checkImports: position does not exist")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 7 0 >>= focus
  • - -- -- -- Left (RFail "import keyword")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 7 13 >>= focus
  • - -- -- -- Left (RFail "white space after import name")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 7 14 >>= focus
  • - -- -- -- Left (RFail "checkImports: position does not exist")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 8 0 >>= focus
  • - -- -- -- Left (RFail "white space after import name")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 8 3 >>= focus
  • - -- -- -- Left (RFail "findIdx: position does not exist")

some successful navigation:

  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 11 0 >>= focus
  • - -- -- -- Right (Ide {_aa = "b"})
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 11 1 >>= focus
  • - -- -- -- Left (RFail "white space after lhs of def b")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 11 2 >>= focus
  • - -- -- -- Left (RFail "equal op")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 11 3 >>= focus
  • - -- -- -- Left (RFail "white space after equal op")
  • - -- -- -- >>> (ezipper $ M $ nopos $ tst) >>= lineColumn 11 4 >>= focus
  • - -- -- -- Left (RFail "lambda token")

some examples of successful navigation (they should always lead to some particular variable, ie. not stop at a higher syntax form like :@, Lam etc):

  • - -- -- -- >>> (ezipper $ M $ tst) >>= lineColumn 21 9 >>= repr
  • - -- -- -- Right "a"

checkModuleKeyword :: (Refactoring m, HasRange (t, t1), HasDetailedRange (t, t1)) => Pos -> Token ModuleTokTy (t, t1) -> m () Source #

checkModuleName :: (HasDetailedRange (a, b), HasRange (a, b), Refactoring m) => Pos -> Nm (a, b) -> m () Source #

checkWsAfterModuleName :: (HasDetailedRange (a, b), HasRange (a, b), Refactoring m) => Pos -> Nm (a, b) -> m () Source #

checkWhereKeyword :: (Refactoring m, HasRange (t, t1), HasDetailedRange (t, t1)) => Pos -> Token WhereTy (t, t1) -> m () Source #

checkWsAfterWhereKeyword :: (Refactoring m, HasRange (t, t1), HasDetailedRange (t, t1)) => Pos -> Token WhereTy (t, t1) -> m () Source #

handleDot :: (Refactoring m, InRange t) => Pos -> Token DotTy t -> m a Source #

handleNm :: (HasRange a1, Monad m, Show a1) => Pos -> Nm a1 -> m a2 Source #

checkNm :: (HasRange a, Monad m, Show a) => Pos -> Nm a -> m () Source #

ensureInNmOrFailWith :: (HasRange t, Monad m) => Pos -> Nm t -> String -> m () Source #

checkImportTok :: (Refactoring m, HasRange (t, t1)) => Pos -> Token ImportTokTy (t, t1) -> m () Source #

handleOf :: (Refactoring m, HasRange t) => Pos -> Token OfTy t -> m a Source #

handleBy :: (Refactoring m, HasRange t) => Pos -> Token ByTy t -> m a Source #

handleIn :: (Refactoring m, HasRange t) => Pos -> Token InTy t -> m a Source #

checkImportNm :: (HasRange t, Monad m) => Pos -> Nm t -> m () Source #

checkImport :: (Decorated (t, t1), HasRange (t, t1), Refactoring m) => Pos -> ModuleImport (t, t1) -> m () Source #

findImport :: (Foldable t1, Decorated (t2, t3), HasRange (t2, t3), Refactoring m) => Pos -> t1 (ModuleImport (t2, t3)) -> m () Source #

checkImports :: (Decorated (t, t1), HasDetailedRange (t, t1), HasRange (t, t1), Refactoring m) => Pos -> [ModuleImport (t, t1)] -> m () Source #

checkBinder :: (Decorated (a, b), HasRange (a, b), HasDetailedRange (a, b), Pretty a, InRange (a, b), Refactoring m) => Pos -> Pattern (a, b) -> m () Source #

findIdx :: (HasDetailedRange [x], HasRange [x], Monad m, InRange x) => Pos -> [x] -> m Int Source #

lineColumn :: (Integral a1, Integral a2, Deco a3, Refactoring m, HasDetailedRange (a3, Delta), HasRange (a3, Delta), InRange (a3, Delta), Pretty a3, Show a3, Ord a3) => a1 -> a2 -> Zipper a3 -> m (Zipper a3) Source #

topos :: (Integral a1, Integral a2) => a1 -> a2 -> Pos Source #