Skip to content

Commit

Permalink
Merge pull request #4369 from unisonweb/fix/pretty-printing
Browse files Browse the repository at this point in the history
Fix parser issue caused by virtual semicolons being emitted inside parens
  • Loading branch information
stew authored Nov 6, 2023
2 parents 2d4215d + 4a43458 commit ebc848a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
31 changes: 31 additions & 0 deletions unison-src/transcripts-round-trip/main.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,37 @@ So we can see the pretty-printed output:
_ -> 2
go (SomethingUnusuallyLong "one" "two" "three")
stew_issue : ()
stew_issue =
error x = ()
a ++ b = 0
toText a = a
Debug : a -> b -> ()
Debug a b = ()
error (Debug None '(Debug "Failed " 42))
stew_issue2 : ()
stew_issue2 =
error x = ()
a ++ b = 0
toText a = a
Debug : a -> b -> ()
Debug a b = ()
error (Debug None '("Failed " ++ toText 42))
stew_issue3 : ()
stew_issue3 =
id x = x
error x = ()
a ++ b = 0
blah x y = 99
toText a = a
configPath = 0
Debug a b = ()
error
(Debug None '("Failed to get timestamp of config file "
++ toText configPath))
test3 : '('('r))
test3 = do
run : Nat -> a
Expand Down
36 changes: 35 additions & 1 deletion unison-src/transcripts-round-trip/reparses-with-same-hash.u
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,38 @@ fix_4258 x y z =
_ = "fix_4258"
()

fix_4258_example = fix_4258 1 () 2
fix_4258_example = fix_4258 1 () 2

-- previously, lexer was emitting virtual semicolons inside parens, which
-- led to some very odd parse errors in cases like these

stew_issue =
error x = ()
(++) a b = 0
toText a = a
Debug : a -> b -> ()
Debug a b = ()
error
(Debug None '(Debug "Failed " -- virtual semicolon here was tripping up parser
42))
stew_issue2 =
error x = ()
(++) a b = 0
toText a = a
Debug : a -> b -> ()
Debug a b = ()
error
(Debug None '("Failed " ++
toText 42))

stew_issue3 =
id x = x
error x = ()
(++) a b = 0
blah x y = 99
toText a = a
configPath = 0
Debug a b = ()
error
(Debug None '("Failed to get timestamp of config file " ++
toText configPath))
2 changes: 1 addition & 1 deletion unison-syntax/src/Unison/Syntax/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ token'' tok p = do
pops p = do
env <- S.get
let l = layout env
if top l == column p
if top l == column p && topBlockName l /= Just "(" -- don't emit virtual semis inside parens
then pure [Token (Semi True) p p]
else
if column p > top l || topHasClosePair l
Expand Down

0 comments on commit ebc848a

Please sign in to comment.