1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Merge branch 'master' into scopes-and-frames

This commit is contained in:
Josh Vera 2018-09-18 13:14:27 -04:00 committed by GitHub
commit 8d9c627579
29 changed files with 142 additions and 103 deletions

View File

@ -267,10 +267,10 @@ floatLiteral :: Assignment Term
floatLiteral = makeTerm <$> symbol FloatLiteral <*> (Literal.Float <$> source)
identifier :: Assignment Term
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier . name <$> source)
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier' <|> symbol Identifier'') <*> (Syntax.Identifier . name <$> source)
identifier' :: Assignment Name
identifier' = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
identifier' = (symbol Identifier <|> symbol Identifier' <|> symbol Identifier'') *> (name <$> source)
imaginaryLiteral :: Assignment Term
imaginaryLiteral = makeTerm <$> symbol ImaginaryLiteral <*> (Literal.Complex <$> source)

View File

@ -163,6 +163,7 @@ expressionChoices =
, heredoc
, identifier
, if'
, then'
, lambda
, literal
, method
@ -270,7 +271,7 @@ literal =
(children (inject . Literal.String <$> some (interpolation <|> escapeSequence)) <|> inject . Literal.TextElement <$> source)
symbol' :: Assignment Term
symbol' = makeTerm' <$> (symbol Symbol <|> symbol Symbol' <|> symbol BareSymbol) <*>
symbol' = makeTerm' <$> (symbol Symbol <|> symbol Symbol' <|> symbol Symbol'' <|> symbol BareSymbol) <*>
(children (inject . Literal.Symbol <$> some interpolation) <|> inject . Literal.SymbolElement <$> source)
interpolation :: Assignment Term
@ -363,14 +364,17 @@ undef = makeTerm <$> symbol Undef <*> children (Expression.Call [] <$> name' <*>
where name' = makeTerm <$> location <*> (Syntax.Identifier . name <$> source)
if' :: Assignment Term
if' = ifElsif If
if' = ifElsif If
<|> makeTerm <$> symbol IfModifier <*> children (flip Statement.If <$> expression <*> expression <*> emptyTerm)
where
ifElsif s = makeTerm <$> symbol s <*> children (Statement.If <$> expression <*> expressions' <*> (elsif' <|> else' <|> emptyTerm))
expressions' = makeTerm <$> location <*> manyTermsTill expression (void (symbol Else) <|> void (symbol Elsif) <|> eof)
elsif' = postContextualize comment (ifElsif Elsif)
expressions' = makeTerm <$> location <*> manyTermsTill expression (void (symbol Else) <|> void (symbol Elsif) <|> eof)
else' = postContextualize comment (symbol Else *> children expressions)
then' :: Assignment Term
then' = postContextualize comment (symbol Then *> children expressions)
unless :: Assignment Term
unless = makeTerm <$> symbol Unless <*> children (Statement.If <$> invert expression <*> expressions' <*> (else' <|> emptyTerm))
<|> makeTerm <$> symbol UnlessModifier <*> children (flip Statement.If <$> expression <*> invert expression <*> emptyTerm)
@ -505,17 +509,17 @@ unary = symbol Unary >>= \ location ->
<|> makeTerm location . Expression.Not <$> children ( symbol AnonBang *> expression )
<|> makeTerm location . Expression.Not <$> children ( symbol AnonNot *> expression )
<|> makeTerm location <$> children (Expression.Call [] <$> (makeTerm <$> symbol AnonDefinedQuestion <*> (Syntax.Identifier . name <$> source)) <*> some expression <*> emptyTerm)
<|> makeTerm location . Expression.Negate <$> children ( symbol AnonMinus' *> expression )
<|> makeTerm location . Expression.Negate <$> children ( (symbol AnonMinus <|> symbol AnonMinus' <|> symbol AnonMinus'') *> expression )
<|> children ( symbol AnonPlus *> expression )
-- TODO: Distinguish `===` from `==` ?
binary :: Assignment Term
binary = makeTerm' <$> symbol Binary <*> children (infixTerm expression expression
[ (inject .) . Expression.Plus <$ symbol AnonPlus
, (inject .) . Expression.Minus <$ symbol AnonMinus'
, (inject .) . Expression.Times <$ symbol AnonStar'
, (inject .) . Expression.Minus <$ (symbol AnonMinus <|> symbol AnonMinus' <|> symbol AnonMinus'')
, (inject .) . Expression.Times <$ (symbol AnonStar <|> symbol AnonStar')
, (inject .) . Expression.Power <$ symbol AnonStarStar
, (inject .) . Expression.DividedBy <$ symbol AnonSlash
, (inject .) . Expression.DividedBy <$ (symbol AnonSlash <|> symbol AnonSlash' <|> symbol AnonSlash'')
, (inject .) . Expression.Modulo <$ symbol AnonPercent
, (inject .) . Expression.And <$ symbol AnonAmpersandAmpersand
, (inject .) . Ruby.Syntax.LowPrecedenceAnd <$ symbol AnonAnd
@ -530,7 +534,7 @@ binary = makeTerm' <$> symbol Binary <*> children (infixTerm expression expressi
-- for this situation.
, (inject .) . Expression.Equal <$ (symbol AnonEqualEqual <|> symbol AnonEqualEqualEqual)
, (inject .) . invert Expression.Equal <$ symbol AnonBangEqual
, (inject .) . Expression.LShift <$ symbol AnonLAngleLAngle
, (inject .) . Expression.LShift <$ (symbol AnonLAngleLAngle <|> symbol AnonLAngleLAngle')
, (inject .) . Expression.RShift <$ symbol AnonRAngleRAngle
, (inject .) . Expression.Comparison <$ symbol AnonLAngleEqualRAngle
, (inject .) . Expression.LessThan <$ symbol AnonLAngle

View File

@ -382,7 +382,7 @@ false :: Assignment Term
false = makeTerm <$> symbol Grammar.False <*> (Literal.false <$ rawSource)
identifier :: Assignment Term
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier . name <$> source)
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier' <|> symbol Identifier'') <*> (Syntax.Identifier . name <$> source)
class' :: Assignment Term
class' = makeClass <$> symbol Class <*> children ((,,,,) <$> manyTerm decorator <*> term typeIdentifier <*> (symbol TypeParameters *> children (manyTerm typeParameter') <|> pure []) <*> (classHeritage' <|> pure []) <*> classBodyStatements)
@ -515,7 +515,7 @@ typeAnnotation' :: Assignment Term
typeAnnotation' = makeTerm <$> symbol TypeAnnotation <*> children (TypeScript.Syntax.Annotation <$> term ty)
typeParameter' :: Assignment Term
typeParameter' = makeTerm <$> symbol Grammar.TypeParameter <*> children (TypeScript.Syntax.TypeParameter <$> term identifier <*> term (constraint <|> emptyTerm) <*> term (defaultType <|> emptyTerm))
typeParameter' = makeTerm <$> symbol Grammar.TypeParameter <*> children (TypeScript.Syntax.TypeParameter <$> term typeIdentifier <*> term (constraint <|> emptyTerm) <*> term (defaultType <|> emptyTerm))
defaultType :: Assignment Term
defaultType = makeTerm <$> symbol Grammar.DefaultType <*> children (TypeScript.Syntax.DefaultType <$> term ty)
@ -593,7 +593,7 @@ typeQuery :: Assignment Term
typeQuery = makeTerm <$> symbol Grammar.TypeQuery <*> children (TypeScript.Syntax.TypeQuery <$> term (identifier <|> nestedIdentifier))
indexTypeQuery :: Assignment Term
indexTypeQuery = makeTerm <$> symbol Grammar.IndexTypeQuery <*> children (TypeScript.Syntax.IndexTypeQuery <$> term (typeIdentifier <|> nestedIdentifier))
indexTypeQuery = makeTerm <$> symbol Grammar.IndexTypeQuery <*> children (TypeScript.Syntax.IndexTypeQuery <$> term (typeIdentifier <|> nestedTypeIdentifier))
thisType :: Assignment Term
thisType = makeTerm <$> symbol Grammar.ThisType <*> (TypeScript.Syntax.ThisType <$> source)
@ -725,7 +725,7 @@ importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> childr
makeImportTerm loc ([x], from) = makeImportTerm1 loc from x
makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs
importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> ((Just <$> rawIdentifier) <|> pure Nothing))
rawIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
rawIdentifier = (symbol Identifier <|> symbol Identifier' <|> symbol Identifier'') *> (name <$> source)
makeNameAliasPair from (Just alias) = (from, alias)
makeNameAliasPair from Nothing = (from, from)
@ -784,7 +784,7 @@ exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (flip
<|> symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> pure Nothing)
makeNameAliasPair from (Just alias) = TypeScript.Syntax.Alias from alias
makeNameAliasPair from Nothing = TypeScript.Syntax.Alias from from
rawIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
rawIdentifier = (symbol Identifier <|> symbol Identifier' <|> symbol Identifier'') *> (name <$> source)
-- TODO: Need to validate that inline comments are still handled with this change in assigning to Path and not a Term.
fromClause = symbol Grammar.String *> (TypeScript.Resolution.importPath <$> source)
@ -860,7 +860,7 @@ variableDeclarator =
where
makeVarDecl loc (subject, annotations, value) = makeTerm loc (Statement.Assignment [annotations] subject value)
requireCall = symbol CallExpression *> children ((symbol Identifier <|> symbol Identifier') *> do
requireCall = symbol CallExpression *> children ((symbol Identifier <|> symbol Identifier' <|> symbol Identifier'') *> do
s <- source
guard (s == "require")
symbol Arguments *> children (symbol Grammar.String *> (TypeScript.Resolution.importPath <$> source))

View File

@ -152,7 +152,7 @@ spec = parallel $ do
it "produces JSON output if there are parse errors" $ do
blobs <- blobsForPaths (both "ruby/toc/methods.A.rb" "ruby/toc/methods.X.rb")
output <- runTaskWithOptions (defaultOptions { optionsLogLevel = Nothing }) (runDiff ToCDiffRenderer [blobs])
runBuilder output `shouldBe` ("{\"changes\":{\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\":[{\"span\":{\"start\":[1,1],\"end\":[2,4]},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"removed\"},{\"span\":{\"start\":[4,1],\"end\":[5,4]},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"removed\"}]},\"errors\":{\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\":[{\"span\":{\"start\":[1,1],\"end\":[3,1]},\"error\":\"expected end of input nodes, but got ParseError\",\"language\":\"Ruby\"}]}}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"changes\":{\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\":[{\"span\":{\"start\":[1,1],\"end\":[2,4]},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"removed\"},{\"span\":{\"start\":[4,1],\"end\":[5,4]},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"removed\"}]},\"errors\":{\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\":[{\"span\":{\"start\":[1,1],\"end\":[2,3]},\"error\":\"expected end of input nodes, but got ParseError\",\"language\":\"Ruby\"}]}}\n" :: ByteString)
it "ignores anonymous functions" $ do
blobs <- blobsForPaths (both "ruby/toc/lambda.A.rb" "ruby/toc/lambda.B.rb")

View File

@ -18,5 +18,6 @@
{+(If
{+(Send
{+(Identifier)+})+}
{+(Statements)+}
{+(Statements
{+(Statements)+})+}
{+(Empty)+})+})

View File

@ -18,5 +18,6 @@
{-(If
{-(Send
{-(Identifier)-})-}
{-(Statements)-}
{-(Statements
{-(Statements)-})-}
{-(Empty)-})-})

View File

@ -7,5 +7,6 @@
(If
(Send
(Identifier))
(Statements)
(Statements
(Statements))
(Empty)))

View File

@ -14,5 +14,6 @@
{+(Not
{+(Send
{+(Identifier)+})+})+}
{+(Statements)+}
{+(Statements
{+(Statements)+})+}
{+(Empty)+})+})

View File

@ -14,5 +14,6 @@
{-(Not
{-(Send
{-(Identifier)-})-})-}
{-(Statements)-}
{-(Statements
{-(Statements)-})-}
{-(Empty)-})-})

View File

@ -9,5 +9,6 @@
(Not
(Send
(Identifier)))
(Statements)
(Statements
(Statements))
(Empty)))

View File

@ -1,6 +1,8 @@
case foo
when bar
baz
when x
when y
else
qoz
end

View File

@ -3,23 +3,33 @@
(Send
(Identifier))
(Statements
{+(Pattern
{+(Statements
{+(Send
{+(Identifier)+})+})+}
{+(Statements
{+(Send
{+(Identifier)+})+})+})+}
(Pattern
(Statements
(Send
{ (Identifier)
->(Identifier) }))
(Statements
(Statements))
{+(Pattern
{+(Statements
{+(Send
{+(Identifier)+})+}
{+(Send
{+(Identifier)+})+}
{-(Pattern
{-(Statements
{-(Send
{-(Identifier)-})-}
{-(Send
{-(Identifier)-})-})-}
{-(Statements
{-(Send
{-(Identifier)-})-}
{-(Statements)-})-})-})))))
{+(Identifier)+})+})+}
{+(Statements)+})+}
{+(Send
{+(Identifier)+})+}
{-(Pattern
{-(Statements
{-(Send
{-(Identifier)-})-}
{-(Send
{-(Identifier)-})-})-}
{-(Statements
{-(Send
{-(Identifier)-})-})-})-}
{-(Statements)-})))

View File

@ -3,23 +3,30 @@
(Send
(Identifier))
(Statements
{+(Pattern
{+(Statements
{+(Send
{+(Identifier)+})+})+}
{+(Statements)+})+}
(Pattern
(Statements
(Send
{ (Identifier)
->(Identifier) }))
(Identifier))
{+(Send
{+(Identifier)+})+})
(Statements
{+(Pattern
{+(Statements
{+(Send
{+(Identifier)+})+}
{+(Send
{+(Identifier)+})+})+}
{+(Statements
{+(Send
{+(Identifier)+})+}
{+(Statements)+})+})+}
(Send
(Identifier))))
{+(Statements)+}
{-(Pattern
{-(Statements
{-(Send
{-(Identifier)-})-}
{-(Identifier)-})-})-}
{-(Statements)-})-}
{-(Pattern
{-(Statements
{-(Send
{-(Identifier)-})-})))))
{-(Identifier)-})-})-}
{-(Statements)-})-}
{-(Send
{-(Identifier)-})-})))

View File

@ -7,14 +7,14 @@
(Statements
(Send
(Identifier)))
(Statements))
(Pattern
(Statements
(Pattern
(Statements
(Send
(Identifier))
(Send
(Identifier)))
(Statements
(Send
(Identifier))
(Statements))))))))
(Send
(Identifier))
(Send
(Identifier)))
(Statements
(Send
(Identifier))))
(Statements))))

View File

@ -9,6 +9,16 @@
(Identifier)))
(Statements
(Send
(Identifier))
(Identifier))))
(Pattern
(Statements
(Send
(Identifier)))))))
(Identifier)))
(Statements))
(Pattern
(Statements
(Send
(Identifier)))
(Statements))
(Send
(Identifier)))))

View File

@ -8,17 +8,17 @@
(Send
(Identifier)))
(Statements
{+(Send
{+(Identifier)+})+}))
{+(Pattern
{+(Statements
{+(Send
{+(Identifier)+})+}
{+(Pattern
{+(Statements
{+(Send
{+(Identifier)+})+}
{+(Send
{+(Identifier)+})+})+}
{+(Statements
{+(Send
{+(Identifier)+})+})+})+}))))
{+(Send
{+(Identifier)+})+})+}
{+(Statements)+})+}
{+(Send
{+(Identifier)+})+}))
{-(Match
{-(Empty)-}
{-(Statements

View File

@ -8,17 +8,17 @@
(Send
(Identifier)))
(Statements
{-(Send
{-(Identifier)-})-}))
{-(Pattern
{-(Statements
{-(Send
{-(Identifier)-})-}
{-(Pattern
{-(Statements
{-(Send
{-(Identifier)-})-}
{-(Send
{-(Identifier)-})-})-}
{-(Statements
{-(Send
{-(Identifier)-})-})-})-}))))
{-(Send
{-(Identifier)-})-})-}
{-(Statements)-})-}
{-(Send
{-(Identifier)-})-}))
{+(Match
{+(Empty)+}
{+(Statements

View File

@ -7,15 +7,15 @@
(Statements
(Send
(Identifier)))
(Statements
(Send
(Identifier))))
(Pattern
(Statements
(Send
(Identifier))
(Pattern
(Statements
(Send
(Identifier))
(Send
(Identifier)))
(Statements
(Send
(Identifier)))))))))
(Send
(Identifier)))
(Statements))
(Send
(Identifier)))))

View File

@ -1,8 +1,8 @@
(Statements
(Class
(TypeParameter
{ (Identifier)
->(Identifier) }
{ (TypeIdentifier)
->(TypeIdentifier) }
(Empty)
(Empty))
{ (TypeIdentifier)

View File

@ -1,8 +1,8 @@
(Statements
(Class
(TypeParameter
{ (Identifier)
->(Identifier) }
{ (TypeIdentifier)
->(TypeIdentifier) }
(Empty)
(Empty))
{ (TypeIdentifier)

View File

@ -1,7 +1,7 @@
(Statements
(Class
(TypeParameter
(Identifier)
(TypeIdentifier)
(Empty)
(Empty))
(TypeIdentifier)

View File

@ -1,7 +1,7 @@
(Statements
(Class
(TypeParameter
(Identifier)
(TypeIdentifier)
(Empty)
(Empty))
(TypeIdentifier)

View File

@ -5,7 +5,7 @@
{+(TypeIdentifier)+})+}
{-(TypeParameters
{-(TypeParameter
{-(Identifier)-}
{-(TypeIdentifier)-}
{-(Empty)-}
{-(Empty)-})-})-}
{-(Annotation

View File

@ -2,7 +2,7 @@
(Function
{+(TypeParameters
{+(TypeParameter
{+(Identifier)+}
{+(TypeIdentifier)+}
{+(Empty)+}
{+(Empty)+})+})+}
{+(Annotation

View File

@ -2,7 +2,7 @@
(Function
(TypeParameters
(TypeParameter
(Identifier)
(TypeIdentifier)
(Empty)
(Empty)))
(Annotation

View File

@ -3,7 +3,7 @@
{+(Empty)+}
{-(TypeParameters
{-(TypeParameter
{-(Identifier)-}
{-(TypeIdentifier)-}
{-(Empty)-}
{-(Empty)-})-})-}
{ (TypeIdentifier)

View File

@ -2,7 +2,7 @@
(InterfaceDeclaration
{+(TypeParameters
{+(TypeParameter
{+(Identifier)+}
{+(TypeIdentifier)+}
{+(Empty)+}
{+(Empty)+})+})+}
{-(Empty)-}

View File

@ -2,7 +2,7 @@
(InterfaceDeclaration
(TypeParameters
(TypeParameter
(Identifier)
(TypeIdentifier)
(Empty)
(Empty)))
(TypeIdentifier)

@ -1 +1 @@
Subproject commit 75f9ddd2deb992d944a8485fe9b0cc7c84911c31
Subproject commit 09ff8a81cd92a696939eb82e0c33111bde3f0376