1
1
mirror of https://github.com/github/semantic.git synced 2024-12-03 00:16:52 +03:00

Assign Set comprehension; condense comprehension assignments to a single assignment

This commit is contained in:
Rick Winfrey 2017-06-01 15:40:06 -07:00
parent 44ab33ee29
commit 3a37e1e8fd

View File

@ -104,8 +104,7 @@ expression = statement
<|> dottedName
<|> await
<|> lambda
<|> generatorExpression
<|> listComprehension
<|> comprehension
dottedName :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location)
dottedName = makeTerm <$> symbol DottedName <*> children (Expression.ScopeResolution <$> many expression)
@ -289,15 +288,15 @@ lambda = makeTerm <$> symbol Lambda <*> children (Declaration.Function <$> lambd
lambdaParameters = many identifier
lambdaBody = expression
generatorExpression :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location)
generatorExpression = makeTerm <$> symbol GeneratorExpression <*> children (Declaration.Comprehension <$> expression <* symbol Variables <*> children (many expression) <*> (flip (foldr makeGeneratorExpression) <$> many nestedGeneratorExpression <*> expression))
where makeGeneratorExpression (loc, makeRest) rest = makeTerm loc (makeRest rest)
nestedGeneratorExpression = (,) <$> location <*> (Declaration.Comprehension <$> expression <* symbol Variables <*> children (many expression))
listComprehension :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location)
listComprehension = makeTerm <$> symbol ListComprehension <*> children (Declaration.Comprehension <$> expression <* symbol Variables <*> children (many expression) <*> (flip (foldr makeListComprehension) <$> many nestedListComprehension <*> expression))
where makeListComprehension (loc, makeRest) rest = makeTerm loc (makeRest rest)
nestedListComprehension = (,) <$> location <*> (Declaration.Comprehension <$> expression <* symbol Variables <*> children (many expression))
comprehension :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location)
comprehension = makeTerm <$> symbol GeneratorExpression <*> children (comprehensionSyntax constructor expression)
<|> makeTerm <$> symbol ListComprehension <*> children (comprehensionSyntax constructor expression)
<|> makeTerm <$> symbol SetComprehension <*> children (comprehensionSyntax constructor expression)
where
constructor = Declaration.Comprehension
comprehensionSyntax constructor preceeding = constructor <$> preceeding <* symbol Variables <*> children (many expression) <*> (flip (foldr makeComprehension) <$> many nestedComprehension <*> expression)
makeComprehension (loc, makeRest) rest = makeTerm loc (makeRest rest)
nestedComprehension = (,) <$> location <*> (Declaration.Comprehension <$> expression <* symbol Variables <*> children (many expression))
makeTerm :: HasCallStack => InUnion Syntax' f => a -> f (Term Syntax a) -> Term Syntax a
makeTerm a f = cofree (a :< inj f)