1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Partially add unary

This commit is contained in:
Timothy Clem 2017-06-19 08:27:44 -06:00
parent f8ba1d203b
commit 0282ebab55
2 changed files with 18 additions and 0 deletions

View File

@ -92,6 +92,7 @@ statement = -- handleError $
<|> literal
<|> scopeResolution
<|> conditional
<|> unary
-- <|> assignment'
-- TODO: rescue
where mk s construct = makeTerm <$> symbol s <*> children ((construct .) . fromMaybe <$> emptyTerm <*> optional (symbol ArgumentList *> children statement))
@ -200,6 +201,17 @@ for = makeTerm <$> symbol For <*> children (Statement.ForEach <$> identifier <*>
-- <|> makeTerm <$> symbol AnonLAngleLAngleEqual <*> (Expression.LShift var <$> expression)
-- <|> makeTerm <$> symbol AnonCaretEqual <*> (Expression.BXOr var <$> expression)))
unary :: Assignment
unary = symbol Unary >>= \ location ->
-- TODO: Match a unary `defined?`
-- makeTerm location . Expression.Call <$> children ( symbol AnonDefinedQuestion *> statement )
makeTerm location . Expression.Complement <$> children ( symbol AnonTilde *> statement )
<|> makeTerm location . Expression.Not <$> children ( symbol AnonBang *> statement )
<|> makeTerm location . Expression.Not <$> children ( symbol AnonNot *> statement )
-- FIXME: Unable to match unary minus (e.g. -a)
<|> makeTerm location . Expression.Negate <$> children ( symbol HiddenUnaryMinus *> statement )
<|> children ( symbol AnonPlus *> statement )
conditional :: Assignment
conditional = makeTerm <$> symbol Conditional <*> children (Statement.If <$> statement <*> statement <*> statement)

6
test/fixtures/ruby/unary.A.rb vendored Normal file
View File

@ -0,0 +1,6 @@
# ~a
# !a
-a
# +a
# not foo
# defined? foo