mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
add dimsExpr and arrayCreationExpression assignments and syntaxes
This commit is contained in:
parent
dad633a3ee
commit
7fec77cc30
@ -64,7 +64,6 @@ handleError = flip Assignment.catchError (\ err -> makeTerm <$> Assignment.locat
|
|||||||
parseError :: (HasCallStack, Error :< syntaxes, Bounded grammar, Enum grammar, Ix grammar, Apply Foldable syntaxes) => Assignment.Assignment ast grammar (Term (Sum syntaxes) (Record Location))
|
parseError :: (HasCallStack, Error :< syntaxes, Bounded grammar, Enum grammar, Ix grammar, Apply Foldable syntaxes) => Assignment.Assignment ast grammar (Term (Sum syntaxes) (Record Location))
|
||||||
parseError = makeTerm <$> Assignment.token maxBound <*> pure (Error (ErrorStack $ errorSite <$> getCallStack (freezeCallStack callStack)) [] (Just "ParseError") [])
|
parseError = makeTerm <$> Assignment.token maxBound <*> pure (Error (ErrorStack $ errorSite <$> getCallStack (freezeCallStack callStack)) [] (Just "ParseError") [])
|
||||||
|
|
||||||
|
|
||||||
-- | Match context terms before a subject term, wrapping both up in a Context term if any context terms matched, or otherwise returning the subject term.
|
-- | Match context terms before a subject term, wrapping both up in a Context term if any context terms matched, or otherwise returning the subject term.
|
||||||
contextualize :: (HasCallStack, Context :< syntaxes, Alternative m, Semigroup ann, Apply Foldable syntaxes)
|
contextualize :: (HasCallStack, Context :< syntaxes, Alternative m, Semigroup ann, Apply Foldable syntaxes)
|
||||||
=> m (Term (Sum syntaxes) ann)
|
=> m (Term (Sum syntaxes) ann)
|
||||||
|
@ -68,8 +68,10 @@ type Syntax =
|
|||||||
, Expression.This
|
, Expression.This
|
||||||
, Java.Syntax.Annotation
|
, Java.Syntax.Annotation
|
||||||
, Java.Syntax.AnnotationField
|
, Java.Syntax.AnnotationField
|
||||||
|
, Java.Syntax.ArrayCreationExpression
|
||||||
, Java.Syntax.Asterisk
|
, Java.Syntax.Asterisk
|
||||||
, Java.Syntax.Constructor
|
, Java.Syntax.Constructor
|
||||||
|
, Java.Syntax.DimsExpr
|
||||||
, Java.Syntax.EnumDeclaration
|
, Java.Syntax.EnumDeclaration
|
||||||
, Java.Syntax.GenericType
|
, Java.Syntax.GenericType
|
||||||
, Java.Syntax.Import
|
, Java.Syntax.Import
|
||||||
@ -163,8 +165,9 @@ expressions = makeTerm'' <$> location <*> many expression
|
|||||||
expressionChoices :: [Assignment Term]
|
expressionChoices :: [Assignment Term]
|
||||||
expressionChoices =
|
expressionChoices =
|
||||||
[
|
[
|
||||||
arrayInitializer
|
arrayAccess
|
||||||
, arrayAccess
|
, arrayCreationExpression
|
||||||
|
, arrayInitializer
|
||||||
, assignment'
|
, assignment'
|
||||||
, block
|
, block
|
||||||
, binary
|
, binary
|
||||||
@ -176,6 +179,7 @@ expressionChoices =
|
|||||||
, classInstance
|
, classInstance
|
||||||
, continue
|
, continue
|
||||||
, constructorDeclaration
|
, constructorDeclaration
|
||||||
|
, dimsExpr
|
||||||
, explicitConstructorInvocation
|
, explicitConstructorInvocation
|
||||||
-- , TODO: constantDeclaration
|
-- , TODO: constantDeclaration
|
||||||
, doWhile
|
, doWhile
|
||||||
@ -237,6 +241,11 @@ variableDeclaratorList = symbol VariableDeclaratorList *> children (makeDecl <$>
|
|||||||
makeSingleDecl modifiers type' (target, Nothing) = makeTerm1 (Java.Syntax.Variable modifiers type' target)
|
makeSingleDecl modifiers type' (target, Nothing) = makeTerm1 (Java.Syntax.Variable modifiers type' target)
|
||||||
makeSingleDecl modifiers type' (target, Just value) = makeTerm1 (Statement.Assignment [] (makeTerm1 (Java.Syntax.Variable modifiers type' target)) value)
|
makeSingleDecl modifiers type' (target, Just value) = makeTerm1 (Statement.Assignment [] (makeTerm1 (Java.Syntax.Variable modifiers type' target)) value)
|
||||||
|
|
||||||
|
-- variable declarator -> variable initializer -> expression -> primary -> array creation expression
|
||||||
|
arrayCreationExpression :: Assignment Term
|
||||||
|
arrayCreationExpression = symbol Grammar.ArrayCreationExpression *> children (makeTerm1 <$> (Java.Syntax.ArrayCreationExpression <$> (new *> type') <*> many dimsExpr))
|
||||||
|
where new = token AnonNew *> pure NewKeyword
|
||||||
|
|
||||||
localVariableDeclarationStatement :: Assignment Term
|
localVariableDeclarationStatement :: Assignment Term
|
||||||
localVariableDeclarationStatement = symbol LocalVariableDeclarationStatement *> children localVariableDeclaration
|
localVariableDeclarationStatement = symbol LocalVariableDeclarationStatement *> children localVariableDeclaration
|
||||||
|
|
||||||
@ -359,6 +368,11 @@ return' = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children
|
|||||||
dims :: Assignment [Term]
|
dims :: Assignment [Term]
|
||||||
dims = symbol Dims *> children (many (emptyTerm <* token AnonLBracket <* token AnonRBracket))
|
dims = symbol Dims *> children (many (emptyTerm <* token AnonLBracket <* token AnonRBracket))
|
||||||
|
|
||||||
|
-- not sure why we did <* token with the dims (possibly because it's the only thing happening?)
|
||||||
|
-- will define with manyTerm annotation <*> manyTerm expression and then revisit whether or not I need brackets
|
||||||
|
dimsExpr :: Assignment Term
|
||||||
|
dimsExpr = makeTerm <$> symbol Grammar.DimsExpr <*> children (Java.Syntax.DimsExpr <$> manyTerm annotation <*> manyTerm expression)
|
||||||
|
|
||||||
type' :: Assignment Term
|
type' :: Assignment Term
|
||||||
type' = choice [
|
type' = choice [
|
||||||
makeTerm <$> token VoidType <*> pure Type.Void
|
makeTerm <$> token VoidType <*> pure Type.Void
|
||||||
|
@ -226,3 +226,21 @@ instance Ord1 LambdaBody where liftCompare = genericLiftCompare
|
|||||||
instance Show1 LambdaBody where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 LambdaBody where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
instance Evaluatable LambdaBody
|
instance Evaluatable LambdaBody
|
||||||
|
|
||||||
|
data ArrayCreationExpression a = ArrayCreationExpression { arrayCreationExpressionType :: !a, arrayCreationExpressionDims :: ![a] }
|
||||||
|
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 ArrayCreationExpression where liftEq = genericLiftEq
|
||||||
|
instance Ord1 ArrayCreationExpression where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 ArrayCreationExpression where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
instance Evaluatable ArrayCreationExpression
|
||||||
|
|
||||||
|
data DimsExpr a = DimsExpr { dimsExprAnnotation :: ![a], dimsExprExpression :: ![a] }
|
||||||
|
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
|
||||||
|
|
||||||
|
instance Eq1 DimsExpr where liftEq = genericLiftEq
|
||||||
|
instance Ord1 DimsExpr where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 DimsExpr where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
instance Evaluatable DimsExpr
|
||||||
|
2
vendor/effects
vendored
2
vendor/effects
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 0b6d04713b70e6b0551b841304fb44c9b1564e9b
|
Subproject commit 105a543ccc98f2929cf0b1f1e97bcc48dfb8f718
|
Loading…
Reference in New Issue
Block a user