Add parens to annotation of lexed symboly segments

This commit is contained in:
Chris Penner 2024-02-12 10:46:38 -08:00
parent 6a6b7b8643
commit b00acbe182
3 changed files with 35 additions and 2 deletions

View File

@ -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

View File

@ -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
@ -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

View File

@ -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_