[ fix ] preserve spacing during update

This commit is contained in:
Guillaume ALLAIS 2020-05-20 17:07:40 +01:00
parent 3869233ce0
commit 53a7cf36a1
6 changed files with 25 additions and 9 deletions

View File

@ -56,22 +56,23 @@ doUpdates : {auto u : Ref UPD (List String)} ->
Core (List SourcePart)
doUpdates defs ups [] = pure []
doUpdates defs ups (LBrace :: xs)
= case dropSpace xs of
= let (ws, nws) = spanSpace xs in map (LBrace :: ws ++) $
case nws of
Name n :: RBrace :: rest =>
pure (LBrace :: Name n ::
pure (Name n ::
Whitespace " " :: Equal :: Whitespace " " ::
!(doUpdates defs ups (Name n :: RBrace :: rest)))
Name n :: Equal :: rest =>
pure (LBrace :: Name n ::
pure (Name n ::
Whitespace " " :: Equal :: Whitespace " " ::
!(doUpdates defs ups rest))
_ => pure (LBrace :: !(doUpdates defs ups xs))
_ => doUpdates defs ups xs
where
dropSpace : List SourcePart -> List SourcePart
dropSpace [] = []
dropSpace (RBrace :: xs) = RBrace :: xs
dropSpace (Whitespace _ :: xs) = dropSpace xs
dropSpace (x :: xs) = x :: dropSpace xs
spanSpace : List SourcePart -> (List SourcePart, List SourcePart)
spanSpace [] = ([], [])
spanSpace (RBrace :: xs) = ([], RBrace :: xs)
spanSpace (w@(Whitespace _) :: xs) = mapFst (w ::) (spanSpace xs)
spanSpace (x :: xs) = map (x ::) (spanSpace xs)
doUpdates defs ups (Name n :: xs)
= case lookup n ups of
Nothing => pure (Name n :: !(doUpdates defs ups xs))

View File

@ -52,6 +52,7 @@ idrisTests
"interactive001", "interactive002", "interactive003", "interactive004",
"interactive005", "interactive006", "interactive007", "interactive008",
"interactive009", "interactive010", "interactive011", "interactive012",
"interactive013",
-- Literate
"literate001", "literate002", "literate003", "literate004",
"literate005", "literate006", "literate007", "literate008",

View File

@ -0,0 +1,4 @@
module Spacing
id : {n : Nat} -> Nat
id { n} = ?a

View File

@ -0,0 +1,5 @@
1/1: Building Spacing (Spacing.idr)
Spacing> id { n = 0} = ?a_1
id { n = (S k)} = ?a_2
Spacing>
Bye for now!

View File

@ -0,0 +1,2 @@
:cs 4 6 n
:q

View File

@ -0,0 +1,3 @@
$1 --no-banner Spacing.idr < input
rm -rf build