From b012b9757179b1972b9ea6f265369e222d823991 Mon Sep 17 00:00:00 2001 From: joshvera Date: Mon, 9 Apr 2018 14:45:34 -0400 Subject: [PATCH 1/3] Revert "Merge pull request #1726 from github/charliesome/ruby-method-calls" This reverts commit 3729f84c487cb2613fd99eca4c6cdb2178c88806, reversing changes made to d8f0566783407780c1a0d0855f43200530887c54. --- src/Language/Ruby/Assignment.hs | 22 ++++-------- src/Language/Ruby/Syntax.hs | 16 --------- test/fixtures/ruby/begin.diffA-B.txt | 5 +-- test/fixtures/ruby/begin.diffB-A.txt | 5 +-- test/fixtures/ruby/begin.parseB.txt | 5 +-- test/fixtures/ruby/else.diffA-B.txt | 10 +++--- test/fixtures/ruby/else.diffB-A.txt | 10 +++--- test/fixtures/ruby/else.parseA.txt | 5 +-- test/fixtures/ruby/else.parseB.txt | 10 +++--- test/fixtures/ruby/elsif.diffA-B.txt | 10 +++--- test/fixtures/ruby/elsif.diffB-A.txt | 10 +++--- test/fixtures/ruby/elsif.parseA.txt | 5 +-- test/fixtures/ruby/elsif.parseB.txt | 10 +++--- test/fixtures/ruby/for.diffA-B.txt | 5 +-- test/fixtures/ruby/for.diffB-A.txt | 5 +-- test/fixtures/ruby/for.parseB.txt | 5 +-- test/fixtures/ruby/heredoc.diffA-B.txt | 15 ++++---- test/fixtures/ruby/heredoc.diffB-A.txt | 15 ++++---- test/fixtures/ruby/heredoc.parseB.txt | 15 ++++---- test/fixtures/ruby/lambda.diffA-B.txt | 9 ++--- test/fixtures/ruby/lambda.diffB-A.txt | 9 ++--- test/fixtures/ruby/lambda.parseA.txt | 9 ++--- test/fixtures/ruby/lambda.parseB.txt | 2 +- .../ruby/method-calls-hash-args.diffA-B.txt | 5 +-- .../ruby/method-calls-hash-args.diffB-A.txt | 5 +-- .../ruby/method-calls-hash-args.parseA.txt | 5 +-- .../ruby/method-calls-hash-args.parseB.txt | 5 +-- .../method-calls-keyword-args.diffA-B.txt | 5 +-- .../method-calls-keyword-args.diffB-A.txt | 5 +-- .../ruby/method-calls-keyword-args.parseA.txt | 5 +-- .../ruby/method-calls-keyword-args.parseB.txt | 5 +-- test/fixtures/ruby/method-calls.diffA-B.txt | 28 +++++++++------ test/fixtures/ruby/method-calls.diffB-A.txt | 26 ++++++++------ test/fixtures/ruby/method-calls.parseA.txt | 26 ++++++++------ test/fixtures/ruby/method-calls.parseB.txt | 5 +-- .../ruby/method-invocation.diffA-B.txt | 34 ++++++++++++------- .../ruby/method-invocation.diffB-A.txt | 28 +++++++++------ .../ruby/method-invocation.parseA.txt | 2 +- .../ruby/method-invocation.parseB.txt | 23 ++++++++----- .../ruby/multiple-assignments.diffA-B.txt | 8 ++--- .../ruby/multiple-assignments.diffB-A.txt | 8 ++--- .../ruby/multiple-assignments.parseA.txt | 8 ++--- .../ruby/relational-operator.diffA-B.txt | 7 ++-- .../ruby/relational-operator.diffB-A.txt | 5 ++- test/fixtures/ruby/require.diffA-B.txt | 5 +-- test/fixtures/ruby/require.diffB-A.txt | 5 +-- test/fixtures/ruby/require.parseA.txt | 5 +-- test/fixtures/ruby/require.parseB.txt | 5 +-- 48 files changed, 269 insertions(+), 211 deletions(-) diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index 89e94f623..f61f08d3b 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -74,7 +74,6 @@ type Syntax = '[ , Syntax.Identifier , Syntax.Paren , Syntax.Program - , Ruby.Syntax.Send , Ruby.Syntax.Class , Ruby.Syntax.Load , Ruby.Syntax.LowPrecedenceBoolean @@ -84,8 +83,7 @@ type Syntax = '[ ] type Term = Term.Term (Union Syntax) (Record Location) -type Assignment' a = HasCallStack => Assignment.Assignment [] Grammar a -type Assignment = Assignment' Term +type Assignment = HasCallStack => Assignment.Assignment [] Grammar Term -- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax. assignment :: Assignment @@ -293,12 +291,9 @@ pair :: Assignment pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm)) methodCall :: Assignment -methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> funcCall <|> regularCall) +methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> regularCall) where - funcCall = inj <$> (Ruby.Syntax.Send Nothing <$> methodSelector <*> args <*> optional block) - - regularCall = inj <$> (symbol Call *> children (Ruby.Syntax.Send <$> (Just <$> expression) <*> methodSelector) <*> args <*> optional block) - + regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm)) require = inj <$> (symbol Identifier *> do s <- source guard (s `elem` ["require", "require_relative"]) @@ -307,17 +302,14 @@ methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> s <- source guard (s == "load") Ruby.Syntax.Load <$> loadArgs) - args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> many expression + args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> pure [] loadArgs = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (some expression) nameExpression = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expression -methodSelector :: Assignment -methodSelector = mk Identifier <|> mk Identifier' - where - mk s = makeTerm <$> symbol s <*> (Syntax.Identifier <$> (name <$> source)) - call :: Assignment -call = makeTerm <$> symbol Call <*> children (Ruby.Syntax.Send <$> (Just <$> expression) <*> methodSelector <*> pure [] <*> optional block) +call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expressions <|> args)) + where + args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expressions rescue :: Assignment rescue = rescue' diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 47977d954..f69a1cf74 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -36,22 +36,6 @@ maybeFailNotFound name = maybeFail notFound cleanNameOrPath :: ByteString -> String cleanNameOrPath = BC.unpack . dropRelativePrefix . stripQuotes -data Send a = Send { sendReceiver :: Maybe a, sendSelector :: a, sendArgs :: [a], sendBlock :: Maybe a } - deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1) - -instance Eq1 Send where liftEq = genericLiftEq -instance Ord1 Send where liftCompare = genericLiftCompare -instance Show1 Send where liftShowsPrec = genericLiftShowsPrec - -instance Evaluatable Send where - eval Send{..} = do - func <- case sendReceiver of - Just recv -> do - recvEnv <- subtermValue recv >>= scopedEnvironment - localEnv (mappend recvEnv) (subtermValue sendSelector) - Nothing -> subtermValue sendSelector -- TODO Does this require `localize` so we don't leak terms when resolving `sendSelector`? - call func (map subtermValue sendArgs) -- TODO pass through sendBlock - data Require a = Require { requireRelative :: Bool, requirePath :: !a } deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1) diff --git a/test/fixtures/ruby/begin.diffA-B.txt b/test/fixtures/ruby/begin.diffA-B.txt index 1bec5bc39..c4981ea41 100644 --- a/test/fixtures/ruby/begin.diffA-B.txt +++ b/test/fixtures/ruby/begin.diffA-B.txt @@ -5,6 +5,7 @@ ( (Try { ([]) - ->(Send + ->(Call {+(Identifier)+} - {+(TextElement)+}) })))) + {+(TextElement)+} + {+(Empty)+}) })))) diff --git a/test/fixtures/ruby/begin.diffB-A.txt b/test/fixtures/ruby/begin.diffB-A.txt index 49fcd5397..cddc43dcb 100644 --- a/test/fixtures/ruby/begin.diffB-A.txt +++ b/test/fixtures/ruby/begin.diffB-A.txt @@ -4,7 +4,8 @@ (Identifier) ( (Try - { (Send + { (Call {-(Identifier)-} - {-(TextElement)-}) + {-(TextElement)-} + {-(Empty)-}) ->([]) })))) diff --git a/test/fixtures/ruby/begin.parseB.txt b/test/fixtures/ruby/begin.parseB.txt index b59119d4d..20e4c291d 100644 --- a/test/fixtures/ruby/begin.parseB.txt +++ b/test/fixtures/ruby/begin.parseB.txt @@ -4,6 +4,7 @@ (Identifier) ( (Try - (Send + (Call (Identifier) - (TextElement)))))) + (TextElement) + (Empty)))))) diff --git a/test/fixtures/ruby/else.diffA-B.txt b/test/fixtures/ruby/else.diffA-B.txt index 5749e4f84..fdcd7ca3f 100644 --- a/test/fixtures/ruby/else.diffA-B.txt +++ b/test/fixtures/ruby/else.diffA-B.txt @@ -1,10 +1,12 @@ (Program (Try ( - (Send - (Identifier)) + (Call + (Identifier) + (Empty)) (Else (Empty) { ([]) - ->(Send - {+(Identifier)+}) })))) + ->(Call + {+(Identifier)+} + {+(Empty)+}) })))) diff --git a/test/fixtures/ruby/else.diffB-A.txt b/test/fixtures/ruby/else.diffB-A.txt index 147cfbfbd..008d4b5f5 100644 --- a/test/fixtures/ruby/else.diffB-A.txt +++ b/test/fixtures/ruby/else.diffB-A.txt @@ -1,10 +1,12 @@ (Program (Try ( - (Send - (Identifier)) + (Call + (Identifier) + (Empty)) (Else (Empty) - { (Send - {-(Identifier)-}) + { (Call + {-(Identifier)-} + {-(Empty)-}) ->([]) })))) diff --git a/test/fixtures/ruby/else.parseA.txt b/test/fixtures/ruby/else.parseA.txt index edf25207d..48a2a4275 100644 --- a/test/fixtures/ruby/else.parseA.txt +++ b/test/fixtures/ruby/else.parseA.txt @@ -1,8 +1,9 @@ (Program (Try ( - (Send - (Identifier)) + (Call + (Identifier) + (Empty)) (Else (Empty) ([]))))) diff --git a/test/fixtures/ruby/else.parseB.txt b/test/fixtures/ruby/else.parseB.txt index 28eaf190d..adec3bef8 100644 --- a/test/fixtures/ruby/else.parseB.txt +++ b/test/fixtures/ruby/else.parseB.txt @@ -1,9 +1,11 @@ (Program (Try ( - (Send - (Identifier)) + (Call + (Identifier) + (Empty)) (Else (Empty) - (Send - (Identifier)))))) + (Call + (Identifier) + (Empty)))))) diff --git a/test/fixtures/ruby/elsif.diffA-B.txt b/test/fixtures/ruby/elsif.diffA-B.txt index 209340fd7..335081649 100644 --- a/test/fixtures/ruby/elsif.diffA-B.txt +++ b/test/fixtures/ruby/elsif.diffA-B.txt @@ -2,11 +2,13 @@ (If (Identifier) ( - (Send - (Identifier))) + (Call + (Identifier) + (Empty))) (If (Identifier) ( - {+(Send - {+(Identifier)+})+}) + {+(Call + {+(Identifier)+} + {+(Empty)+})+}) (Empty)))) diff --git a/test/fixtures/ruby/elsif.diffB-A.txt b/test/fixtures/ruby/elsif.diffB-A.txt index 0d5cf800a..888a02a12 100644 --- a/test/fixtures/ruby/elsif.diffB-A.txt +++ b/test/fixtures/ruby/elsif.diffB-A.txt @@ -2,11 +2,13 @@ (If (Identifier) ( - (Send - (Identifier))) + (Call + (Identifier) + (Empty))) (If (Identifier) ([] - {-(Send - {-(Identifier)-})-}) + {-(Call + {-(Identifier)-} + {-(Empty)-})-}) (Empty)))) diff --git a/test/fixtures/ruby/elsif.parseA.txt b/test/fixtures/ruby/elsif.parseA.txt index 5e0b329d4..10cd3a0d8 100644 --- a/test/fixtures/ruby/elsif.parseA.txt +++ b/test/fixtures/ruby/elsif.parseA.txt @@ -2,8 +2,9 @@ (If (Identifier) ( - (Send - (Identifier))) + (Call + (Identifier) + (Empty))) (If (Identifier) ([]) diff --git a/test/fixtures/ruby/elsif.parseB.txt b/test/fixtures/ruby/elsif.parseB.txt index a823c51eb..6b06523ca 100644 --- a/test/fixtures/ruby/elsif.parseB.txt +++ b/test/fixtures/ruby/elsif.parseB.txt @@ -2,11 +2,13 @@ (If (Identifier) ( - (Send - (Identifier))) + (Call + (Identifier) + (Empty))) (If (Identifier) ( - (Send - (Identifier))) + (Call + (Identifier) + (Empty))) (Empty)))) diff --git a/test/fixtures/ruby/for.diffA-B.txt b/test/fixtures/ruby/for.diffA-B.txt index a65b6c3b9..56a898a61 100644 --- a/test/fixtures/ruby/for.diffA-B.txt +++ b/test/fixtures/ruby/for.diffA-B.txt @@ -6,9 +6,10 @@ {+(Integer)+} {+(Integer)+} {+(Integer)+})+} - {+(Send + {+(Call {+(Identifier)+} - {+(Identifier)+})+})+} + {+(Identifier)+} + {+(Empty)+})+})+} {-(ForEach {-( {-(Identifier)-})-} diff --git a/test/fixtures/ruby/for.diffB-A.txt b/test/fixtures/ruby/for.diffB-A.txt index 02167c97b..396c9dcf2 100644 --- a/test/fixtures/ruby/for.diffB-A.txt +++ b/test/fixtures/ruby/for.diffB-A.txt @@ -22,9 +22,10 @@ {+(Integer)+} {+(Integer)+} {+(Empty)+}) } - { (Send + { (Call {-(Identifier)-} - {-(Identifier)-}) + {-(Identifier)-} + {-(Empty)-}) ->(Boolean) }) {+(ForEach {+( diff --git a/test/fixtures/ruby/for.parseB.txt b/test/fixtures/ruby/for.parseB.txt index a0c763c04..fad56b5a4 100644 --- a/test/fixtures/ruby/for.parseB.txt +++ b/test/fixtures/ruby/for.parseB.txt @@ -6,6 +6,7 @@ (Integer) (Integer) (Integer)) - (Send + (Call (Identifier) - (Identifier)))) + (Identifier) + (Empty)))) diff --git a/test/fixtures/ruby/heredoc.diffA-B.txt b/test/fixtures/ruby/heredoc.diffA-B.txt index c95f20db7..982163b39 100644 --- a/test/fixtures/ruby/heredoc.diffA-B.txt +++ b/test/fixtures/ruby/heredoc.diffA-B.txt @@ -1,9 +1,12 @@ (Program -{+(Send - {+(Send - {+(Identifier)+} - {+(TextElement)+} - {+(TextElement)+})+} - {+(Identifier)+})+} +{+(Call + {+(MemberAccess + {+(Call + {+(Identifier)+} + {+(TextElement)+} + {+(TextElement)+} + {+(Empty)+})+} + {+(Identifier)+})+} + {+(Empty)+})+} {-(TextElement)-} {-(TextElement)-}) diff --git a/test/fixtures/ruby/heredoc.diffB-A.txt b/test/fixtures/ruby/heredoc.diffB-A.txt index 0e4948ace..33636b938 100644 --- a/test/fixtures/ruby/heredoc.diffB-A.txt +++ b/test/fixtures/ruby/heredoc.diffB-A.txt @@ -1,9 +1,12 @@ (Program {+(TextElement)+} {+(TextElement)+} -{-(Send - {-(Send - {-(Identifier)-} - {-(TextElement)-} - {-(TextElement)-})-} - {-(Identifier)-})-}) +{-(Call + {-(MemberAccess + {-(Call + {-(Identifier)-} + {-(TextElement)-} + {-(TextElement)-} + {-(Empty)-})-} + {-(Identifier)-})-} + {-(Empty)-})-}) diff --git a/test/fixtures/ruby/heredoc.parseB.txt b/test/fixtures/ruby/heredoc.parseB.txt index b21f0d865..538a5f692 100644 --- a/test/fixtures/ruby/heredoc.parseB.txt +++ b/test/fixtures/ruby/heredoc.parseB.txt @@ -1,7 +1,10 @@ (Program - (Send - (Send - (Identifier) - (TextElement) - (TextElement)) - (Identifier))) + (Call + (MemberAccess + (Call + (Identifier) + (TextElement) + (TextElement) + (Empty)) + (Identifier)) + (Empty))) diff --git a/test/fixtures/ruby/lambda.diffA-B.txt b/test/fixtures/ruby/lambda.diffA-B.txt index 39a195bf4..e54c73a89 100644 --- a/test/fixtures/ruby/lambda.diffA-B.txt +++ b/test/fixtures/ruby/lambda.diffA-B.txt @@ -1,8 +1,9 @@ (Program -{-(Send +{-(Call {-(Identifier)-} - {-(Hash)-})-} - (Send + {-(Hash)-} + {-(Empty)-})-} + (Call (Identifier) (Function (Empty) @@ -11,7 +12,7 @@ ->(Plus {+(Identifier)+} {+(Integer)+}) })) -{-(Send +{-(Call {-(Identifier)-} {-(Function {-(Empty)-} diff --git a/test/fixtures/ruby/lambda.diffB-A.txt b/test/fixtures/ruby/lambda.diffB-A.txt index 45ba77da6..cca253910 100644 --- a/test/fixtures/ruby/lambda.diffB-A.txt +++ b/test/fixtures/ruby/lambda.diffB-A.txt @@ -1,8 +1,9 @@ (Program -{+(Send +{+(Call {+(Identifier)+} - {+(Hash)+})+} - (Send + {+(Hash)+} + {+(Empty)+})+} + (Call (Identifier) (Function (Empty) @@ -11,7 +12,7 @@ {-(Identifier)-} {-(Integer)-}) ->(Identifier) })) -{+(Send +{+(Call {+(Identifier)+} {+(Function {+(Empty)+} diff --git a/test/fixtures/ruby/lambda.parseA.txt b/test/fixtures/ruby/lambda.parseA.txt index d70c65aeb..2d8da24f0 100644 --- a/test/fixtures/ruby/lambda.parseA.txt +++ b/test/fixtures/ruby/lambda.parseA.txt @@ -1,13 +1,14 @@ (Program - (Send + (Call (Identifier) - (Hash)) - (Send + (Hash) + (Empty)) + (Call (Identifier) (Function (Empty) (Identifier))) - (Send + (Call (Identifier) (Function (Empty) diff --git a/test/fixtures/ruby/lambda.parseB.txt b/test/fixtures/ruby/lambda.parseB.txt index 23f3795f0..becaeb20c 100644 --- a/test/fixtures/ruby/lambda.parseB.txt +++ b/test/fixtures/ruby/lambda.parseB.txt @@ -1,5 +1,5 @@ (Program - (Send + (Call (Identifier) (Function (Empty) diff --git a/test/fixtures/ruby/method-calls-hash-args.diffA-B.txt b/test/fixtures/ruby/method-calls-hash-args.diffA-B.txt index 36b32e871..85fbeada0 100644 --- a/test/fixtures/ruby/method-calls-hash-args.diffA-B.txt +++ b/test/fixtures/ruby/method-calls-hash-args.diffA-B.txt @@ -1,9 +1,10 @@ (Program - (Send + (Call (Identifier) (KeyValue (Symbol) (Boolean)) {+(KeyValue {+(Symbol)+} - {+(Integer)+})+})) + {+(Integer)+})+} + (Empty))) diff --git a/test/fixtures/ruby/method-calls-hash-args.diffB-A.txt b/test/fixtures/ruby/method-calls-hash-args.diffB-A.txt index 7348a10ea..0e6d75399 100644 --- a/test/fixtures/ruby/method-calls-hash-args.diffB-A.txt +++ b/test/fixtures/ruby/method-calls-hash-args.diffB-A.txt @@ -1,9 +1,10 @@ (Program - (Send + (Call (Identifier) (KeyValue (Symbol) (Boolean)) {-(KeyValue {-(Symbol)-} - {-(Integer)-})-})) + {-(Integer)-})-} + (Empty))) diff --git a/test/fixtures/ruby/method-calls-hash-args.parseA.txt b/test/fixtures/ruby/method-calls-hash-args.parseA.txt index 4a1b85927..a9a7064e7 100644 --- a/test/fixtures/ruby/method-calls-hash-args.parseA.txt +++ b/test/fixtures/ruby/method-calls-hash-args.parseA.txt @@ -1,6 +1,7 @@ (Program - (Send + (Call (Identifier) (KeyValue (Symbol) - (Boolean)))) + (Boolean)) + (Empty))) diff --git a/test/fixtures/ruby/method-calls-hash-args.parseB.txt b/test/fixtures/ruby/method-calls-hash-args.parseB.txt index 082424e40..331effe26 100644 --- a/test/fixtures/ruby/method-calls-hash-args.parseB.txt +++ b/test/fixtures/ruby/method-calls-hash-args.parseB.txt @@ -1,9 +1,10 @@ (Program - (Send + (Call (Identifier) (KeyValue (Symbol) (Boolean)) (KeyValue (Symbol) - (Integer)))) + (Integer)) + (Empty))) diff --git a/test/fixtures/ruby/method-calls-keyword-args.diffA-B.txt b/test/fixtures/ruby/method-calls-keyword-args.diffA-B.txt index 29d015331..7b4c1affd 100644 --- a/test/fixtures/ruby/method-calls-keyword-args.diffA-B.txt +++ b/test/fixtures/ruby/method-calls-keyword-args.diffA-B.txt @@ -1,9 +1,10 @@ (Program - (Send + (Call (Identifier) (KeyValue (Identifier) (Boolean)) {+(KeyValue {+(Identifier)+} - {+(Integer)+})+})) + {+(Integer)+})+} + (Empty))) diff --git a/test/fixtures/ruby/method-calls-keyword-args.diffB-A.txt b/test/fixtures/ruby/method-calls-keyword-args.diffB-A.txt index d997a17bc..3db88f4f7 100644 --- a/test/fixtures/ruby/method-calls-keyword-args.diffB-A.txt +++ b/test/fixtures/ruby/method-calls-keyword-args.diffB-A.txt @@ -1,9 +1,10 @@ (Program - (Send + (Call (Identifier) (KeyValue (Identifier) (Boolean)) {-(KeyValue {-(Identifier)-} - {-(Integer)-})-})) + {-(Integer)-})-} + (Empty))) diff --git a/test/fixtures/ruby/method-calls-keyword-args.parseA.txt b/test/fixtures/ruby/method-calls-keyword-args.parseA.txt index 44ef36306..56cfdc9d0 100644 --- a/test/fixtures/ruby/method-calls-keyword-args.parseA.txt +++ b/test/fixtures/ruby/method-calls-keyword-args.parseA.txt @@ -1,6 +1,7 @@ (Program - (Send + (Call (Identifier) (KeyValue (Identifier) - (Boolean)))) + (Boolean)) + (Empty))) diff --git a/test/fixtures/ruby/method-calls-keyword-args.parseB.txt b/test/fixtures/ruby/method-calls-keyword-args.parseB.txt index 2c25ecd29..2d1be75a7 100644 --- a/test/fixtures/ruby/method-calls-keyword-args.parseB.txt +++ b/test/fixtures/ruby/method-calls-keyword-args.parseB.txt @@ -1,9 +1,10 @@ (Program - (Send + (Call (Identifier) (KeyValue (Identifier) (Boolean)) (KeyValue (Identifier) - (Integer)))) + (Integer)) + (Empty))) diff --git a/test/fixtures/ruby/method-calls.diffA-B.txt b/test/fixtures/ruby/method-calls.diffA-B.txt index 3c46d8c5c..c79b1ddb2 100644 --- a/test/fixtures/ruby/method-calls.diffA-B.txt +++ b/test/fixtures/ruby/method-calls.diffA-B.txt @@ -1,9 +1,11 @@ (Program - (Send - {-(Identifier)-} - { (Identifier) - ->(Identifier) }) -{-(Send + (Call + { (MemberAccess + {-(Identifier)-} + {-(Identifier)-}) + ->(Identifier) } + (Empty)) +{-(Call {-(Identifier)-} {-(Identifier)-} {-(Identifier)-} @@ -12,13 +14,16 @@ {-(Integer)-})-} {-(KeyValue {-(Identifier)-} - {-(Integer)-})-})-} -{-(Send + {-(Integer)-})-} + {-(Empty)-})-} +{-(Call {-(Identifier)-} - {-(Send + {-(Call {-(Identifier)-} - {-(Identifier)-})-})-} -{-(Send + {-(Identifier)-} + {-(Empty)-})-} + {-(Empty)-})-} +{-(Call {-(Identifier)-} {-(KeyValue {-(Array)-} @@ -30,4 +35,5 @@ {-(Identifier)-} {-(Function {-(Empty)-} - {-(Integer)-})-})-})-}) + {-(Integer)-})-})-} + {-(Empty)-})-}) diff --git a/test/fixtures/ruby/method-calls.diffB-A.txt b/test/fixtures/ruby/method-calls.diffB-A.txt index c028170a1..83ccfe9eb 100644 --- a/test/fixtures/ruby/method-calls.diffB-A.txt +++ b/test/fixtures/ruby/method-calls.diffB-A.txt @@ -1,9 +1,11 @@ (Program - (Send - {+(Identifier)+} + (Call { (Identifier) - ->(Identifier) }) -{+(Send + ->(MemberAccess + {+(Identifier)+} + {+(Identifier)+}) } + (Empty)) +{+(Call {+(Identifier)+} {+(Identifier)+} {+(Identifier)+} @@ -12,13 +14,16 @@ {+(Integer)+})+} {+(KeyValue {+(Identifier)+} - {+(Integer)+})+})+} -{+(Send + {+(Integer)+})+} + {+(Empty)+})+} +{+(Call {+(Identifier)+} - {+(Send + {+(Call {+(Identifier)+} - {+(Identifier)+})+})+} -{+(Send + {+(Identifier)+} + {+(Empty)+})+} + {+(Empty)+})+} +{+(Call {+(Identifier)+} {+(KeyValue {+(Array)+} @@ -30,4 +35,5 @@ {+(Identifier)+} {+(Function {+(Empty)+} - {+(Integer)+})+})+})+}) + {+(Integer)+})+})+} + {+(Empty)+})+}) diff --git a/test/fixtures/ruby/method-calls.parseA.txt b/test/fixtures/ruby/method-calls.parseA.txt index 0bc76963f..f7d64b9db 100644 --- a/test/fixtures/ruby/method-calls.parseA.txt +++ b/test/fixtures/ruby/method-calls.parseA.txt @@ -1,8 +1,10 @@ (Program - (Send - (Identifier) - (Identifier)) - (Send + (Call + (MemberAccess + (Identifier) + (Identifier)) + (Empty)) + (Call (Identifier) (Identifier) (Identifier) @@ -11,13 +13,16 @@ (Integer)) (KeyValue (Identifier) - (Integer))) - (Send + (Integer)) + (Empty)) + (Call (Identifier) - (Send + (Call (Identifier) - (Identifier))) - (Send + (Identifier) + (Empty)) + (Empty)) + (Call (Identifier) (KeyValue (Array) @@ -29,4 +34,5 @@ (Identifier) (Function (Empty) - (Integer))))) + (Integer))) + (Empty))) diff --git a/test/fixtures/ruby/method-calls.parseB.txt b/test/fixtures/ruby/method-calls.parseB.txt index 28fc4d141..63ef21d34 100644 --- a/test/fixtures/ruby/method-calls.parseB.txt +++ b/test/fixtures/ruby/method-calls.parseB.txt @@ -1,3 +1,4 @@ (Program - (Send - (Identifier))) + (Call + (Identifier) + (Empty))) diff --git a/test/fixtures/ruby/method-invocation.diffA-B.txt b/test/fixtures/ruby/method-invocation.diffA-B.txt index 8804f3a1f..c4de741c2 100644 --- a/test/fixtures/ruby/method-invocation.diffA-B.txt +++ b/test/fixtures/ruby/method-invocation.diffA-B.txt @@ -1,17 +1,25 @@ (Program -{+(Send +{+(Call {+(Identifier)+} - {+(TextElement)+})+} + {+(TextElement)+} + {+(Empty)+})+} +{+(Call + {+(MemberAccess + {+(Identifier)+} + {+(Identifier)+})+} + {+(Empty)+})+} +{+(Call + {+(Identifier)+} + {+(Integer)+} + {+(Integer)+} + {+(Empty)+})+} +{+(Call + {+(Identifier)+} + {+(Integer)+} + {+(Integer)+} + {+(Empty)+})+} {-(Identifier)-} - (Send - (Identifier) - (Identifier)) -{+(Send - {+(Identifier)+} - {+(Integer)+} - {+(Integer)+})+} -{+(Send - {+(Identifier)+} - {+(Integer)+} - {+(Integer)+})+} +{-(MemberAccess + {-(Identifier)-} + {-(Identifier)-})-} {-(Identifier)-}) diff --git a/test/fixtures/ruby/method-invocation.diffB-A.txt b/test/fixtures/ruby/method-invocation.diffB-A.txt index d736631e1..1de44f821 100644 --- a/test/fixtures/ruby/method-invocation.diffB-A.txt +++ b/test/fixtures/ruby/method-invocation.diffB-A.txt @@ -1,17 +1,25 @@ (Program {+(Identifier)+} -{-(Send - {-(Identifier)-} - {-(TextElement)-})-} - (Send - (Identifier) - (Identifier)) +{+(MemberAccess + {+(Identifier)+} + {+(Identifier)+})+} {+(Identifier)+} -{-(Send +{-(Call + {-(Identifier)-} + {-(TextElement)-} + {-(Empty)-})-} +{-(Call + {-(MemberAccess + {-(Identifier)-} + {-(Identifier)-})-} + {-(Empty)-})-} +{-(Call {-(Identifier)-} {-(Integer)-} - {-(Integer)-})-} -{-(Send + {-(Integer)-} + {-(Empty)-})-} +{-(Call {-(Identifier)-} {-(Integer)-} - {-(Integer)-})-}) + {-(Integer)-} + {-(Empty)-})-}) diff --git a/test/fixtures/ruby/method-invocation.parseA.txt b/test/fixtures/ruby/method-invocation.parseA.txt index 5d1ce8893..2c64d0064 100644 --- a/test/fixtures/ruby/method-invocation.parseA.txt +++ b/test/fixtures/ruby/method-invocation.parseA.txt @@ -1,6 +1,6 @@ (Program (Identifier) - (Send + (MemberAccess (Identifier) (Identifier)) (Identifier)) diff --git a/test/fixtures/ruby/method-invocation.parseB.txt b/test/fixtures/ruby/method-invocation.parseB.txt index de9b0825b..c2fb2427a 100644 --- a/test/fixtures/ruby/method-invocation.parseB.txt +++ b/test/fixtures/ruby/method-invocation.parseB.txt @@ -1,15 +1,20 @@ (Program - (Send + (Call (Identifier) - (TextElement)) - (Send - (Identifier) - (Identifier)) - (Send + (TextElement) + (Empty)) + (Call + (MemberAccess + (Identifier) + (Identifier)) + (Empty)) + (Call (Identifier) (Integer) - (Integer)) - (Send + (Integer) + (Empty)) + (Call (Identifier) (Integer) - (Integer))) + (Integer) + (Empty))) diff --git a/test/fixtures/ruby/multiple-assignments.diffA-B.txt b/test/fixtures/ruby/multiple-assignments.diffA-B.txt index b60fbedae..8645f3aef 100644 --- a/test/fixtures/ruby/multiple-assignments.diffA-B.txt +++ b/test/fixtures/ruby/multiple-assignments.diffA-B.txt @@ -37,17 +37,17 @@ {-(Identifier)-})-} {-(Assignment {-( - {-(Send + {-(MemberAccess {-(Identifier)-} {-(Identifier)-})-} - {-(Send + {-(MemberAccess {-(Identifier)-} {-(Identifier)-})-})-} {-( - {-(Send + {-(MemberAccess {-(Identifier)-} {-(Identifier)-})-} - {-(Send + {-(MemberAccess {-(Identifier)-} {-(Identifier)-})-})-})-} {-(Assignment diff --git a/test/fixtures/ruby/multiple-assignments.diffB-A.txt b/test/fixtures/ruby/multiple-assignments.diffB-A.txt index 9072ef138..9ed61e0d3 100644 --- a/test/fixtures/ruby/multiple-assignments.diffB-A.txt +++ b/test/fixtures/ruby/multiple-assignments.diffB-A.txt @@ -37,17 +37,17 @@ {+(Identifier)+})+} {+(Assignment {+( - {+(Send + {+(MemberAccess {+(Identifier)+} {+(Identifier)+})+} - {+(Send + {+(MemberAccess {+(Identifier)+} {+(Identifier)+})+})+} {+( - {+(Send + {+(MemberAccess {+(Identifier)+} {+(Identifier)+})+} - {+(Send + {+(MemberAccess {+(Identifier)+} {+(Identifier)+})+})+})+} {+(Assignment diff --git a/test/fixtures/ruby/multiple-assignments.parseA.txt b/test/fixtures/ruby/multiple-assignments.parseA.txt index 917c016f8..ccd753227 100644 --- a/test/fixtures/ruby/multiple-assignments.parseA.txt +++ b/test/fixtures/ruby/multiple-assignments.parseA.txt @@ -36,17 +36,17 @@ (Identifier)) (Assignment ( - (Send + (MemberAccess (Identifier) (Identifier)) - (Send + (MemberAccess (Identifier) (Identifier))) ( - (Send + (MemberAccess (Identifier) (Identifier)) - (Send + (MemberAccess (Identifier) (Identifier)))) (Assignment diff --git a/test/fixtures/ruby/relational-operator.diffA-B.txt b/test/fixtures/ruby/relational-operator.diffA-B.txt index 573104fbf..a49ea9971 100644 --- a/test/fixtures/ruby/relational-operator.diffA-B.txt +++ b/test/fixtures/ruby/relational-operator.diffA-B.txt @@ -1,5 +1,5 @@ (Program -{ (Equal +{(Equal {-(Identifier)-} {-(Identifier)-}) ->(Comparison @@ -10,12 +10,11 @@ {+(Identifier)+})+} {+(Assignment {+(Identifier)+} - {+(Not - {+(Identifier)+})+})+} + {+(Not{+(Identifier)+})+})+} {-(Not {-(Equal {-(Identifier)-} {-(Identifier)-})-})-} {-(Equal {-(Identifier)-} - {-(Identifier)-})-}) + {-(Identifier)-})- }) diff --git a/test/fixtures/ruby/relational-operator.diffB-A.txt b/test/fixtures/ruby/relational-operator.diffB-A.txt index 6c5ab4bab..9e9a702a3 100644 --- a/test/fixtures/ruby/relational-operator.diffB-A.txt +++ b/test/fixtures/ruby/relational-operator.diffB-A.txt @@ -1,5 +1,5 @@ (Program -{ (Comparison +{(Comparison {-(Identifier)-} {-(Identifier)-}) ->(Equal @@ -17,5 +17,4 @@ {-(Identifier)-})-} {-(Assignment {-(Identifier)-} - {-(Not - {-(Identifier)-})-})-}) + {-(Not{-(Identifier)-})-})- }) diff --git a/test/fixtures/ruby/require.diffA-B.txt b/test/fixtures/ruby/require.diffA-B.txt index a5dbacab3..ec63bdae0 100644 --- a/test/fixtures/ruby/require.diffA-B.txt +++ b/test/fixtures/ruby/require.diffA-B.txt @@ -2,9 +2,10 @@ (Require { (TextElement) ->(TextElement) }) - (Send + (Call { (Identifier) ->(Identifier) } {+(Symbol)+} {+(TextElement)+} - {-(Identifier)-})) + {-(Identifier)-} + (Empty))) diff --git a/test/fixtures/ruby/require.diffB-A.txt b/test/fixtures/ruby/require.diffB-A.txt index 9097a9f15..890c906af 100644 --- a/test/fixtures/ruby/require.diffB-A.txt +++ b/test/fixtures/ruby/require.diffB-A.txt @@ -2,9 +2,10 @@ (Require { (TextElement) ->(TextElement) }) - (Send + (Call { (Identifier) ->(Identifier) } {+(Identifier)+} {-(Symbol)-} - {-(TextElement)-})) + {-(TextElement)-} + (Empty))) diff --git a/test/fixtures/ruby/require.parseA.txt b/test/fixtures/ruby/require.parseA.txt index 3537988d3..f33f28750 100644 --- a/test/fixtures/ruby/require.parseA.txt +++ b/test/fixtures/ruby/require.parseA.txt @@ -1,6 +1,7 @@ (Program (Require (TextElement)) - (Send + (Call (Identifier) - (Identifier))) + (Identifier) + (Empty))) diff --git a/test/fixtures/ruby/require.parseB.txt b/test/fixtures/ruby/require.parseB.txt index 25ff2f139..638ed1768 100644 --- a/test/fixtures/ruby/require.parseB.txt +++ b/test/fixtures/ruby/require.parseB.txt @@ -1,7 +1,8 @@ (Program (Require (TextElement)) - (Send + (Call (Identifier) (Symbol) - (TextElement))) + (TextElement) + (Empty))) From 17ae13474d788450394fc88ccf0c512afd1f4de3 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 9 Apr 2018 13:17:23 -0700 Subject: [PATCH 2/3] Flag to fail on assignment warnings --- src/Semantic/CLI.hs | 1 + src/Semantic/Log.hs | 16 +++++++++------- src/Semantic/Task.hs | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index f6e84513f..60df96e4d 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -53,6 +53,7 @@ arguments = info (version <*> helper <*> ((,) <$> optionsParser <*> argumentsPar <*> pure False -- PrintSource <*> pure Log.logfmtFormatter -- Formatter <*> pure 0 -- ProcessID + <*> switch (long "fail-on-warning" <> help "Fail on assignment warnings.") argumentsParser = (. Task.writeToOutput) . (>>=) <$> hsubparser (diffCommand <> parseCommand) <*> ( Right <$> strOption (long "output" <> short 'o' <> help "Output path, defaults to stdout") diff --git a/src/Semantic/Log.hs b/src/Semantic/Log.hs index 55c934de0..f472c0ad6 100644 --- a/src/Semantic/Log.hs +++ b/src/Semantic/Log.hs @@ -83,13 +83,14 @@ terminalFormatter Options{..} (Message level message pairs time) = -- | Options controlling logging, error handling, &c. data Options = Options - { optionsEnableColour :: Bool -- ^ Whether to enable colour formatting for logging (Only works when logging to a terminal that supports ANSI colors). - , optionsLevel :: Maybe Level -- ^ What level of messages to log. 'Nothing' disabled logging. - , optionsRequestID :: Maybe String -- ^ Optional request id for tracing across systems. - , optionsIsTerminal :: Bool -- ^ Whether a terminal is attached (set automaticaly at runtime). - , optionsPrintSource :: Bool -- ^ Whether to print the source reference when logging errors (set automatically at runtime). - , optionsFormatter :: Options -> Message -> String -- ^ Log formatter to use (set automaticaly at runtime). - , optionsProcessID :: CPid -- ^ ProcessID (set automaticaly at runtime). + { optionsEnableColour :: Bool -- ^ Whether to enable colour formatting for logging (Only works when logging to a terminal that supports ANSI colors). + , optionsLevel :: Maybe Level -- ^ What level of messages to log. 'Nothing' disabled logging. + , optionsRequestID :: Maybe String -- ^ Optional request id for tracing across systems. + , optionsIsTerminal :: Bool -- ^ Whether a terminal is attached (set automaticaly at runtime). + , optionsPrintSource :: Bool -- ^ Whether to print the source reference when logging errors (set automatically at runtime). + , optionsFormatter :: Options -> Message -> String -- ^ Log formatter to use (set automaticaly at runtime). + , optionsProcessID :: CPid -- ^ ProcessID (set automaticaly at runtime). + , optionsFailOnWarning :: Bool } defaultOptions :: Options @@ -101,6 +102,7 @@ defaultOptions = Options , optionsPrintSource = False , optionsFormatter = logfmtFormatter , optionsProcessID = 0 + , optionsFailOnWarning = False } configureOptionsForHandle :: MonadIO io => Handle -> Options -> io Options diff --git a/src/Semantic/Task.hs b/src/Semantic/Task.hs index 8ccf979a8..e4287c4d0 100644 --- a/src/Semantic/Task.hs +++ b/src/Semantic/Task.hs @@ -51,6 +51,7 @@ import Analysis.Decorator (decoratorWithAlgebra) import qualified Assigning.Assignment as Assignment import qualified Control.Abstract.Analysis as Analysis import qualified Control.Exception as Exc +import Control.Monad import Control.Monad.Effect.Exception import Control.Monad.Effect.Internal as Eff hiding (run) import Control.Monad.Effect.Reader @@ -215,6 +216,7 @@ runParser blob@Blob{..} parser = case parser of _ -> do writeStat (Stat.increment "parse.assign_warnings" languageTag) logError options Warning blob err (("task", "assign") : blobFields) + when (optionsFailOnWarning options) $ throwError (toException err) writeStat (Stat.count "parse.nodes" (length term) languageTag) pure term MarkdownParser -> From 7b54a26859189c0593e41a57d3adf9f5c65bf8c6 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 9 Apr 2018 13:39:17 -0700 Subject: [PATCH 3/3] Order matters here - fix parse-examples --- src/Language/Ruby/Assignment.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index f61f08d3b..7f72c14cd 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -307,7 +307,7 @@ methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> nameExpression = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expression call :: Assignment -call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expressions <|> args)) +call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (args <|> expressions)) where args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expressions