1
1
mirror of https://github.com/github/semantic.git synced 2025-01-05 14:11:33 +03:00

Handle Until/Unless in the same manner as the other control statements/modifiers.

This commit is contained in:
Rob Rix 2017-01-19 13:06:12 -05:00
parent 72f2260164
commit d9397f930c

View File

@ -23,22 +23,6 @@ termConstructor
-> IO (SyntaxTerm Text '[Range, Category, SourceSpan]) -- ^ The resulting term, in IO.
termConstructor source sourceSpan category range children allChildren
| category == Error = pure $! withDefaultInfo (S.Error children)
| category == Unless = pure $! case children of
[ lhs, rhs ] ->
let condition = withRecord (setCategory (extract rhs) Negate) (S.Negate rhs)
in withDefaultInfo $ S.If condition [lhs]
( expr : rest ) ->
let condition = withRecord (setCategory (extract expr) Negate) (S.Negate expr)
in withDefaultInfo $ S.If condition rest
_ -> withDefaultInfo $ S.Error children
| category == Until = pure $! case children of
[ lhs, rhs ] ->
let condition = withRecord (setCategory (extract rhs) Negate) (S.Negate rhs)
in withDefaultInfo $ S.While condition [lhs]
( expr : rest ) ->
let condition = withRecord (setCategory (extract expr) Negate) (S.Negate expr)
in withDefaultInfo $ S.While condition rest
_ -> withDefaultInfo $ S.Error children
| category `elem` operators = do
allChildren' <- allChildren
pure $! withDefaultInfo $ S.Operator allChildren'
@ -94,6 +78,20 @@ termConstructor source sourceSpan category range children allChildren
(If, [ lhs, condition ]) -> S.If condition [lhs]
(If, condition : body ) -> S.If condition body
(If, _ ) -> S.Error children
(Unless, [lhs, rhs]) ->
let condition = withRecord (setCategory (extract rhs) Negate) (S.Negate rhs)
in S.If condition [lhs]
(Unless, expr : rest) ->
let condition = withRecord (setCategory (extract expr) Negate) (S.Negate expr)
in S.If condition rest
(Unless, _) -> S.Error children
(Until, [ lhs, rhs ]) ->
let condition = withRecord (setCategory (extract rhs) Negate) (S.Negate rhs)
in S.While condition [lhs]
(Until, expr : rest) ->
let condition = withRecord (setCategory (extract expr) Negate) (S.Negate expr)
in S.While condition rest
(Until, _) -> S.Error children
(Elsif, condition : body ) -> S.If condition body
(Elsif, _ ) -> S.Error children
(SubscriptAccess, [ base, element ]) -> S.SubscriptAccess base element