Skip to content

Commit

Permalink
Add parens to annotation of lexed symboly segments
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Feb 12, 2024
1 parent 6a6b7b8 commit b00acbe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
9 changes: 9 additions & 0 deletions unison-src/transcripts/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ x y =
x + y
-- Should keep comments after
-- symbolyDefinition
(<|>) : Nat -> Nat -> (Nat, Nat)
(<|>) a b = (a, b)
symbolyEndOfBlock =
use List +:
(+:)
-- Test for a previous regression that added extra brackets.
oneLiner = {{ one liner }}
-- After
Expand Down
16 changes: 16 additions & 0 deletions unison-src/transcripts/formatter.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ x y =
x + y
-- Should keep comments after
-- symbolyDefinition
(<|>) : Nat -> Nat -> (Nat, Nat)
(<|>) a b = (a, b)
f x y =
use List +:
(+:)
-- Test for a previous regression that added extra brackets.
oneLiner = {{ one liner }}
-- After
Expand Down Expand Up @@ -94,6 +103,13 @@ x y =
x + y
-- Should keep comments after
-- symbolyDefinition
(<|>) : Nat -> Nat -> (Nat, Nat)
a <|> b = (a, b)
f x y = (+:)
-- Test for a previous regression that added extra brackets.
oneLiner = {{ one liner }}
-- After
Expand Down
12 changes: 10 additions & 2 deletions unison-syntax/src/Unison/Syntax/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,16 @@ symbolyDefinitionName = queryToken $ \case
L.SymbolyId n -> Just $ Name.toVar (HQ'.toName n)
_ -> Nothing

parenthesize :: (Ord v) => P v m a -> P v m a
parenthesize p = P.try (openBlockWith "(" *> p) <* closeBlock
-- | Expect parentheses around a token, includes the parentheses within the start/end
-- annotations of the resulting token.
parenthesize :: (Ord v) => P v m (L.Token a) -> P v m (L.Token a)
parenthesize p = do
(start, a) <- P.try do
start <- L.start <$> openBlockWith "("
a <- p
pure (start, a)
end <- L.end <$> closeBlock
pure (L.Token {payload = L.payload a, start, end})

hqPrefixId, hqInfixId :: (Ord v) => P v m (L.Token (HQ.HashQualified Name))
hqPrefixId = hqWordyId_ <|> parenthesize hqSymbolyId_
Expand Down

0 comments on commit b00acbe

Please sign in to comment.