1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 14:13:27 +03:00

Allow nested block comments (#2075)

- Closes #2070
This commit is contained in:
Jan Mas Rovira 2023-05-15 09:57:23 +02:00 committed by GitHub
parent 0462d623f2
commit 2b0668b55a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 4 deletions

View File

@ -91,10 +91,21 @@ space' special =
special
(notFollowedBy (P.chunk Str.pragmasStart))
(_commentText, _commentInterval) <- interval $ do
void (P.chunk "{-")
pack <$> P.manyTill anySingle (P.chunk "-}")
void start
go 1 ""
hspace_
return Comment {..}
where
start :: m Text = P.chunk "{-"
ending :: m Text = P.chunk "-}"
go :: Int -> Text -> m Text
go n acc = do
(txt, startOrEnd) <- P.manyTill_ anySingle (Left <$> start <|> Right <$> ending)
case startOrEnd of
Left st -> go (n + 1) (acc <> pack txt <> st)
Right en
| n > 1 -> go (n - 1) (acc <> pack txt <> en)
| otherwise -> return (acc <> pack txt)
integer' :: ParsecS r (Integer, Interval) -> ParsecS r (Integer, Interval)
integer' dec = do

View File

@ -5,7 +5,7 @@ module test003;
Multiline comment
{- nested comments don't work -- }
{- nested comments work -}
-}

View File

@ -4,6 +4,6 @@
Multiline comment
{- nested comments don't work -- }
{- nested comments work -}
-}

View File

@ -3,5 +3,25 @@ module Parsing;
let' : Type;
let' := Type;
{- block comment -}
-- line comment
-- line comment 2
{- block comment 2
block comment 2
-}
{- Nesting
{- Nesting
{- Nesting
-}
-}
-}
TypeMine : Type;
TypeMine := Type;