mirror of
https://github.com/github/semantic.git
synced 2025-01-02 20:41:38 +03:00
Map var declarations to VarDecl
This commit is contained in:
parent
23450d64ee
commit
c3201ed689
@ -225,7 +225,7 @@ toTermName source term = case unwrap term of
|
||||
_ -> toTermName' base <> "[" <> toTermName' element <> "]"
|
||||
(_, _) -> toTermName' base <> "[" <> toTermName' element <> "]"
|
||||
S.VarAssignment varId _ -> toTermName' varId
|
||||
S.VarDecl decl -> toTermName' decl
|
||||
S.VarDecl decl _ -> toTermName' decl
|
||||
-- TODO: We should remove Case from Syntax since I don't think we should ever
|
||||
-- evaluate Case as a single toTermName Text - joshvera
|
||||
S.Case expr _ -> termNameFromSource expr
|
||||
|
@ -60,7 +60,7 @@ termConstructor source sourceSpan name range children _ =
|
||||
pure $! cofree ((range .: Other name .: sourceSpan' .: RNil) :< syntax)
|
||||
|
||||
toVarDecl :: (HasField fields Category) => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields)
|
||||
toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl child
|
||||
toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl child Nothing
|
||||
|
||||
toTuple :: Term (S.Syntax Text) (Record fields) -> [Term (S.Syntax Text) (Record fields)]
|
||||
toTuple child | S.Indexed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)]
|
||||
|
@ -195,7 +195,11 @@ termConstructor source sourceSpan name range children _ = case name of
|
||||
withDefaultInfo (S.Indexed assignments')
|
||||
constSpecToVarAssignment = toVarAssignment . toList . unwrap
|
||||
toVarAssignment = \case
|
||||
[idList, expressionList] -> do
|
||||
[idList, ty] | category (extract ty) == Identifier -> do
|
||||
let ids = toList (unwrap idList)
|
||||
idList' <- mapM (\id -> withRanges range VarDecl [id] (S.VarDecl id (Just ty))) ids
|
||||
withRanges range ExpressionStatements idList' (S.Indexed idList')
|
||||
[idList, expressionList] | category (extract expressionList) == Other "expression_list" -> do
|
||||
assignments' <- sequenceA $ zipWith (\id expr ->
|
||||
withCategory VarAssignment $ S.VarAssignment id expr)
|
||||
(toList $ unwrap idList) (toList $ unwrap expressionList)
|
||||
@ -204,8 +208,7 @@ termConstructor source sourceSpan name range children _ = case name of
|
||||
assignments' <- sequenceA $ zipWith (\id expr ->
|
||||
withCategory VarAssignment $ S.VarAssignment id expr) (toList $ unwrap idList) (toList $ unwrap expressionList)
|
||||
withDefaultInfo (S.Indexed assignments')
|
||||
[idList] -> do
|
||||
withDefaultInfo (S.Indexed [idList])
|
||||
[idList] -> withDefaultInfo (S.Indexed [idList])
|
||||
rest -> withRanges range Error rest (S.Error rest)
|
||||
|
||||
withRanges originalRange category' terms syntax = do
|
||||
@ -238,7 +241,6 @@ categoryForGoName = \case
|
||||
"slice_expression" -> Slice
|
||||
"parameters" -> Args
|
||||
"short_var_declaration" -> VarDecl
|
||||
"var_declaration" -> VarDecl
|
||||
"var_spec" -> VarAssignment
|
||||
"assignment_statement" -> Assignment
|
||||
"source_file" -> Module
|
||||
|
@ -110,7 +110,7 @@ syntaxToTermField syntax = case syntax of
|
||||
S.MemberAccess identifier value -> [ "identifier" .= identifier ] <> [ "value" .= value ]
|
||||
S.MethodCall identifier methodIdentifier parameters -> [ "identifier" .= identifier ] <> [ "methodIdentifier" .= methodIdentifier ] <> [ "parameters" .= parameters ]
|
||||
S.Operator syntaxes -> [ "operatorSyntaxes" .= syntaxes ]
|
||||
S.VarDecl declaration -> [ "declaration" .= declaration ]
|
||||
S.VarDecl declaration ty -> [ "declaration" .= declaration ] <> [ "type" .= ty]
|
||||
S.VarAssignment identifier value -> [ "identifier" .= identifier ] <> [ "value" .= value ]
|
||||
S.SubscriptAccess identifier property -> [ "identifier" .= identifier ] <> [ "property" .= property ]
|
||||
S.Switch expression cases -> [ "expression" .= expression ] <> [ "cases" .= cases ]
|
||||
|
@ -39,7 +39,7 @@ data Syntax a f
|
||||
-- | An operator can be applied to a list of syntaxes.
|
||||
| Operator [f]
|
||||
-- | A variable declaration. e.g. var foo;
|
||||
| VarDecl f
|
||||
| VarDecl f (Maybe f)
|
||||
-- | A variable assignment in a variable declaration. var foo = bar;
|
||||
| VarAssignment { varId :: f, varValue :: f }
|
||||
-- | A subscript access contains a syntax, and another syntax that indefies a property or value in the first syntax.
|
||||
|
Loading…
Reference in New Issue
Block a user