mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Parse type switch statements
This commit is contained in:
parent
ed532220d1
commit
666452da18
@ -35,13 +35,19 @@ termConstructor source sourceSpan name range children = case (name, children) of
|
|||||||
[rangeClause, body] | category (extract rangeClause) == Other "range_clause" ->
|
[rangeClause, body] | category (extract rangeClause) == Other "range_clause" ->
|
||||||
S.For (toList $ unwrap rangeClause) (toList $ unwrap body)
|
S.For (toList $ unwrap rangeClause) (toList $ unwrap body)
|
||||||
other -> S.Error other
|
other -> S.Error other
|
||||||
("expression_switch_statement", children) -> case Prologue.break isCaseClause children of
|
("expression_switch_statement", children) ->
|
||||||
(clauses, cases) -> do
|
case Prologue.break isCaseClause children of
|
||||||
clauses' <- withDefaultInfo $ S.Indexed clauses
|
(clauses, cases) -> do
|
||||||
withDefaultInfo $ S.Switch clauses' cases
|
clauses' <- withDefaultInfo $ S.Indexed clauses
|
||||||
where isCaseClause = (== Case) . category . extract
|
withDefaultInfo $ S.Switch clauses' cases
|
||||||
|
where isCaseClause = (== Case) . category . extract
|
||||||
|
("type_switch_statement", children) ->
|
||||||
|
case Prologue.break isCaseClause children of
|
||||||
|
(clauses, cases) -> do
|
||||||
|
withDefaultInfo $ case clauses of
|
||||||
|
[id] -> S.Switch id cases
|
||||||
|
_ -> S.Error children
|
||||||
|
where isCaseClause = (== Case) . category . extract
|
||||||
-- TODO: Handle multiple var specs
|
-- TODO: Handle multiple var specs
|
||||||
("var_declaration", varSpecs) -> withDefaultInfo . S.Indexed =<< mapM toVarDecl varSpecs
|
("var_declaration", varSpecs) -> withDefaultInfo . S.Indexed =<< mapM toVarDecl varSpecs
|
||||||
("short_var_declaration", children) -> listToVarDecls children
|
("short_var_declaration", children) -> listToVarDecls children
|
||||||
@ -135,5 +141,7 @@ categoryForGoName = \case
|
|||||||
"for_statement" -> For
|
"for_statement" -> For
|
||||||
"expression_switch_statement" -> Switch
|
"expression_switch_statement" -> Switch
|
||||||
"expression_case_clause" -> Case
|
"expression_case_clause" -> Case
|
||||||
|
"type_switch_statement" -> Switch
|
||||||
|
"type_case_clause" -> Case
|
||||||
s -> Other (toS s)
|
s -> Other (toS s)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user