1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Update assignment for single list comprehensions

This commit is contained in:
Rick Winfrey 2017-08-09 15:27:10 -07:00
parent 77d53e9127
commit f9f2e46059

View File

@ -456,15 +456,12 @@ none :: Assignment
none = makeTerm <$> symbol None <*> (Literal.Null <$ source)
comprehension :: Assignment
comprehension = makeTerm <$> symbol GeneratorExpression <*> children (comprehensionDeclaration expression)
<|> makeTerm <$> symbol ListComprehension <*> children (comprehensionDeclaration expression)
<|> makeTerm <$> symbol SetComprehension <*> children (comprehensionDeclaration expression)
<|> makeTerm <$> symbol DictionaryComprehension <*> children (comprehensionDeclaration keyValue)
where
keyValue = makeTerm <$> location <*> (Literal.KeyValue <$> expression <*> expression)
comprehensionDeclaration preceeding = Declaration.Comprehension <$ many comment <*> 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))
comprehension = symbol ListComprehension >>= \ loc -> children (mk loc <$> expression <*> forInClause <*> (ifClause <|> emptyTerm))
where forInClause = symbol ForInClause *> children ((,) <$> variables <*> expressions)
variables = symbol Variables *> children expression
ifClause = symbol IfClause *> children expression
mk loc expr (bindings, context) ifExpr = makeTerm loc (Declaration.Comprehension expr bindings context ifExpr)
conditionalExpression :: Assignment
conditionalExpression = makeTerm <$> symbol ConditionalExpression <*> children (