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

Add support for MathAssignment Category and Syntax

This commit is contained in:
Rick Winfrey 2016-06-17 14:57:51 -05:00
parent dae03ef31e
commit 76c4037933
6 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,8 @@ data Category
| ArrayLiteral | ArrayLiteral
-- | An assignment expression. -- | An assignment expression.
| Assignment | Assignment
-- | A math assignment expression.
| MathAssignment
-- | A member access expression. -- | A member access expression.
| MemberAccess | MemberAccess
-- | A subscript access expression. -- | A subscript access expression.

View File

@ -77,6 +77,7 @@ instance HasCategory Category where
Category.Switch -> "switch statement" Category.Switch -> "switch statement"
Category.Case -> "case statement" Category.Case -> "case statement"
Category.SubscriptAccess -> "subscript access" Category.SubscriptAccess -> "subscript access"
Category.MathAssignment -> "math assignment"
Identifier -> "identifier" Identifier -> "identifier"
IntegerLiteral -> "integer" IntegerLiteral -> "integer"
Other s -> s Other s -> s
@ -138,6 +139,7 @@ termToDiffInfo term = case runCofree term of
(info :< Syntax.FunctionCall identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ] (info :< Syntax.FunctionCall identifier _) -> [ DiffInfo (toCategoryName info) (toTermName identifier) ]
(info :< Syntax.Function identifier _ _) -> [ DiffInfo (toCategoryName info) (maybe "anonymous" toTermName identifier) ] (info :< Syntax.Function identifier _ _) -> [ DiffInfo (toCategoryName info) (maybe "anonymous" toTermName identifier) ]
(info :< Syntax.Assignment identifier _) -> [ DiffInfo (toCategoryName info) (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) ] memberAccess@(info :< Syntax.MemberAccess{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree memberAccess) ]
subscriptAccess@(info :< Syntax.SubscriptAccess{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree subscriptAccess) ] subscriptAccess@(info :< Syntax.SubscriptAccess{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree subscriptAccess) ]
methodCall@(info :< Syntax.MethodCall{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree methodCall) ] methodCall@(info :< Syntax.MethodCall{}) -> [ DiffInfo (toCategoryName info) (toTermName $ cofree methodCall) ]

View File

@ -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 (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 (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 (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 (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 (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') recur (MethodCall a' as' aParams') (MethodCall b' bs' bParams') = annotate $ MethodCall (diffTerms' a' b') (diffTerms' as' bs') (diffTerms' aParams' bParams')

View File

@ -44,6 +44,8 @@ termConstructor source info = cofree . construct
construct [] = withDefaultInfo $ S.Leaf . pack . toString $ slice (characterRange info) source construct [] = withDefaultInfo $ S.Leaf . pack . toString $ slice (characterRange info) source
construct children | Assignment == category info = case children of construct children | Assignment == category info = case children of
(identifier:value:[]) -> withDefaultInfo $ S.Assignment identifier value (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 construct children | MemberAccess == category info = case children of
(base:property:[]) -> withDefaultInfo $ S.MemberAccess base property (base:property:[]) -> withDefaultInfo $ S.MemberAccess base property
construct children | SubscriptAccess == category info = case children of construct children | SubscriptAccess == category info = case children of

View File

@ -23,6 +23,8 @@ data Syntax
| Function { id :: (Maybe f), params :: (Maybe f), expressions :: f } | 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.) -- | 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 } | 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. -- | 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. -- | e.g. in Javascript x.y represents a member access syntax.
| MemberAccess { memberId :: f, property :: f } | MemberAccess { memberId :: f, property :: f }

View File

@ -63,6 +63,7 @@ defaultCategoryForNodeName name = case name of
"var_assignment" -> VarAssignment "var_assignment" -> VarAssignment
"var_declaration" -> VarDecl "var_declaration" -> VarDecl
"switch_statement" -> Switch "switch_statement" -> Switch
"math_assignment" -> MathAssignment
"case" -> Case "case" -> Case
"true" -> Boolean "true" -> Boolean
"false" -> Boolean "false" -> Boolean