1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Merge remote-tracking branch 'origin/master' into graph-cli

This commit is contained in:
Timothy Clem 2018-04-09 15:38:10 -07:00
commit b02b7c74c9
51 changed files with 281 additions and 218 deletions

View File

@ -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 Rubys grammar onto a program in Rubys 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 <*> (args <|> expressions))
where
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expressions
rescue :: Assignment
rescue = rescue'

View File

@ -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)

View File

@ -57,6 +57,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 <> graphCommand)
<*> ( Right <$> strOption (long "output" <> short 'o' <> help "Output path, defaults to stdout")

View File

@ -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

View File

@ -53,6 +53,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
@ -228,6 +229,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 ->

View File

@ -5,6 +5,7 @@
(
(Try
{ ([])
->(Send
->(Call
{+(Identifier)+}
{+(TextElement)+}) }))))
{+(TextElement)+}
{+(Empty)+}) }))))

View File

@ -4,7 +4,8 @@
(Identifier)
(
(Try
{ (Send
{ (Call
{-(Identifier)-}
{-(TextElement)-})
{-(TextElement)-}
{-(Empty)-})
->([]) }))))

View File

@ -4,6 +4,7 @@
(Identifier)
(
(Try
(Send
(Call
(Identifier)
(TextElement))))))
(TextElement)
(Empty))))))

View File

@ -1,10 +1,12 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
{ ([])
->(Send
{+(Identifier)+}) }))))
->(Call
{+(Identifier)+}
{+(Empty)+}) }))))

View File

@ -1,10 +1,12 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
{ (Send
{-(Identifier)-})
{ (Call
{-(Identifier)-}
{-(Empty)-})
->([]) }))))

View File

@ -1,8 +1,9 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
([])))))

View File

@ -1,9 +1,11 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
(Send
(Identifier))))))
(Call
(Identifier)
(Empty))))))

View File

@ -2,11 +2,13 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
(
{+(Send
{+(Identifier)+})+})
{+(Call
{+(Identifier)+}
{+(Empty)+})+})
(Empty))))

View File

@ -2,11 +2,13 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
([]
{-(Send
{-(Identifier)-})-})
{-(Call
{-(Identifier)-}
{-(Empty)-})-})
(Empty))))

View File

@ -2,8 +2,9 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
([])

View File

@ -2,11 +2,13 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(Empty))))

View File

@ -6,9 +6,10 @@
{+(Integer)+}
{+(Integer)+}
{+(Integer)+})+}
{+(Send
{+(Call
{+(Identifier)+}
{+(Identifier)+})+})+}
{+(Identifier)+}
{+(Empty)+})+})+}
{-(ForEach
{-(
{-(Identifier)-})-}

View File

@ -22,9 +22,10 @@
{+(Integer)+}
{+(Integer)+}
{+(Empty)+}) }
{ (Send
{ (Call
{-(Identifier)-}
{-(Identifier)-})
{-(Identifier)-}
{-(Empty)-})
->(Boolean) })
{+(ForEach
{+(

View File

@ -6,6 +6,7 @@
(Integer)
(Integer)
(Integer))
(Send
(Call
(Identifier)
(Identifier))))
(Identifier)
(Empty))))

View File

@ -1,9 +1,12 @@
(Program
{+(Send
{+(Send
{+(Identifier)+}
{+(TextElement)+}
{+(TextElement)+})+}
{+(Identifier)+})+}
{+(Call
{+(MemberAccess
{+(Call
{+(Identifier)+}
{+(TextElement)+}
{+(TextElement)+}
{+(Empty)+})+}
{+(Identifier)+})+}
{+(Empty)+})+}
{-(TextElement)-}
{-(TextElement)-})

View File

@ -1,9 +1,12 @@
(Program
{+(TextElement)+}
{+(TextElement)+}
{-(Send
{-(Send
{-(Identifier)-}
{-(TextElement)-}
{-(TextElement)-})-}
{-(Identifier)-})-})
{-(Call
{-(MemberAccess
{-(Call
{-(Identifier)-}
{-(TextElement)-}
{-(TextElement)-}
{-(Empty)-})-}
{-(Identifier)-})-}
{-(Empty)-})-})

View File

@ -1,7 +1,10 @@
(Program
(Send
(Send
(Identifier)
(TextElement)
(TextElement))
(Identifier)))
(Call
(MemberAccess
(Call
(Identifier)
(TextElement)
(TextElement)
(Empty))
(Identifier))
(Empty)))

View File

@ -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)-}

View File

@ -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)+}

View File

@ -1,13 +1,14 @@
(Program
(Send
(Call
(Identifier)
(Hash))
(Send
(Hash)
(Empty))
(Call
(Identifier)
(Function
(Empty)
(Identifier)))
(Send
(Call
(Identifier)
(Function
(Empty)

View File

@ -1,5 +1,5 @@
(Program
(Send
(Call
(Identifier)
(Function
(Empty)

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))
{+(KeyValue
{+(Symbol)+}
{+(Integer)+})+}))
{+(Integer)+})+}
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))
{-(KeyValue
{-(Symbol)-}
{-(Integer)-})-}))
{-(Integer)-})-}
(Empty)))

View File

@ -1,6 +1,7 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))))
(Boolean))
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))
(KeyValue
(Symbol)
(Integer))))
(Integer))
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))
{+(KeyValue
{+(Identifier)+}
{+(Integer)+})+}))
{+(Integer)+})+}
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))
{-(KeyValue
{-(Identifier)-}
{-(Integer)-})-}))
{-(Integer)-})-}
(Empty)))

View File

@ -1,6 +1,7 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))))
(Boolean))
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))
(KeyValue
(Identifier)
(Integer))))
(Integer))
(Empty)))

View File

@ -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)-})-})

View File

@ -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)+})+})

View File

@ -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)))

View File

@ -1,3 +1,4 @@
(Program
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))

View File

@ -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)-})

View File

@ -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)-})-})

View File

@ -1,6 +1,6 @@
(Program
(Identifier)
(Send
(MemberAccess
(Identifier)
(Identifier))
(Identifier))

View File

@ -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)))

View File

@ -37,17 +37,17 @@
{-(Identifier)-})-}
{-(Assignment
{-(
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-})-}
{-(
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-})-})-}
{-(Assignment

View File

@ -37,17 +37,17 @@
{+(Identifier)+})+}
{+(Assignment
{+(
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+})+}
{+(
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+})+})+}
{+(Assignment

View File

@ -36,17 +36,17 @@
(Identifier))
(Assignment
(
(Send
(MemberAccess
(Identifier)
(Identifier))
(Send
(MemberAccess
(Identifier)
(Identifier)))
(
(Send
(MemberAccess
(Identifier)
(Identifier))
(Send
(MemberAccess
(Identifier)
(Identifier))))
(Assignment

View File

@ -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)-})- })

View File

@ -1,5 +1,5 @@
(Program
{ (Comparison
{(Comparison
{-(Identifier)-}
{-(Identifier)-})
->(Equal
@ -17,5 +17,4 @@
{-(Identifier)-})-}
{-(Assignment
{-(Identifier)-}
{-(Not
{-(Identifier)-})-})-})
{-(Not{-(Identifier)-})-})- })

View File

@ -2,9 +2,10 @@
(Require
{ (TextElement)
->(TextElement) })
(Send
(Call
{ (Identifier)
->(Identifier) }
{+(Symbol)+}
{+(TextElement)+}
{-(Identifier)-}))
{-(Identifier)-}
(Empty)))

View File

@ -2,9 +2,10 @@
(Require
{ (TextElement)
->(TextElement) })
(Send
(Call
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
{-(Symbol)-}
{-(TextElement)-}))
{-(TextElement)-}
(Empty)))

View File

@ -1,6 +1,7 @@
(Program
(Require
(TextElement))
(Send
(Call
(Identifier)
(Identifier)))
(Identifier)
(Empty)))

View File

@ -1,7 +1,8 @@
(Program
(Require
(TextElement))
(Send
(Call
(Identifier)
(Symbol)
(TextElement)))
(TextElement)
(Empty)))