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:
parent
f8ba1d203b
commit
0282ebab55
@ -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
6
test/fixtures/ruby/unary.A.rb
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
# ~a
|
||||
# !a
|
||||
-a
|
||||
# +a
|
||||
# not foo
|
||||
# defined? foo
|
Loading…
Reference in New Issue
Block a user