1
1
mirror of https://github.com/github/semantic.git synced 2025-01-09 00:56:32 +03:00

Split up Subscript

This commit is contained in:
joshvera 2018-06-21 16:14:02 -04:00
parent 1cafaab9dd
commit c72b8abed0
7 changed files with 17 additions and 6 deletions

View File

@ -1,12 +1,12 @@
{-# LANGUAGE DeriveAnyClass, MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances, DuplicateRecordFields #-} {-# LANGUAGE DeriveAnyClass, MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances, DuplicateRecordFields #-}
module Data.Syntax.Expression where module Data.Syntax.Expression where
import Data.Abstract.Evaluatable import Data.Abstract.Evaluatable hiding (Member)
import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedFloorDiv) import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedFloorDiv)
import Data.Fixed import Data.Fixed
import Data.JSON.Fields import Data.JSON.Fields
import Diffing.Algorithm import Diffing.Algorithm
import Prologue hiding (index) import Prologue hiding (index, Member)
import Proto3.Suite.Class import Proto3.Suite.Class
-- | Typical prefix function application, like `f(x)` in many languages, or `f x` in Haskell. -- | Typical prefix function application, like `f(x)` in many languages, or `f x` in Haskell.
@ -322,9 +322,7 @@ instance Evaluatable MemberAccess where
pure $! LvalMember ptr propName pure $! LvalMember ptr propName
-- | Subscript (e.g a[1]) -- | Subscript (e.g a[1])
data Subscript a data Subscript a = Subscript { lhs :: a, rhs :: [a] }
= Subscript !a ![a]
| Member !a !a
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable, Named1, Message1)
instance Eq1 Subscript where liftEq = genericLiftEq instance Eq1 Subscript where liftEq = genericLiftEq
@ -336,8 +334,15 @@ instance Show1 Subscript where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Subscript where instance Evaluatable Subscript where
eval (Subscript l [r]) = Rval <$> join (index <$> subtermValue l <*> subtermValue r) eval (Subscript l [r]) = Rval <$> join (index <$> subtermValue l <*> subtermValue r)
eval (Subscript _ _) = rvalBox =<< throwResumable (Unspecialized "Eval unspecialized for subscript with slices") eval (Subscript _ _) = rvalBox =<< throwResumable (Unspecialized "Eval unspecialized for subscript with slices")
eval (Member _ _) = rvalBox =<< throwResumable (Unspecialized "Eval unspecialized for member access")
data Member a = Member { lhs :: a, rhs :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable, Named1, Message1)
instance Eq1 Member where liftEq = genericLiftEq
instance Ord1 Member where liftCompare = genericLiftCompare
instance Show1 Member where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Member where
-- | Enumeration (e.g. a[1:10:1] in Python (start at index 1, stop at index 10, step 1 element from start to stop)) -- | Enumeration (e.g. a[1:10:1] in Python (start at index 1, stop at index 10, step 1 element from start to stop))
data Enumeration a = Enumeration { enumerationStart :: !a, enumerationEnd :: !a, enumerationStep :: !a } data Enumeration a = Enumeration { enumerationStart :: !a, enumerationEnd :: !a, enumerationStep :: !a }

View File

@ -50,6 +50,7 @@ type Syntax =
, Expression.StrictEqual , Expression.StrictEqual
, Expression.Comparison , Expression.Comparison
, Expression.Subscript , Expression.Subscript
, Expression.Member
, Statement.PostDecrement , Statement.PostDecrement
, Statement.PostIncrement , Statement.PostIncrement
, Expression.MemberAccess , Expression.MemberAccess

View File

@ -57,6 +57,7 @@ type Syntax =
, Expression.InstanceOf , Expression.InstanceOf
, Expression.MemberAccess , Expression.MemberAccess
, Expression.Subscript , Expression.Subscript
, Expression.Member
, Expression.Super , Expression.Super
, Expression.This , Expression.This
, Java.Syntax.Annotation , Java.Syntax.Annotation

View File

@ -65,6 +65,7 @@ type Syntax = '[
, Expression.New , Expression.New
, Expression.SequenceExpression , Expression.SequenceExpression
, Expression.Subscript , Expression.Subscript
, Expression.Member
, Literal.Array , Literal.Array
, Literal.Float , Literal.Float
, Literal.Integer , Literal.Integer

View File

@ -71,6 +71,7 @@ type Syntax =
, Expression.ScopeResolution , Expression.ScopeResolution
, Expression.MemberAccess , Expression.MemberAccess
, Expression.Subscript , Expression.Subscript
, Expression.Member
, Literal.Array , Literal.Array
, Literal.Boolean , Literal.Boolean
, Literal.Float , Literal.Float

View File

@ -69,6 +69,7 @@ type Syntax = '[
, Expression.MemberAccess , Expression.MemberAccess
, Expression.ScopeResolution , Expression.ScopeResolution
, Expression.Subscript , Expression.Subscript
, Expression.Member
, Literal.Array , Literal.Array
, Literal.Complex , Literal.Complex
, Literal.Float , Literal.Float

View File

@ -74,6 +74,7 @@ type Syntax = '[
, Expression.ScopeResolution , Expression.ScopeResolution
, Expression.SequenceExpression , Expression.SequenceExpression
, Expression.Subscript , Expression.Subscript
, Expression.Member
, Expression.Delete , Expression.Delete
, Expression.Void , Expression.Void
, Expression.Typeof , Expression.Typeof