mirror of
https://github.com/github/semantic.git
synced 2024-12-23 14:54:16 +03:00
Add a few more expressions
Expression.New, NamespaceName, QualifiedName, RelativeScope, NewVariable, variadic unpacking, class type designators
This commit is contained in:
parent
f7d97d06a7
commit
85c92b60be
@ -164,7 +164,7 @@ instance Ord1 Await where liftCompare = genericLiftCompare
|
||||
instance Show1 Await where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
-- | An object constructor call in Javascript, Java, etc.
|
||||
newtype New a = New { newSubject :: a }
|
||||
newtype New a = New { newSubject :: [a] }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 New where liftEq = genericLiftEq
|
||||
|
@ -53,6 +53,11 @@ type Syntax = '[
|
||||
, Literal.Float
|
||||
, Syntax.ShellCommand
|
||||
, Syntax.Update
|
||||
, Syntax.NamespaceName
|
||||
, Syntax.QualifiedName
|
||||
, Syntax.RelativeScope
|
||||
, Syntax.NewVariable
|
||||
, Expression.New
|
||||
, [] ]
|
||||
|
||||
type Term = Term.Term (Data.Union.Union Syntax) (Record Location)
|
||||
@ -69,6 +74,8 @@ term term = contextualize comment (postContextualize comment term)
|
||||
manyTerm :: Assignment -> Assignment.Assignment [] Grammar [Term]
|
||||
manyTerm term = many (contextualize comment term <|> makeTerm1 <$> (Syntax.Context <$> some1 comment <*> emptyTerm))
|
||||
|
||||
someTerm :: Assignment -> Assignment.Assignment [] Grammar [Term]
|
||||
someTerm term = some (contextualize comment term <|> makeTerm1 <$> (Syntax.Context <$> some1 comment <*> emptyTerm))
|
||||
|
||||
text :: Assignment
|
||||
text = makeTerm <$> symbol Text <*> (Syntax.Text <$> source)
|
||||
@ -132,12 +139,45 @@ primaryExpression = choice [
|
||||
-- arrayCreationExpression,
|
||||
-- intrinsic,
|
||||
-- anonymousFunctionCreationExpression,
|
||||
-- objectCreationExpression,
|
||||
objectCreationExpression,
|
||||
updateExpression,
|
||||
shellCommandExpression,
|
||||
expression
|
||||
]
|
||||
|
||||
objectCreationExpression :: Assignment
|
||||
objectCreationExpression = makeTerm <$> symbol ObjectCreationExpression <*> children (fmap Expression.New . (:) <$> classTypeDesignator <*> (arguments <|> pure []))
|
||||
|
||||
arguments :: Assignment.Assignment [] Grammar [Term]
|
||||
arguments = symbol Arguments *> children (manyTerm (variadicUnpacking <|> expression))
|
||||
|
||||
variadicUnpacking :: Assignment
|
||||
variadicUnpacking = symbol VariadicUnpacking *> children (term expression)
|
||||
|
||||
classTypeDesignator :: Assignment
|
||||
classTypeDesignator = qualifiedName <|> newVariable
|
||||
|
||||
newVariable :: Assignment
|
||||
newVariable = makeTerm <$> symbol NewVariable <*> children (Syntax.NewVariable <$> ((pure <$> simpleVariable) <|> ((\a b -> [a, b]) <$> (newVariable <|> qualifiedName <|> relativeScope) <*> (expression <|> memberName <|> emptyTerm))))
|
||||
|
||||
memberName :: Assignment
|
||||
memberName = name <|> simpleVariable <|> expression
|
||||
|
||||
relativeScope :: Assignment
|
||||
relativeScope = makeTerm <$> symbol RelativeScope <*> (Syntax.RelativeScope <$> source)
|
||||
|
||||
qualifiedName :: Assignment
|
||||
qualifiedName = makeTerm <$> symbol QualifiedName <*> children (Syntax.QualifiedName <$> (namespaceNameAsPrefix <|> emptyTerm) <*> name)
|
||||
|
||||
namespaceNameAsPrefix :: Assignment
|
||||
namespaceNameAsPrefix = symbol NamespaceNameAsPrefix *> children (namespaceName <|> emptyTerm)
|
||||
|
||||
namespaceName :: Assignment
|
||||
namespaceName = makeTerm <$> symbol NamespaceName <*> children (Syntax.NamespaceName <$> someTerm name)
|
||||
|
||||
-- anonymousClass :: Assignment
|
||||
-- anonymousClass = makeTerm <$> symbol Grammar.AnonymousClass <*> children (Declaration.Class <$> pure [] <*> emptyTerm <*> (classHeritage' <|> pure []) <*> classBodyStatements)
|
||||
|
||||
updateExpression :: Assignment
|
||||
updateExpression = makeTerm <$> symbol UpdateExpression <*> children (Syntax.Update <$> term expression)
|
||||
|
||||
|
@ -108,3 +108,31 @@ newtype Update a = Update { _updateSubject :: a }
|
||||
instance Eq1 Update where liftEq = genericLiftEq
|
||||
instance Ord1 Update where liftCompare = genericLiftCompare
|
||||
instance Show1 Update where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
newtype NewVariable a = NewVariable [a]
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 NewVariable where liftEq = genericLiftEq
|
||||
instance Ord1 NewVariable where liftCompare = genericLiftCompare
|
||||
instance Show1 NewVariable where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
newtype RelativeScope a = RelativeScope ByteString
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 RelativeScope where liftEq = genericLiftEq
|
||||
instance Ord1 RelativeScope where liftCompare = genericLiftCompare
|
||||
instance Show1 RelativeScope where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data QualifiedName a = QualifiedName a a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 QualifiedName where liftEq = genericLiftEq
|
||||
instance Ord1 QualifiedName where liftCompare = genericLiftCompare
|
||||
instance Show1 QualifiedName where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data NamespaceName a = NamespaceName [a]
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 NamespaceName where liftEq = genericLiftEq
|
||||
instance Ord1 NamespaceName where liftCompare = genericLiftCompare
|
||||
instance Show1 NamespaceName where liftShowsPrec = genericLiftShowsPrec
|
||||
|
@ -266,7 +266,7 @@ memberExpression :: Assignment
|
||||
memberExpression = makeTerm <$> (symbol Grammar.MemberExpression <|> symbol Grammar.MemberExpression') <*> children (Expression.MemberAccess <$> term expression <*> term propertyIdentifier)
|
||||
|
||||
newExpression :: Assignment
|
||||
newExpression = makeTerm <$> symbol Grammar.NewExpression <*> children (Expression.New <$> term expression)
|
||||
newExpression = makeTerm <$> symbol Grammar.NewExpression <*> children (Expression.New . pure <$> term expression)
|
||||
|
||||
updateExpression :: Assignment
|
||||
updateExpression = makeTerm <$> symbol Grammar.UpdateExpression <*> children (TypeScript.Syntax.Update <$> term expression)
|
||||
|
Loading…
Reference in New Issue
Block a user