diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 294609866..a3c7d584c 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -225,7 +225,7 @@ toTermName source term = case unwrap term of _ -> toTermName' base <> "[" <> toTermName' element <> "]" (_, _) -> toTermName' base <> "[" <> toTermName' element <> "]" S.VarAssignment varId _ -> toTermName' varId - S.VarDecl decl -> toTermName' decl + S.VarDecl decl _ -> toTermName' decl -- TODO: We should remove Case from Syntax since I don't think we should ever -- evaluate Case as a single toTermName Text - joshvera S.Case expr _ -> termNameFromSource expr diff --git a/src/Language.hs b/src/Language.hs index 62e9acf43..d1408f0c0 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -60,7 +60,7 @@ termConstructor source sourceSpan name range children _ = pure $! cofree ((range .: Other name .: sourceSpan' .: RNil) :< syntax) toVarDecl :: (HasField fields Category) => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields) -toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl child +toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl child Nothing toTuple :: Term (S.Syntax Text) (Record fields) -> [Term (S.Syntax Text) (Record fields)] toTuple child | S.Indexed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)] diff --git a/src/Language/Go.hs b/src/Language/Go.hs index 72315d31b..129ca3491 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -195,7 +195,11 @@ termConstructor source sourceSpan name range children _ = case name of withDefaultInfo (S.Indexed assignments') constSpecToVarAssignment = toVarAssignment . toList . unwrap toVarAssignment = \case - [idList, expressionList] -> do + [idList, ty] | category (extract ty) == Identifier -> do + let ids = toList (unwrap idList) + idList' <- mapM (\id -> withRanges range VarDecl [id] (S.VarDecl id (Just ty))) ids + withRanges range ExpressionStatements idList' (S.Indexed idList') + [idList, expressionList] | category (extract expressionList) == Other "expression_list" -> do assignments' <- sequenceA $ zipWith (\id expr -> withCategory VarAssignment $ S.VarAssignment id expr) (toList $ unwrap idList) (toList $ unwrap expressionList) @@ -204,8 +208,7 @@ termConstructor source sourceSpan name range children _ = case name of assignments' <- sequenceA $ zipWith (\id expr -> withCategory VarAssignment $ S.VarAssignment id expr) (toList $ unwrap idList) (toList $ unwrap expressionList) withDefaultInfo (S.Indexed assignments') - [idList] -> do - withDefaultInfo (S.Indexed [idList]) + [idList] -> withDefaultInfo (S.Indexed [idList]) rest -> withRanges range Error rest (S.Error rest) withRanges originalRange category' terms syntax = do @@ -238,7 +241,6 @@ categoryForGoName = \case "slice_expression" -> Slice "parameters" -> Args "short_var_declaration" -> VarDecl - "var_declaration" -> VarDecl "var_spec" -> VarAssignment "assignment_statement" -> Assignment "source_file" -> Module diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index 9a9726da0..4ed85ceac 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -110,7 +110,7 @@ syntaxToTermField syntax = case syntax of S.MemberAccess identifier value -> [ "identifier" .= identifier ] <> [ "value" .= value ] S.MethodCall identifier methodIdentifier parameters -> [ "identifier" .= identifier ] <> [ "methodIdentifier" .= methodIdentifier ] <> [ "parameters" .= parameters ] S.Operator syntaxes -> [ "operatorSyntaxes" .= syntaxes ] - S.VarDecl declaration -> [ "declaration" .= declaration ] + S.VarDecl declaration ty -> [ "declaration" .= declaration ] <> [ "type" .= ty] S.VarAssignment identifier value -> [ "identifier" .= identifier ] <> [ "value" .= value ] S.SubscriptAccess identifier property -> [ "identifier" .= identifier ] <> [ "property" .= property ] S.Switch expression cases -> [ "expression" .= expression ] <> [ "cases" .= cases ] diff --git a/src/Syntax.hs b/src/Syntax.hs index 84c1356d8..81eea5df1 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -39,7 +39,7 @@ data Syntax a f -- | An operator can be applied to a list of syntaxes. | Operator [f] -- | A variable declaration. e.g. var foo; - | VarDecl f + | VarDecl f (Maybe f) -- | A variable assignment in a variable declaration. var foo = bar; | VarAssignment { varId :: f, varValue :: f } -- | A subscript access contains a syntax, and another syntax that indefies a property or value in the first syntax.