mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
fixes #4233 - term declarations should not allow hashes in term names
This commit is contained in:
parent
39c3bd558f
commit
cd048f7bdd
@ -76,3 +76,4 @@ The format for this list: name, GitHub handle
|
||||
* Mario Bašić (@mabasic)
|
||||
* Chris Krycho (@chriskrycho)
|
||||
* Hatim Khambati (@hatimkhambati26)
|
||||
* Kyle Goetz (@kylegoetz)
|
||||
|
@ -985,7 +985,7 @@ infixAppOrBooleanOp = chainl1 term4 (or <|> and <|> infixApp)
|
||||
typedecl :: (Monad m, Var v) => P v m (L.Token v, Type v Ann)
|
||||
typedecl =
|
||||
(,)
|
||||
<$> P.try (prefixDefinitionName <* reserved ":")
|
||||
<$> P.try (prefixTermName <* reserved ":")
|
||||
<*> TypeParser.valueType
|
||||
<* semi
|
||||
|
||||
@ -1053,8 +1053,8 @@ binding = label "binding" do
|
||||
arg2 <- prefixDefinitionName
|
||||
pure (ann arg1, op, [arg1, arg2])
|
||||
let prefixLhs = do
|
||||
v <- prefixDefinitionName
|
||||
vs <- many prefixDefinitionName
|
||||
v <- prefixTermName
|
||||
vs <- many prefixTermName
|
||||
pure (ann v, v, vs)
|
||||
let lhs :: P v m (Ann, L.Token v, [L.Token v])
|
||||
lhs = infixLhs <|> prefixLhs
|
||||
|
@ -297,6 +297,19 @@ prefixDefinitionName :: (Var v) => P v m (L.Token v)
|
||||
prefixDefinitionName =
|
||||
wordyDefinitionName <|> parenthesize symbolyDefinitionName
|
||||
|
||||
-- Parse a prefix identifier e.g. Foo or (+), rejecting any hash
|
||||
-- This is useful for term declarations, where type signatures and term names should not have hashes.
|
||||
prefixTermName :: (Var v) => P v (L.Token v)
|
||||
prefixTermName = wordyTermName <|> parenthesize symbolyTermName
|
||||
where
|
||||
wordyTermName = queryToken $ \case
|
||||
L.WordyId s Nothing -> Just $ Var.nameds s
|
||||
L.Blank s -> Just $ Var.nameds ("_" <> s)
|
||||
_ -> Nothing
|
||||
symbolyTermName = queryToken $ \case
|
||||
L.SymbolyId s Nothing -> Just $ Var.nameds s
|
||||
_ -> Nothing
|
||||
|
||||
-- Parse a wordy identifier e.g. Foo, discarding any hash
|
||||
wordyDefinitionName :: (Var v) => P v m (L.Token v)
|
||||
wordyDefinitionName = queryToken $ \case
|
||||
|
Loading…
Reference in New Issue
Block a user