diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 264fc16ca..1574f3471 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -223,7 +223,9 @@ toTermName source term = case unwrap term of (S.Negate condition) -> termNameFromSource condition _ -> termNameFromSource expr S.For clauses _ -> termNameFromChildren term clauses - S.While expr _ -> toTermName' expr + S.While expr _ -> case unwrap expr of + (S.Negate condition) -> termNameFromSource condition + _ -> toTermName' expr S.DoWhile _ expr -> toTermName' expr S.Throw expr -> termNameFromSource expr S.Constructor expr -> toTermName' expr @@ -240,7 +242,6 @@ toTermName source term = case unwrap term of S.Export (Just identifier) [] -> "{ " <> toTermName' identifier <> " }" S.Export (Just identifier) expr -> "{ " <> intercalate ", " (termNameFromSource <$> expr) <> " }" <> " from " <> toTermName' identifier S.ConditionalAssignment id _ -> toTermName' id - S.Until expr _ -> toTermName' expr S.Negate expr -> toTermName' expr S.Rescue args _ -> intercalate ", " $ toTermName' <$> args where toTermName' = toTermName source diff --git a/src/Language/Ruby.hs b/src/Language/Ruby.hs index cc5633e4f..420867390 100644 --- a/src/Language/Ruby.hs +++ b/src/Language/Ruby.hs @@ -35,6 +35,16 @@ termConstructor source sourceSpan name range children condition <- withDefaultInfo (S.Negate expr) withDefaultInfo $ S.If condition rest _ -> withDefaultInfo $ S.Error children + | name == "until_modifier" = case children of + [ lhs, rhs ] -> do + condition <- withDefaultInfo (S.Negate rhs) + withDefaultInfo $ S.While condition [lhs] + _ -> withDefaultInfo $ S.Error children + | name == "until_statement" = case children of + ( expr : rest ) -> do + condition <- withDefaultInfo (S.Negate expr) + withDefaultInfo $ S.While condition rest + _ -> withDefaultInfo $ S.Error children | otherwise = withDefaultInfo $ case (name, children) of ("array", _ ) -> S.Array children ("assignment", [ identifier, value ]) -> S.Assignment identifier value @@ -100,11 +110,6 @@ termConstructor source sourceSpan name range children ("rescue_modifier", [lhs, rhs] ) -> S.Rescue [lhs] [rhs] ("rescue_modifier", _ ) -> S.Error children ("return_statement", _ ) -> S.Return (listToMaybe children) - ("unless_statement", _ ) -> S.Error children - ("until_modifier", [ lhs, condition ]) -> S.Until condition [lhs] - ("until_modifier", _ ) -> S.Error children - ("until_statement", expr : rest ) -> S.Until expr rest - ("until_statement", _ ) -> S.Error children ("while_modifier", [ lhs, condition ]) -> S.While condition [lhs] ("while_modifier", _ ) -> S.Error children ("while_statement", expr : rest ) -> S.While expr rest diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index 665d22e3c..c3178fc49 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -127,7 +127,6 @@ syntaxToTermField syntax = case syntax of S.Export identifier statements -> [ "identifier" .= identifier ] <> [ "statements" .= statements ] S.ConditionalAssignment id value -> [ "conditionalIdentifier" .= id ] <> [ "value" .= value ] S.Yield expr -> [ "yieldExpression" .= expr ] - S.Until expr body -> [ "untilExpr" .= expr ] <> [ "untilBody" .= body ] S.Negate expr -> [ "negate" .= expr ] S.Rescue args expressions -> [ "args" .= args ] <> childrenFields expressions where childrenFields c = [ "children" .= c ] diff --git a/src/Syntax.hs b/src/Syntax.hs index 1618bbe39..e3763fb1f 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -79,8 +79,7 @@ data Syntax a f -- | A conditional assignment represents expressions whose operator classifies as conditional (e.g. ||= or &&=). | ConditionalAssignment { conditionalAssignmentId :: f, value :: f } | Yield (Maybe f) - | Until { untilExpr :: f, untilBody :: [f] } - -- | A negation has a single expression. + -- | A negation of a single expression. | Negate f -- | A rescue block has a list of arguments to rescue and a list of expressions. | Rescue [f] [f]