Skip to content

Commit

Permalink
Merge pull request #5117 from unisonweb/24-06-21-fix-ability-list-lex…
Browse files Browse the repository at this point in the history
…-bug
  • Loading branch information
aryairani committed Jun 21, 2024
2 parents 4cda154 + 0c2e8c5 commit 2010b57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion unison-syntax/src/Unison/Syntax/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ token'' tok p = do
pops p = do
env <- S.get
let l = layout env
if top l == column p && topBlockName l /= Just "(" -- don't emit virtual semis inside parens
if top l == column p && topContainsVirtualSemis l
then pure [Token (Semi True) p p]
else
if column p > top l || topHasClosePair l
Expand All @@ -234,6 +234,12 @@ token'' tok p = do
then S.put (env {layout = pop l}) >> ((Token Close p p :) <$> pops p)
else error "impossible"

-- don't emit virtual semis in (, {, or [ blocks
topContainsVirtualSemis :: Layout -> Bool
topContainsVirtualSemis = \case
[] -> False
((name, _) : _) -> name /= "(" && name /= "{" && name /= "["

topHasClosePair :: Layout -> Bool
topHasClosePair [] = False
topHasClosePair ((name, _) : _) =
Expand Down
8 changes: 7 additions & 1 deletion unison-syntax/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ test =
[Textual "test escaped quotes \"in quotes\""],
t "\"\\n \\t \\b \\a\"" [Textual "\n \t \b \a"],
-- Delayed string
t "'\"\"" [Reserved "'", Textual ""]
t "'\"\"" [Reserved "'", Textual ""],
-- https://github.com/unisonweb/unison/issues/4683
-- don't emit virtual semis in ability lists or normal lists
t "{foo\n,bar}" [Open "{", simpleWordyId "foo", Reserved ",", simpleWordyId "bar", Close],
t "{foo\n ,bar}" [Open "{", simpleWordyId "foo", Reserved ",", simpleWordyId "bar", Close],
t "[foo\n,bar]" [Open "[", simpleWordyId "foo", Reserved ",", simpleWordyId "bar", Close],
t "[foo\n ,bar]" [Open "[", simpleWordyId "foo", Reserved ",", simpleWordyId "bar", Close]
]

t :: String -> [Lexeme] -> Test ()
Expand Down

0 comments on commit 2010b57

Please sign in to comment.