1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Flatten import declarations.

This commit is contained in:
Rob Rix 2017-01-23 13:21:20 -05:00
parent b2456dce33
commit aa1d770ab1

View File

@ -20,7 +20,12 @@ termAssignment source (range :. category :. sourceSpan :. Nil) children = Just $
(Module, _) | (comments, packageName : rest) <- Prologue.break ((== Other "package_clause") . Info.category . extract) children
, S.Indexed [id] <- unwrap packageName
-> withCategory Program (S.Indexed (comments <> [withCategory Module (S.Module id rest)]))
(Other "import_declaration", _) -> toImports children
(Other "import_declaration", _) -> withDefaultInfo $ S.Indexed (children >>= toImport)
where
toImport i = case toList (unwrap i) of
[importName] -> [ withCategory Import (S.Import importName []) ]
rest@(_:_) -> [ withRanges range Error rest (S.Error rest)]
[] -> []
(Function, [id, params, block]) -> withDefaultInfo $ S.Function id (toList $ unwrap params) (toList $ unwrap block)
(For, [body]) | Other "block" <- Info.category (extract body) -> withDefaultInfo $ S.For [] (toList (unwrap body))
(For, [forClause, body]) | Other "for_clause" <- Info.category (extract forClause) -> withDefaultInfo $ S.For (toList (unwrap forClause)) (toList (unwrap body))
@ -104,14 +109,6 @@ termAssignment source (range :. category :. sourceSpan :. Nil) children = Just $
blocks' = foldMap (toList . unwrap) blocks
in withDefaultInfo (S.If clauses' blocks')
toImports imports =
withDefaultInfo $ S.Indexed (imports >>= toImport)
where
toImport i = case toList (unwrap i) of
[importName] -> [ withCategory Import (S.Import importName []) ]
rest@(_:_) -> [ withRanges range Error rest (S.Error rest)]
[] -> []
toVarDecls children = withDefaultInfo (S.Indexed children)
toConsts constSpecs = withDefaultInfo (S.Indexed constSpecs)