1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

New shape for yield statements

This commit is contained in:
Timothy Clem 2016-12-05 15:56:18 -08:00
parent 47402c7c8a
commit 2ee93b4525
5 changed files with 10 additions and 9 deletions

View File

@ -156,6 +156,7 @@ determiner (LeafInfo "when block" _ _) = "a"
determiner (LeafInfo "anonymous function" _ _) = "an"
determiner (LeafInfo "break statement" _ _) = "a"
determiner (LeafInfo "continue statement" _ _) = "a"
determiner (LeafInfo "yield statement" "" _) = "a"
determiner (LeafInfo "return statement" "" _) = "a"
determiner (BranchInfo bs _ _) = determiner (last bs)
determiner _ = "the"
@ -180,6 +181,7 @@ toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
(LeafInfo cName@"subshell command" termName _) -> toDoc termName <+> toDoc cName
(LeafInfo cName@"break statement" _ _) -> toDoc cName
(LeafInfo cName@"continue statement" _ _) -> toDoc cName
(LeafInfo cName@"yield statement" "" _) -> toDoc cName
(LeafInfo cName@"return statement" "" _) -> toDoc cName
LeafInfo{..} -> squotes (toDoc termName) <+> toDoc categoryName
node -> panic $ "Expected a leaf info but got a: " <> show node
@ -230,8 +232,8 @@ toTermName source term = case unwrap term of
S.Operator _ -> termNameFromSource term
S.Object kvs -> "{ " <> intercalate ", " (toTermName' <$> kvs) <> " }"
S.Pair k v -> toKeyName k <> toArgName v
S.Yield expr -> maybe "empty" toTermName' expr
S.Return children -> intercalate ", " (termNameFromSource <$> children)
S.Yield children -> intercalate ", " (termNameFromSource <$> children)
S.Error _ -> termNameFromSource term
S.If expr _ -> termNameFromSource expr
S.For clauses _ -> termNameFromChildren term clauses

View File

@ -103,8 +103,7 @@ termConstructor source sourceSpan name range children
_ -> S.Export (Just statements) []
("export_statement", _ ) -> S.Error children
("break_statement", [ expr ] ) -> S.Break expr
("yield_statement", [ expr ] ) -> S.Yield (Just expr)
("yield_statement", [ ] ) -> S.Yield Nothing
("yield_statement", _ ) -> S.Yield children
_ | name `elem` forStatements -> case unsnoc children of
Just (exprs, body) -> S.For exprs [body]
_ -> S.Error children

View File

@ -122,7 +122,7 @@ termConstructor source sourceSpan name range children
("while_modifier", _ ) -> S.Error children
("while_statement", expr : rest ) -> S.While expr rest
("while_statement", _ ) -> S.Error children
("yield", _ ) -> S.Yield (listToMaybe children)
("yield", _ ) -> S.Yield children
_ | name `elem` operators -> S.Operator children
_ | name `elem` functions -> case children of
[ body ] -> S.AnonymousFunction [] [body]

View File

@ -79,7 +79,7 @@ data Syntax a f
| Export (Maybe f) [f]
-- | A conditional assignment represents expressions whose operator classifies as conditional (e.g. ||= or &&=).
| ConditionalAssignment { conditionalAssignmentId :: f, value :: f }
| Yield (Maybe f)
| Yield [f]
-- | A negation of a single expression.
| Negate f
-- | A rescue block has a list of arguments to rescue and a list of expressions.

View File

@ -54,7 +54,7 @@
]
}
},
"summary": "Added the 'empty' yield statement"
"summary": "Added a yield statement"
},
{
"span": {
@ -191,7 +191,7 @@
]
}
},
"summary": "Deleted the 'empty' yield statement"
"summary": "Deleted a yield statement"
},
{
"span": {
@ -221,7 +221,7 @@
]
}
},
"summary": "Added the 'empty' yield statement"
"summary": "Added a yield statement"
}
]
},
@ -301,7 +301,7 @@
]
}
},
"summary": "Deleted the 'empty' yield statement"
"summary": "Deleted a yield statement"
}
]
},