1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

Merge branch 'master' into oh-javascript

This commit is contained in:
Timothy Clem 2017-06-08 11:48:56 -07:00 committed by GitHub
commit 1c2ee1880c
2 changed files with 39 additions and 1 deletions

View File

@ -30,7 +30,6 @@ newtype Pattern a = Pattern a
instance Eq1 Pattern where liftEq = genericLiftEq
instance Show1 Pattern where liftShowsPrec = genericLiftShowsPrec
-- Assignment
-- | Assignment to a variable or other lvalue.
@ -67,6 +66,12 @@ newtype Continue a = Continue a
instance Eq1 Continue where liftEq = genericLiftEq
instance Show1 Continue where liftShowsPrec = genericLiftShowsPrec
newtype NoOp a = NoOp a
deriving (Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable)
instance Eq1 NoOp where liftEq = genericLiftEq
instance Show1 NoOp where liftShowsPrec = genericLiftShowsPrec
-- Loops

View File

@ -53,8 +53,12 @@ type Syntax =
, Literal.Tuple
, Redirect
, Statement.Assignment
, Statement.Break
, Statement.Continue
, Statement.If
, Statement.NoOp
, Statement.Return
, Statement.Throw
, Statement.Yield
, Language.Python.Syntax.Ellipsis
, Syntax.Empty
@ -92,13 +96,20 @@ statement :: Assignment
statement = assertStatement
<|> assignment'
<|> augmentedAssignment
<|> breakStatement
<|> continueStatement
<|> deleteStatement
<|> execStatement
<|> expressionStatement
<|> globalStatement
<|> ifStatement
<|> identifier
<|> import'
<|> importFrom
<|> nonlocalStatement
<|> passStatement
<|> printStatement
<|> raiseStatement
<|> returnStatement
expressionStatement :: Assignment
@ -114,6 +125,7 @@ expression = await
<|> conditionalExpression
<|> dottedName
<|> ellipsis
<|> expressionList
<|> lambda
<|> keywordIdentifier
<|> literal
@ -267,6 +279,9 @@ printStatement = do
redirectCallTerm location keyword = makeTerm location <$ symbol Chevron <*> (flip Redirect <$> children expression <*> printCallTerm location keyword)
printCallTerm location keyword = makeTerm location . Expression.Call keyword <$> many expression
nonlocalStatement :: Assignment
nonlocalStatement = makeTerm <$> symbol NonlocalStatement <*> children (Expression.Call <$> (makeTerm <$> symbol AnonNonlocal <*> (Syntax.Identifier <$> source)) <*> many identifier)
globalStatement :: Assignment
globalStatement = makeTerm <$> symbol GlobalStatement <*> children (Expression.Call <$> (makeTerm <$> symbol AnonGlobal <*> (Syntax.Identifier <$> source)) <*> many identifier)
@ -276,6 +291,12 @@ await = makeTerm <$> symbol Await <*> children (Expression.Call <$> (makeTerm <$
returnStatement :: Assignment
returnStatement = makeTerm <$> symbol ReturnStatement <*> (Statement.Return <$> children expressionList)
deleteStatement :: Assignment
deleteStatement = makeTerm <$> symbol DeleteStatement <*> children (Expression.Call <$> deleteIdentifier <* symbol ExpressionList <*> children (many expression))
where deleteIdentifier = makeTerm <$> symbol AnonDel <*> (Syntax.Identifier <$> source)
raiseStatement :: Assignment
raiseStatement = makeTerm <$> symbol RaiseStatement <*> children (Statement.Throw <$> (makeTerm <$> location <*> many expression))
ifStatement :: Assignment
ifStatement = makeTerm <$> symbol IfStatement <*> children (Statement.If <$> expression <*> statement <*> (flip (foldr makeElif) <$> many elifClause <*> optionalElse))
@ -284,6 +305,18 @@ ifStatement = makeTerm <$> symbol IfStatement <*> children (Statement.If <$> exp
optionalElse = fromMaybe <$> emptyTerm <*> optional elseClause
makeElif (loc, makeIf) rest = makeTerm loc (makeIf rest)
execStatement :: Assignment
execStatement = makeTerm <$> symbol ExecStatement <*> children (Expression.Call <$> (makeTerm <$> location <*> (Syntax.Identifier <$> source)) <*> many (string <|> expression))
passStatement :: Assignment
passStatement = makeTerm <$> symbol PassStatement <*> (Statement.NoOp <$> (makeTerm <$> location <*> (Syntax.Identifier <$> source)))
breakStatement :: Assignment
breakStatement = makeTerm <$> symbol BreakStatement <*> (Statement.Break <$> (makeTerm <$> location <*> (Syntax.Identifier <$> source)))
continueStatement :: Assignment
continueStatement = makeTerm <$> symbol ContinueStatement <*> (Statement.Continue <$> (makeTerm <$> location <*> (Syntax.Identifier <$> source)))
memberAccess :: Assignment
memberAccess = makeTerm <$> symbol Attribute <*> children (Expression.MemberAccess <$> expression <*> expression)