1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 17:05:33 +03:00

Assign exec statements

This commit is contained in:
Rick Winfrey 2017-06-07 17:01:13 -07:00
parent 7cb37aad74
commit 833b02b94a
2 changed files with 11 additions and 0 deletions

View File

@ -30,6 +30,12 @@ newtype Pattern a = Pattern a
instance Eq1 Pattern where liftEq = genericLiftEq
instance Show1 Pattern where liftShowsPrec = genericLiftShowsPrec
-- | Evaluate (e.g. exec in Python, or eval in Ruby)
data Evaluate a = Evaluate { evaluateExpression :: !a, evaluateContext :: !(Maybe [a]) }
deriving (Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable)
instance Eq1 Evaluate where liftEq = genericLiftEq
instance Show1 Evaluate where liftShowsPrec = genericLiftShowsPrec
-- Assignment

View File

@ -55,6 +55,7 @@ type Syntax' =
, Statement.Assignment
, Statement.Break
, Statement.Continue
, Statement.Evaluate
, Statement.If
, Statement.NoOp
, Statement.Return
@ -97,6 +98,7 @@ statement = assertStatement
<|> breakStatement
<|> continueStatement
<|> deleteStatement
<|> execStatement
<|> expressionStatement
<|> globalStatement
<|> ifStatement
@ -302,6 +304,9 @@ ifStatement = makeTerm <$> symbol IfStatement <*> children (Statement.If <$> exp
optionalElse = fromMaybe <$> emptyTerm <*> optional elseClause
makeElif (loc, makeIf) rest = makeTerm loc (makeIf rest)
execStatement :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location)
execStatement = makeTerm <$> symbol ExecStatement <*> children (Statement.Evaluate <$> string <*> (optional (many expression)))
passStatement :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location)
passStatement = makeTerm <$> symbol PassStatement <*> (Statement.NoOp <$> (makeTerm <$> location <*> (Syntax.Identifier <$> source)))