1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00

move error handling out

This commit is contained in:
joshvera 2016-11-01 21:21:29 -04:00
parent fb99a1421a
commit 160a9a34d7

View File

@ -35,18 +35,23 @@ termConstructor source sourceSpan name range children = case (name, children) of
("var_declaration", [varSpec]) -> do
assignment' <- case toList (unwrap varSpec) of
[idList, _, exprs] -> do
identifier' <- case toList (unwrap idList) of
[identifier] -> pure identifier
_ -> withCategory Error (S.Error [idList])
identifier' <- idOrError idList
withDefaultInfo $ S.VarAssignment identifier' exprs
_ -> withCategory Error (S.Error [varSpec])
withDefaultInfo $ S.VarDecl assignment'
("call_expression", [id]) -> withDefaultInfo $ S.FunctionCall id []
("const_declaration", constSpecs) -> do
("const_declaration", constSpecs) -> toConsts constSpecs
("func_literal", [params, _, body]) -> withDefaultInfo $ S.AnonymousFunction (toList $ unwrap params) body
(_, []) -> withDefaultInfo . S.Leaf $ toText (slice range source)
_ -> withDefaultInfo $ S.Indexed children
where
idOrError idList = case toList (unwrap idList) of
[identifier] -> pure identifier
_ -> withCategory Error (S.Error [idList])
toConsts constSpecs = do
assignments' <- sequenceA $ toVarAssignment <$> constSpecs
constSpecs'<- withDefaultInfo (S.Indexed assignments')
withDefaultInfo $ S.VarDecl constSpecs'
where
toVarAssignment constSpec = do
assignment <- case toList (unwrap constSpec) of
idList : rest -> do
@ -59,10 +64,6 @@ termConstructor source sourceSpan name range children = case (name, children) of
withDefaultInfo $ S.VarAssignment identifier' rest'
_ -> withCategory Error (S.Error [constSpec])
withDefaultInfo $ S.VarDecl assignment
("func_literal", [params, _, body]) -> withDefaultInfo $ S.AnonymousFunction (toList $ unwrap params) body
(_, []) -> withDefaultInfo . S.Leaf $ toText (slice range source)
_ -> withDefaultInfo $ S.Indexed children
where
withCategory category syntax = do
sourceSpan' <- sourceSpan
pure $! cofree ((range .: category .: sourceSpan' .: RNil) :< syntax)