diff --git a/src/Category.hs b/src/Category.hs index 22e49924a..238c8fc20 100644 --- a/src/Category.hs +++ b/src/Category.hs @@ -45,6 +45,8 @@ data Category | ArrayLiteral -- | An assignment expression. | Assignment + -- | A math assignment expression. + | MathAssignment -- | A member access expression. | MemberAccess -- | A subscript access expression. diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 2261815a7..014fa9b29 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -77,6 +77,7 @@ instance HasCategory Category where Category.Switch -> "switch statement" Category.Case -> "case statement" Category.SubscriptAccess -> "subscript access" + Category.MathAssignment -> "math assignment" Identifier -> "identifier" IntegerLiteral -> "integer" Other s -> s @@ -138,6 +139,7 @@ termToDiffInfo term = case runCofree term of (info :< Syntax.FunctionCall identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] (info :< Syntax.Function identifier _ _) -> [ DiffInfo (toCategoryName info) (maybe "anonymous" toTermName identifier) ] (info :< Syntax.Assignment identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] + (info :< Syntax.MathAssignment identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] memberAccess@(info :< Syntax.MemberAccess{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree memberAccess) ] subscriptAccess@(info :< Syntax.SubscriptAccess{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree subscriptAccess) ] methodCall@(info :< Syntax.MethodCall{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree methodCall) ] diff --git a/src/Interpreter.hs b/src/Interpreter.hs index d9067eb18..ab9522cdd 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -60,6 +60,7 @@ run construct comparable cost algorithm = case runFree algorithm of recur (FunctionCall a' as') (FunctionCall b' bs') | length as' == length bs' = annotate $ FunctionCall (diffTerms' a' b') (zipWith diffTerms' as' bs') recur (Function a' as' aExprs') (Function b' bs' bExprs') = annotate $ Function (liftA2 diffTerms' a' b') (liftA2 diffTerms' as' bs') (diffTerms' aExprs' bExprs') recur (Assignment a' as') (Assignment b' bs') = annotate $ Assignment (diffTerms' a' b') (diffTerms' as' bs') + recur (MathAssignment a' as') (MathAssignment b' bs') = annotate $ MathAssignment (diffTerms' a' b') (diffTerms' as' bs') recur (MemberAccess a' as') (MemberAccess b' bs') = annotate $ MemberAccess (diffTerms' a' b') (diffTerms' as' bs') recur (SubscriptAccess a' as') (SubscriptAccess b' bs') = annotate $ SubscriptAccess (diffTerms' a' b') (diffTerms' as' bs') recur (MethodCall a' as' aParams') (MethodCall b' bs' bParams') = annotate $ MethodCall (diffTerms' a' b') (diffTerms' as' bs') (diffTerms' aParams' bParams') diff --git a/src/Parser.hs b/src/Parser.hs index 9da2cdace..aa07e889f 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -44,6 +44,8 @@ termConstructor source info = cofree . construct construct [] = withDefaultInfo $ S.Leaf . pack . toString $ slice (characterRange info) source construct children | Assignment == category info = case children of (identifier:value:[]) -> withDefaultInfo $ S.Assignment identifier value + construct children | MathAssignment == category info = case children of + (identifier:value:[]) -> withDefaultInfo $ S.MathAssignment identifier value construct children | MemberAccess == category info = case children of (base:property:[]) -> withDefaultInfo $ S.MemberAccess base property construct children | SubscriptAccess == category info = case children of diff --git a/src/Syntax.hs b/src/Syntax.hs index 684ea5fee..6511367e5 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -23,6 +23,8 @@ data Syntax | Function { id :: (Maybe f), params :: (Maybe f), expressions :: f } -- | An assignment has an identifier where f can be a member access, and the value is another syntax element (function call, leaf, etc.) | Assignment { assignmentId :: f, value :: f } + -- | A math assignment represents expressions whose operator classifies as mathy (e.g. += or *=). + | MathAssignment { mathAssignmentId :: f, value :: f } -- | A member access contains a syntax, and another syntax that identifies a property or value in the first syntax. -- | e.g. in Javascript x.y represents a member access syntax. | MemberAccess { memberId :: f, property :: f } diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 4a253dad0..ecb55db71 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -63,6 +63,7 @@ defaultCategoryForNodeName name = case name of "var_assignment" -> VarAssignment "var_declaration" -> VarDecl "switch_statement" -> Switch + "math_assignment" -> MathAssignment "case" -> Case "true" -> Boolean "false" -> Boolean