mirror of
https://github.com/github/semantic.git
synced 2024-11-28 18:23:44 +03:00
Break apart else clauses for If syntax nodes
- This is an intermediate step and not complete. We currently only handle one level of else-if, rather than arbitrary levels of else-if.
This commit is contained in:
parent
ddb39bdbcc
commit
a9d28f95c1
@ -49,8 +49,10 @@ termConstructor source sourceSpan name range children
|
||||
("case", [ expr, body ]) -> S.Case expr body
|
||||
("object", _) -> S.Object $ foldMap toTuple children
|
||||
("pair", _) -> S.Fixed children
|
||||
("if_statement", [ expr, clause1, clause2 ]) -> S.If expr clause1 (Just clause2)
|
||||
("if_statement", [ expr, clause ]) -> S.If expr clause Nothing
|
||||
("if_statement", [ expr, thenClause, elseClause ]) -> case unwrap elseClause of
|
||||
S.If{} -> S.If expr thenClause [(toElseIf elseClause)]
|
||||
_ -> S.If expr thenClause [elseClause]
|
||||
("if_statement", [ expr, thenClause ]) -> S.If expr thenClause []
|
||||
("while_statement", [ expr, body ]) -> S.While expr body
|
||||
("do_statement", [ expr, body ]) -> S.DoWhile expr body
|
||||
("throw_statement", [ expr ]) -> S.Throw expr
|
||||
@ -156,6 +158,9 @@ categoryForJavaScriptProductionName name = case name of
|
||||
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
|
||||
|
||||
toElseIf :: (HasField fields Category) => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields)
|
||||
toElseIf child = cofree $ setCategory (extract child) If :< S.If child child []
|
||||
|
||||
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)]
|
||||
toTuple child | S.Fixed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)]
|
||||
|
Loading…
Reference in New Issue
Block a user